var p=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var y=(t,e)=>{for(var n in e)p(t,n,{get:e[n],enumerable:!0})},m=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of d(e))!k.call(t,s)&&s!==n&&p(t,s,{get:()=>e[s],enumerable:!(r=P(e,s))||r.enumerable});return t};var h=t=>m(p({},"__esModule",{value:!0}),t);var b={};y(b,{PackageJSON:()=>l,Person:()=>f,default:()=>O});module.exports=h(b);var o=require("path"),a=require("semver"),c=require("fs");const u={personMagic:/^((?:.*?(?=\s*(?:<[^ ]*>|\([^ ]*\)))|.*?))(?: <([^ ]*)>)? *(?:\((.*)\))?$/};class f{name;email;url;toString(){return(this.name!=="[Anonymous]"?this.name:"")+(this.email!==void 0?" <"+this.email+">":"")+(this.url!==void 0?" ("+this.url+")":"")}static isPersonObject(e){if(e instanceof Object){if(typeof e.name!="string"||e.email!==void 0&&typeof e.email!="string"||e.url!==void 0&&typeof e.url!="string")return!1}else return!1;return!0}static isPerson(e){return this.isPersonObject(e)?!0:typeof e=="string"?u.personMagic.exec(e)?.[1]!==void 0:!1}constructor(e){if(e instanceof Object)this.name=e.name,this.email=e.email,this.url=e.url;else{const n=u.personMagic.exec(e);this.name=(n?.[1]??"[Anonymous]").trimEnd(),this.email=n?.[2]??void 0,this.url=n?.[3]??void 0}}}class l{data;checkPackageJsonComplete(e){if(e instanceof Object){for(const n in e)if(typeof n!="string")return"'object' keys are not of the type 'string'."}else return"'object' is actually not an object (but '"+typeof e+"')!";if(e.contributors instanceof Object){for(const n of e.contributors??[])if(!f.isPerson(n))return"Contributors field is of invalid type."}if(e.author!==void 0&&!f.isPerson(e.author))return`Author field '${JSON.stringify(e?.author)}' is of invalid type.`;for(const n of["name","description","license"])if(typeof e[n]!="string")return"'"+n+"' is not assignable to type 'string'.";if(typeof e.repository!="string"&&typeof e.repository!="object")return"Repository field is neither of type 'string' nor 'object'.";for(const n of["type","url"]){const r=e.repository;if(typeof r=="object"&&typeof r[n]!="string")return"Repository object does not contain a '"+n+"' property."}if(/^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.exec(e.name)===null)return"'"+e.name+"' is not a valid Node.js package name.";if(typeof e.version=="string"){if((0,a.valid)(e.version)===null)return"Version "+e.version+" can't be parsed to 'semver'."}else return"Version property is not assignable to type 'string'!";for(const n of["dependencies","devDependencies"]){const r=e[n];if(/undefined|object/.test(typeof r)){if(r instanceof Object)for(const[s,i]of Object.entries(r)){if(typeof s!="string")return"Package name '"+JSON.stringify(s)+"' is not a valid 'string'.";if(typeof i!="string")return"Version of the package '"+s+"' is not of type 'string'.";if((0,a.validRange)(i)===null&&i!=="latest"&&!/^[a-z]*:?[^/:]+\/[^/:]+/.test(i))return"Version '"+i+"' of the package '"+s+"' is not of the valid format."}}else return"Property '"+n+"' is of invalid type!"}return e.homepage!==void 0&&typeof e.homepage!="string"?"Homepage property is neither 'string' nor 'undefined'.":""}findProjectPackageJson(){let e=__dirname;for(;!(0,c.existsSync)((0,o.resolve)(e,"package.json"))&&e!=="/";)e=(0,o.resolve)(e,"../");return(0,o.resolve)(e,"package.json")}isPackageJsonComplete(e){return this.checkPackageJsonComplete(e)===""}constructor(e,n){const r=n??this.findProjectPackageJson(),s=JSON.parse((0,c.readFileSync)(r).toString());if(!this.isPackageJsonComplete(s))throw new TypeError("While parsing `package.json`: "+this.checkPackageJsonComplete(s));const i={};for(const g of Array.from(new Set(e)))i[g]=Object.freeze(s[g]);this.data=Object.freeze(i)}}const J=new l(["homepage","name","repository","author","contributors"]);var O=J;0&&(module.exports={PackageJSON,Person});
