@nejs/basic-extensions 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@nejs/basic-extensions.bundle.1.3.0.js +2 -0
- package/dist/@nejs/basic-extensions.bundle.1.3.0.js.map +7 -0
- package/dist/cjs/descriptor.js +51 -12
- package/dist/cjs/functionextensions.js +1 -1
- package/dist/cjs/globals.d.ts +2 -0
- package/dist/cjs/globals.js +177 -0
- package/dist/cjs/index.d.ts +4 -1
- package/dist/cjs/index.js +45 -3
- package/dist/cjs/objectextensions.js +71 -45
- package/dist/mjs/descriptor.js +51 -12
- package/dist/mjs/functionextensions.js +1 -1
- package/dist/mjs/globals.d.ts +2 -0
- package/dist/mjs/globals.js +174 -0
- package/dist/mjs/index.d.ts +4 -1
- package/dist/mjs/index.js +43 -3
- package/dist/mjs/objectextensions.js +71 -45
- package/package.json +2 -2
- package/src/descriptor.js +56 -16
- package/src/functionextensions.js +1 -1
- package/src/globals.js +216 -0
- package/src/index.js +47 -4
- package/src/objectextensions.js +75 -46
- package/dist/@nejs/basic-extensions.bundle.1.0.0.js +0 -2
- package/dist/@nejs/basic-extensions.bundle.1.0.0.js.map +0 -7
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var nejsBasicExtensions=(()=>{var R=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var B=(e,t)=>{for(var r in t)R(e,r,{get:t[r],enumerable:!0})},K=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of C(t))!I.call(e,i)&&i!==r&&R(e,i,{get:()=>t[i],enumerable:!(s=F(t,i))||s.enumerable});return e};var Y=e=>K(R({},"__esModule",{value:!0}),e);var J={};B(J,{ArrayPrototypeExtensions:()=>D,DescriptorExtension:()=>E,FunctionExtensions:()=>d,GlobalFunctionsAndProps:()=>x,ObjectExtensions:()=>p,ReflectExtensions:()=>b,StringExtensions:()=>y,SymbolExtensions:()=>v,all:()=>W,disableAll:()=>H,enableAll:()=>U});var k=e=>/(\w+)]/.exec(Object.prototype.toString.call(e))[1],f=class extends Error{constructor(t,r){super(`${k(t)} disallows tampering with ${r}.`),Object.assign(this,{owner:t,key:r})}get[Symbol.toStringTag](){return this.constructor.name}};var M=e=>/(\w+)]/.exec(Object.prototype.toString.call(e))[1],h=class extends Error{constructor(t,r){super(`${M(t)} does not have a property named '${r}'.`),Object.assign(this,{owner:t,key:r})}get[Symbol.toStringTag](){return this.constructor.name}};var g=class{constructor(t,r=!1){this.started=!1,this.preventRevert=r,this.patch=t,this.patchName=t.owner?.name??t.owner?.constructor?.name??/(\w+)]/.exec(Object.prototype.toString.call(t.owner))[1],this.state={needsApplication:!1,needsReversion:!1}}start(){return this.started||(this.state.needsApplication=!this.patch.applied,this.state.needsReversion=this.patch.applied,this.started=!0,this.state.needsApplication&&this.patch.apply()),this}stop(){return this.started&&((this.preventRevert||this.patch.applied)&&this.patch.revert(),this.state.needsApplication=!1,this.state.needsReversion=!1,this.started=!1),this}get[Symbol.toStringTag](){return`${this.constructor.name}:${this.patchName}`}[Symbol.for("nodejs.util.inspect.custom")](t,r,s){let i=this[Symbol.toStringTag],n=`(started: ${this.started} needed: ${this.state.needsApplication})`;return s(`${i} ${n}`,{...r,depth:t})}};var c=class e{constructor(t,r,s={}){Object.assign(this,{owner:t,options:s,applied:!1}),this.patchConflicts={},this.patchEntries={},this.patchesOwner=r,Reflect.ownKeys(r).forEach(i=>{this.patchEntries[i]=new e.#t(i,this.patchesOwner),Reflect.has(this.owner,i)&&(this.patchConflicts[i]=new e.#t(i,this.owner))}),e.patches.has(t)||e.patches.set(t,[]),e.patches.get(t).push(this)}get patches(){return Reflect.ownKeys(this.patchEntries).map(t=>[t,this.patchEntries[t]])}get conflicts(){return Reflect.ownKeys(this.patchConflicts).map(t=>[t,this.patchConflicts[t]])}apply(){this.applied||(this.patches.forEach(([,t])=>{Object.defineProperty(this.owner,t.key,t.descriptor)}),this.applied=!0)}createToggle(t=!1){return new g(this,t)}revert(){this.applied&&(this.patches.forEach(([,t])=>{delete this.owner[t.key]}),this.conflicts.forEach(([,t])=>{Object.defineProperty(this.owner,t.key,t.descriptor)}),this.applied=!1)}release(){let t=e.patches.get(this.owner);t.splice(t.find(r=>r===this),1)}owner=null;options=null;static patches=new Map;static enableFor(t){if(e.patches.has(t))for(let r of e.patches.get(t))r.apply()}static disableFor(t){if(e.patches.has(t))for(let r of e.patches.get(t))r.revert()}static#t=class{constructor(t,r=globalThis){Object.assign(this,{key:t,descriptor:Object.getOwnPropertyDescriptor(r,t),owner:r})}get computed(){return this.isAccessor?this.descriptor.get.bind(this.owner).call():this.descriptor.value}get isData(){return Reflect.has(this.descriptor,"value")}get isAccessor(){return Reflect.has(this.descriptor,"get")}get isReadOnly(){return Reflect.has(this.descriptor,"configurable")&&!this.descriptor.configurable||Reflect.has(this.descriptor,"writable")&&!this.descriptor.writable}get[Symbol.toStringTag](){return this.constructor.name}[Symbol.for("nodejs.util.inspect.custom")](t,r,s){return`PatchEntry<${this.key}, ${this.isData?"Data":"Accessor"}${this.isReadOnly?" [ReadOnly]":""}>`}}};var m=class e extends c{constructor(t,r,s=globalThis,i={}){let{key:n,extension:o,valid:a}=e.determineInput(t);if(o=r||o,!a)throw new h(s,n);let l=Object.getOwnPropertyDescriptor(s,n);if(l&&(Reflect.has(l,"writable")&&!l.writable||Reflect.has(l,"configurable")&&!l.configurable))throw new f(s,n);super(s,{[n]:o},i),this.key=n}static determineInput(t){let r={key:null,extension:null,valid:!1};return t instanceof Function?r={key:t.name,extension:t,valid:!0}:(typeof t=="string"||t instanceof String)&&(r={key:t,extension:null,valid:!0}),r}[Symbol.for("nodejs.util.inspect.custom")](t,r,s){return`Extension<${this.key}>`}get[Symbol.toStringTag](){return this.constructor.name}};var d=new c(Function,{isClass(e){return e instanceof Function&&!!/^class\s/.exec(String(e))},isFunction(e){return e instanceof Function},isAsync(e){let t=/(\w+)]/g.exec(Object.prototype.toString.call(e))[1];return e instanceof Function&&t.includes("Async")},isBigArrow(e){return e instanceof Function&&String(e).includes("=>")&&!String(e).startsWith("bound")&&!Reflect.has(e,"prototype")},isBound(e){return e instanceof Function&&String(e).startsWith("bound")&&!Reflect.has(e,"prototype")}});var p=new c(Object,{getStringTag(e){return/\s(.+)]/.exec(Object.prototype.toString.call(e))[1]},getType(e,t=globalThis){let r=Object.getStringTag(e);switch(r){case"Null":return null;case"Undefined":return;default:return t[r]}},isObject(e){return e&&(e instanceof Object||typeof e=="object")},isPrimitive(e){if(e===null)return!0;switch(typeof e){case"string":case"number":case"bigint":case"boolean":case"undefined":case"symbol":return!0;default:return!1}},isValidKey(e){return typeof e=="string"||typeof e=="symbol"},stripTo(e,t,r=!0){let s={};if(!Array.isArray(t))return s;for(let i of t)if(Reflect.has(e,i)){let n=Object.getOwnPropertyDescriptor(e,i);(Reflect.has(n,"get")||Reflect.has(n,"set"))&&r&&(n.get=n?.get?.bind(e),n.set=n?.set?.bind(e)),Object.defineProperty(s,n)}return s}});var b=new c(Reflect,{hasAll(e,...t){return Object.isObject(e)&&t.flat(1/0).map(r=>Reflect.has(e,r)).every(r=>r)},ownDescriptors(e){let t={},r=()=>r.doIt?p.revert():"";if(r.doIt=!1,Object.isObject||(r.doIt=!0,p.apply()),!Object.isObject(e))return r(),{};let s=Reflect.ownKeys(e);for(let i of s)t[i]=Object.getOwnPropertyDescriptor(i);return r(),t},hasSome(e,...t){return Object.isObject(e)&&t.flat(1/0).map(r=>Reflect.has(e,r)).some(r=>r)},entries(e){return!e||typeof e!="object"?[]:Reflect.ownKeys(e).map(t=>[t,Object.getOwnPropertyDescriptor(e,t)])},values(e){return Reflect.entries.map(([,t])=>t)}});var y=new c(String,{isString(e){return e&&(typeof e=="string"||e instanceof String)?e.length>0:!1}});var v=new c(Symbol,{isSymbol(e){return!!(e&&typeof e=="symbol")}});var D=new c(Array.prototype,{contains(e){return!!this.find(t=>t===e)},findEntry(e){let t=this.entries(),r=1;for(let s of t)if(e(s[r]))return s},get first(){return this[0]},get last(){return this[this.length-1]}});var S=p.patchEntries?.isObject?.computed,P=p.patchEntries?.isValidKey?.computed,G=y.patchEntries?.isString?.computed,w=b.patchEntries?.hasSome?.computed,T=class e{#t=e.enigmatic;constructor(t,r){if(this.#t=t,S(t)&&P(r)&&(this.#t=Object.getOwnPropertyDescriptor(t,r)),!this.isDescriptor)throw new Error("Not a valid descriptor:",this.#t)}get isAccessor(){return e.isAccessor(this.#t)}get isData(){return e.isData(this.#t)}get isDescriptor(){return e.isDescriptor(this.#t)}get configurable(){return!!this.#t?.configurable}set configurable(t){(this.#t||{}).configurable=!!t}get enumerable(){return this.#t?.enumerable}set enumerable(t){(this.#t||{}).enumerable=t}get writable(){return this.#t?.writable}set writable(t){(this.#t||{}).writable=t}get value(){return this.#t?.value}set value(t){(this.#t||{}).value=t}get get(){return this.#t?.get}set get(t){(this.#t||{}).get=t}get set(){return this.#t?.writable}set set(t){(this.#t||{}).set=t}static for(t,r){return!S(t)&&!P(r)?null:Object.getOwnPropertyDescriptor(t,r)}applyTo(t,r){if(!S(t)||!P(r))throw new Error("Cannot apply descriptor to non-object or invalid key");return Object.defineProperty(t,r,this.#t)}[Symbol.toPrimitive](t){switch(t){case"string":if(this.isAccessor){let r=Reflect.has(this.#t,"get")?"getter":"",s=Reflect.has(this.#t,"set")?"setter":"";return`Accessor (${r}${r&&s?", ":""}${s})`}else if(this.isData){let r=Reflect.has(this.#t,"value")?"value":"",s=Reflect.has(this.#t,"writable")?"writable":"";return`Data (${r}${r&&s?", ":""}${s})`}break;case"number":return NaN;default:return this.#t}}static getData(t,r){if(!S(t)||!G(r))return null;let s=e.all(t);if(s.has(r)){let i=s.get(r);if(e.isData(i))return i.value}}static getAccessor(t,r){if(!S(t))return null;let[s,i,n]=[0,1,2],o=[void 0,void 0,void 0],a=this.all(t),l=e.isDescriptor(t);if(a.has(r)||l){let u=l?t:a.get(r);if(e.isAccessor(u))return o[n]=a.object(r),o[s]=u?.get,o[i]=u?.set,Object.assign(o,{get(){this[s].bind(this[n])()},set(A){this[i].bind(this[n])(A)},get accessor(){return!0},get descriptor(){return u},get boundDescriptor(){return{...u,get:u.get?.bind(t),set:u.set?.bind(t)}}}),o}}static base(t=!1,r=!1){return{enumerable:t,configurable:r}}static accessor(t,r,{enumerable:s,configurable:i}=e.base()){return{get:t,set:r,enumerable:s,configurable:i}}static data(t,r=!0,{enumerable:s,configurable:i}=e.base()){return{value:t,enumerable:s,writable:r,configurable:i}}static isDescriptor(t){let r=[...e.SHARED_KEYS,...e.ACCESSOR_KEYS,...e.DATA_KEYS];return w(t,r)}static isData(t,r){let i=(typeof t=="object"||t instanceof Object)&&r instanceof String?e.for(t,r):t,{ACCESSOR_KEYS:n,DATA_KEYS:o}=this,a=!1;return w(i,n)?a=!1:w(i,o)&&(a=!0),a}static isAccessor(t,r){let i=t&&r&&(typeof t=="object"||t instanceof Object)&&(r instanceof String||typeof r=="symbol")?e.for(t,r):t,{ACCESSOR_KEYS:n,DATA_KEYS:o}=this,a=!1;return w(i,o)?a=!1:w(i,n)&&(a=!0),a}static get flexible(){return this.base(!0,!0)}static get enigmatic(){return this.base(!1,!0)}static get intrinsic(){return this.base(!1,!1)}static get transparent(){return this.base(!0,!1)}static get SHARED_KEYS(){return["configurable","enumerable"]}static get ACCESSOR_KEYS(){return["get","set"]}static get DATA_KEYS(){return["value","writable"]}},E=new m(T);var{isClass:V,isFunction:O}=d.patchEntries.isClass.computed,N=Symbol.for("nodejs.util.inspect.custom"),x=new c(globalThis,{asBigIntObject(e){let t={configurable:!0,enumerable:!1},r={value:e};return Object.defineProperties(r,{[Symbol.toPrimitive]:{value:function(){return e},...t},[Symbol.toStringTag]:{value:BigInt.name,...t},[Symbol.species]:{get(){return BigInt},...t},[N]:{...t,value(s,i,n){return n(this[Symbol.toPrimitive](),{...i,depth:s})}}}),Object.setPrototypeOf(r,BigInt.prototype),Reflect.ownKeys(BigInt.prototype).forEach(s=>{typeof r[s]=="function"&&(r[s]=function(...i){return BigInt.prototype[s].apply(this,i)}.bind(r.value))}),r},maskAs(e,t,r){let{prototype:s,toPrimitive:i}=GenericMask({...r,prototype:t}),n={configurable:!0,enumerable:!1},o=O(s)?s.prototype:s,a=V(s)?s:o?.constructor;return!a&&!o?null:(Object.setPrototypeOf(e,o),Object.defineProperties(e,{valueOf:{value(){return String(i("default",e))},...n},[Symbol.toPrimitive]:{value(l){return i(l,e)},...n},[Symbol.toStringTag]:{value:a.name,...n},[Symbol.species]:{get(){return a},...n},[N]:{...n,value(l,u,A){return A(this[Symbol.toPrimitive](),{...u,depth:l})}}}),e)},maskAsString(e,t,r){return e&&Reflect.has(e,t)?maskAs(e,StringMask(t??"value",r)):null},maskAsNumber(e,t,r){return e&&Reflect.has(e,t)?maskAs(e,NumberMask(t??"value",r)):null},GenericMask({prototype:e,targetKey:t="value",toPrimitive:r}){let s={targetKey:t,toPrimitive:r,prototype:e};return O(r)||(s.toPrimitive=(i,n)=>{let o=n[t],a=typeof o=="number"&&Number.isFinite(o)||typeof o=="string"&&!isNaN(parseFloat(o))&&isFinite(o);switch(i){case"string":return a?String(o):o??String(n);case"number":return a?Number(o):NaN;case"default":default:return a?Number(o):o}}),s},StringMask(e,t){let r={targetKey:e,toPrimitive:t,prototype:String.prototype};return O(t)||(r.toPrimitive=function(i,n){switch(i){case"default":return n[e];case"number":return parseInt(n[e],36);case"string":return String(n[e]);default:return n}}),r},NumberMask(e,t){let r={targetKey:e,toPrimitive:t,prototype:Number.prototype};return O(t)||(r.toPrimitive=function(i,n){switch(i){case"default":return n[e];case"number":return Number(n[e]);case"string":return String(n[e]);default:return n}}),r}});var $=[Object,Function,Reflect,String,Symbol,Array.prototype],j=[x,E];function U(e){let t=e||$;if(!t)throw new Error("Unable to enable features without owners list");t.forEach(r=>{c.enableFor(r)}),j.forEach(r=>{r.apply()})}function H(e){let t=e||$;if(!t)throw new Error("Unable to disable features without owners list");t.forEach(r=>{c.disableFor(r)}),j.forEach(r=>{r.revert()})}var W=[p,d,b,y,v,D,x,E].reduce((r,s)=>(Reflect.ownKeys(s.patchEntries).reduce((i,n)=>(r[n]=s.patchEntries[n].computed,r),r),r),{});return Y(J);})();
|
|
2
|
+
//# sourceMappingURL=basic-extensions.bundle.1.3.0.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.js", "../../node_modules/@nejs/extension/dist/mjs/errors/CannotBeExtendedError.js", "../../node_modules/@nejs/extension/dist/mjs/errors/MissingOwnerValue.js", "../../node_modules/@nejs/extension/dist/mjs/patchtoggle.js", "../../node_modules/@nejs/extension/dist/mjs/patch.js", "../../node_modules/@nejs/extension/dist/mjs/extension.js", "../../src/functionextensions.js", "../../src/objectextensions.js", "../../src/reflectextensions.js", "../../src/stringextensions.js", "../../src/symbolextensions.js", "../../src/arrayextensions.js", "../../src/descriptor.js", "../../src/globals.js"],
|
|
4
|
+
"sourcesContent": ["import { FunctionExtensions } from './functionextensions.js'\nimport { ObjectExtensions } from './objectextensions.js'\nimport { ReflectExtensions } from './reflectextensions.js'\nimport { StringExtensions } from './stringextensions.js'\nimport { SymbolExtensions } from './symbolextensions.js'\nimport { ArrayPrototypeExtensions } from './arrayextensions.js'\nimport { DescriptorExtension } from './descriptor.js'\nimport { GlobalFunctionsAndProps } from './globals.js'\n\nimport { Patch } from '@nejs/extension'\n\nconst Owners = [\n Object,\n Function,\n Reflect,\n String,\n Symbol,\n\n Array.prototype,\n]\n\nconst NetNew = [\n GlobalFunctionsAndProps,\n DescriptorExtension,\n]\n\nexport function enableAll(owners) {\n const list = owners || Owners\n\n if (!list) {\n throw new Error('Unable to enable features without owners list')\n }\n\n list.forEach(owner => {\n Patch.enableFor(owner)\n })\n\n NetNew.forEach(extension => {\n extension.apply()\n })\n}\n\nexport function disableAll(owners) {\n const list = owners || Owners\n\n if (!list) {\n throw new Error('Unable to disable features without owners list')\n }\n\n list.forEach(owner => {\n Patch.disableFor(owner)\n })\n\n NetNew.forEach(extension => {\n extension.revert()\n })\n}\n\nexport const all = (() => {\n let extensions = [\n ObjectExtensions,\n FunctionExtensions,\n ReflectExtensions,\n StringExtensions,\n SymbolExtensions,\n ArrayPrototypeExtensions,\n\n GlobalFunctionsAndProps,\n DescriptorExtension,\n ]\n\n const dest = extensions.reduce((accumulator, extension) => {\n Reflect.ownKeys(extension.patchEntries).reduce((_, key) => {\n accumulator[key] = extension.patchEntries[key].computed\n return accumulator\n }, accumulator)\n\n return accumulator\n }, {})\n\n return dest\n})()\n\n\nexport {\n ObjectExtensions,\n FunctionExtensions,\n ReflectExtensions,\n StringExtensions,\n SymbolExtensions,\n ArrayPrototypeExtensions,\n\n GlobalFunctionsAndProps,\n DescriptorExtension,\n}", "/** Small utility to fetch name of class or type */\nconst typeOf = o => /(\\w+)]/.exec(Object.prototype.toString.call(o))[1];\n/**\n * Represents an error that is thrown when there is an attempt to extend a\n * restricted part of the code. This error is specifically used to signal\n * violations of extension constraints, such as tampering with certain keys\n * or properties of an object. The error message constructed will include the\n * details of the owner (the restricted part) and the key that was attempted to\n * be tampered with.\n */\nexport class CannotBeExtendedError extends Error {\n /**\n * Constructs a new CannotBeExtendedError instance.\n *\n * @param {string} owner The name or identifier of the restricted part\n * that is disallowing extension or tampering.\n * @param {string} key The key or property that was attempted to be\n * modified or extended.\n */\n constructor(owner, key) {\n super(`${typeOf(owner)} disallows tampering with ${key}.`);\n Object.assign(this, { owner, key });\n }\n /**\n * Custom getter for the toStringTag symbol. Overrides the default\n * Object.prototype.toString behavior, returning the constructor's name\n * of this error instance. Useful for debugging and logging purposes.\n * @returns {string} The name of the constructor for this error instance.\n */\n get [Symbol.toStringTag]() {\n return this.constructor.name;\n }\n}\n", "/** Small utility to fetch name of class or type */\nconst typeOf = o => /(\\w+)]/.exec(Object.prototype.toString.call(o))[1];\n/**\n * Represents an error that is thrown when a property is missing from a specified\n * owner object. This error is used to indicate that a specific key or property\n * expected to be present on the owner is not found, highlighting potential issues\n * in property access or data integrity.\n */\nexport class MissingOwnerValue extends Error {\n /**\n * Constructs a new MissingOwnerValue instance.\n *\n * @param {string} owner The object or entity that is supposed to contain the\n * property.\n * @param {string} key The name of the property that is missing from the owner.\n */\n constructor(owner, key) {\n super(`${typeOf(owner)} does not have a property named '${key}'.`);\n Object.assign(this, { owner, key });\n }\n /**\n * Custom getter for the toStringTag symbol. Overrides the default\n * Object.prototype.toString behavior, returning the constructor's name\n * of this error instance. Useful for debugging and logging purposes.\n *\n * @returns {string} The name of the constructor for this error instance.\n */\n get [Symbol.toStringTag]() {\n return this.constructor.name;\n }\n}\n", "import { Patch } from \"./patch\";\n/**\n * Early usage of the Patch and Extension classes made it clear that it was\n * cumbersome to use a Patch temporarily for a block of code and excessive\n * amounts of if/else statements were required. This simple wrapper makes that\n * process easier.\n */\nexport class PatchToggle {\n /**\n * Wraps an instance of a Patch. It allows low-code clean-readability to\n * start and stop the underlying patch regardless of whether or not the\n * patch has been already applied.\n *\n * @param {Patch} patch instance of `Patch` to wrap with this toggle\n * @param {boolean} preventRevert prevents the call to `.revert()` on the\n * supplied patch when stop() is called.\n */\n constructor(patch, preventRevert = false) {\n this.started = false;\n this.preventRevert = preventRevert;\n this.patch = patch;\n this.patchName = (patch.owner?.name ??\n patch.owner?.constructor?.name ??\n /(\\w+)]/.exec(Object.prototype.toString.call(patch.owner))[1]);\n this.state = {\n needsApplication: false,\n needsReversion: false,\n };\n }\n /**\n * If the usage of the wrapped Patch hasn't been started yet, the code checks\n * whether or not the patch has been applied by checking for signs of it in\n * the owning object.\n *\n * If the patch needs to be applied, it will be applied at this time.\n *\n * @returns {PatchToggle} returns `this` to allow for chaining\n */\n start() {\n if (!this.started) {\n this.state.needsApplication = !this.patch.applied;\n this.state.needsReversion = this.patch.applied;\n this.started = true;\n if (this.state.needsApplication) {\n this.patch.apply();\n }\n }\n return this;\n }\n /**\n * Checks to see if the toggle has been started. If so, the patch is reverted\n * if it needed to be applied previously. After stopping, the state of the instance\n * is reverted to allow for clean subsequent calls to start.\n *\n * @returns {PatchToggle} returns `this` to allow further chaining\n */\n stop() {\n if (this.started) {\n if (this.preventRevert || this.patch.applied) {\n this.patch.revert();\n }\n this.state.needsApplication = false;\n this.state.needsReversion = false;\n this.started = false;\n }\n return this;\n }\n /**\n * When the string tag for this class instance is inspected, it will\n * reflect the string `PatchToggle:PatchName`\n */\n get [Symbol.toStringTag]() {\n return `${this.constructor.name}:${this.patchName}`;\n }\n /**\n * Custom inspect function for Node.js that provides a formatted representation\n * of the PatchToggle instance, primarily for debugging purposes.\n *\n * @param {number} depth The depth to which the object should be formatted.\n * @param {object} options Formatting options.\n * @param {function} inspect The inspection function to format the object.\n * @returns {string} A formatted string representing the PatchEntry instance.\n */\n [Symbol.for('nodejs.util.inspect.custom')](depth, options, inspect) {\n const objName = this[Symbol.toStringTag];\n const status = `(started: ${this.started} needed: ${this.state.needsApplication})`;\n return inspect(`${objName} ${status}`, { ...options, depth });\n }\n}\n", "import { PatchToggle } from './patchtoggle.js';\n/**\n * The Patch class provides a mechanism to apply patches to properties or\n * methods of an object (the owner). It keeps track of the original state of\n * these properties and allows for the application and reversion of patches.\n */\nexport class Patch {\n /**\n * Constructs a new Patch instance.\n *\n * @param {object} owner The object to which patches will be applied.\n * @param {object} patches An object containing properties or methods to\n * be patched onto the owner.\n * @param {object} [options={}] Additional options for patching behavior.\n */\n constructor(owner, patches, options = {}) {\n Object.assign(this, {\n owner,\n options,\n applied: false,\n });\n this.patchConflicts = {};\n this.patchEntries = {};\n this.patchesOwner = patches;\n Reflect.ownKeys(patches).forEach(key => {\n this.patchEntries[key] = new Patch.#PatchEntry(key, this.patchesOwner);\n if (Reflect.has(this.owner, key)) {\n this.patchConflicts[key] = new Patch.#PatchEntry(key, this.owner);\n }\n });\n if (!Patch.patches.has(owner)) {\n Patch.patches.set(owner, []);\n }\n Patch.patches.get(owner).push(this);\n }\n /**\n * Retrieves the patch entries as an array of [key, patchEntry] pairs.\n *\n * @returns {Array} An array of [key, patchEntry] pairs.\n */\n get patches() {\n return Reflect.ownKeys(this.patchEntries).map(key => {\n return [key, this.patchEntries[key]];\n });\n }\n /**\n * Retrieves the conflict entries (existing properties on the owner that\n * will be overridden by patches) as an array of [key, patchEntry] pairs.\n *\n * @returns {Array} An array of [key, patchEntry] pairs.\n */\n get conflicts() {\n return Reflect.ownKeys(this.patchConflicts).map(key => {\n return [key, this.patchConflicts[key]];\n });\n }\n /**\n * Applies all patches to the owner object. If a property with the same key\n * already exists on the owner, it will be overridden.\n */\n apply() {\n if (!this.applied) {\n this.patches.forEach(([, patch]) => {\n Object.defineProperty(this.owner, patch.key, patch.descriptor);\n });\n this.applied = true;\n }\n }\n /**\n * Creates an easy to use toggle for working with `Patch` classes\n *\n * @param {boolean} preventRevert true if calling stop() on the toggle does not\n * revert the patch. false, the default, if it should.\n * @returns {PatchToggle} an instance of PatchToggle wrapped around this instance\n * of `Patch`\n * @example const toggle = ObjectExtensions.createToggle().start()\n */\n createToggle(preventRevert = false) {\n return new PatchToggle(this, preventRevert);\n }\n /**\n * Reverts all applied patches on the owner object, restoring any overridden\n * properties to their original state.\n */\n revert() {\n if (this.applied) {\n this.patches.forEach(([, patch]) => {\n delete this.owner[patch.key];\n });\n this.conflicts.forEach(([, patch]) => {\n Object.defineProperty(this.owner, patch.key, patch.descriptor);\n });\n this.applied = false;\n }\n }\n /**\n * Removes this Patch instance from being tracked amongst all the tracked Patch\n * instances. The JavaScript virtual machine will clean this instance up once\n * nothing else is holding a reference to it.\n */\n release() {\n const patches = Patch.patches.get(this.owner);\n patches.splice(patches.find(e => e === this), 1);\n }\n /**\n * The object to which the patches are applied.\n */\n owner = null;\n /**\n * Additional options for patching behavior.\n */\n options = null;\n /**\n * A global mapping of all patches in play\n */\n static patches = new Map();\n /**\n * Applies all patches associated with a given owner object. This method\n * is used to enable all patches for a specific owner if they have been\n * previously registered.\n *\n * @param {object} owner The object whose patches are to be applied.\n */\n static enableFor(owner) {\n if (Patch.patches.has(owner)) {\n for (const patch of Patch.patches.get(owner)) {\n patch.apply();\n }\n }\n }\n /**\n * Reverts all patches associated with a given owner object. This method\n * is used to disable all patches for a specific owner if they have been\n * previously applied.\n *\n * @param {object} owner The object whose patches are to be reverted.\n */\n static disableFor(owner) {\n if (Patch.patches.has(owner)) {\n for (const patch of Patch.patches.get(owner)) {\n patch.revert();\n }\n }\n }\n /**\n * Internal class representing a single patch entry.\n */\n static #PatchEntry = class {\n /**\n * Constructs a new PatchEntry instance.\n *\n * @param {string} property The property key to be patched.\n * @param {object} [owningObject=globalThis] The object from which the\n * property descriptor is taken.\n */\n constructor(property, owningObject = globalThis) {\n Object.assign(this, {\n key: property,\n descriptor: Object.getOwnPropertyDescriptor(owningObject, property),\n owner: owningObject\n });\n }\n /**\n * Computes and returns the current value of the patch, based on its type\n * (data or accessor).\n *\n * @returns {any} The current value of the patch.\n */\n get computed() {\n if (this.isAccessor) {\n return this.descriptor.get.bind(this.owner).call();\n }\n else {\n return this.descriptor.value;\n }\n }\n /**\n * Checks if the patch is a data property (has a value).\n *\n * @returns {boolean} True if the patch is a data property, false otherwise.\n */\n get isData() {\n return Reflect.has(this.descriptor, 'value');\n }\n /**\n * Checks if the patch is an accessor property (has a getter).\n *\n * @returns {boolean} True if the patch is an accessor property, false otherwise.\n */\n get isAccessor() {\n return Reflect.has(this.descriptor, 'get');\n }\n /**\n * Checks if the patch is read-only (not configurable or not writable).\n *\n * @returns {boolean} True if the patch is read-only, false otherwise.\n */\n get isReadOnly() {\n return ((Reflect.has(this.descriptor, 'configurable') && !this.descriptor.configurable) ||\n (Reflect.has(this.descriptor, 'writable') && !this.descriptor.writable));\n }\n /**\n * Custom getter for the toStringTag symbol. Provides the class name of\n * the PatchEntry instance.\n *\n * @returns {string} The class name of the PatchEntry instance.\n */\n get [Symbol.toStringTag]() {\n return this.constructor.name;\n }\n /**\n * Custom inspect function for Node.js that provides a formatted representation\n * of the PatchEntry instance, primarily for debugging purposes.\n *\n * @param {number} depth The depth to which the object should be formatted.\n * @param {object} options Formatting options.\n * @param {function} inspect The inspection function to format the object.\n * @returns {string} A formatted string representing the PatchEntry instance.\n */\n [Symbol.for('nodejs.util.inspect.custom')](depth, options, inspect) {\n return `PatchEntry<${this.key}, ${this.isData ? 'Data' : 'Accessor'}${this.isReadOnly ? ' [ReadOnly]' : ''}>`;\n }\n };\n}\n", "import { CannotBeExtendedError } from \"./errors/CannotBeExtendedError.js\";\nimport { MissingOwnerValue } from './errors/MissingOwnerValue.js';\nimport { Patch } from './patch.js';\n/**\n * The Extension class, inheriting from the Patch class, is specifically designed\n * for extending properties or methods of a given object. It facilitates the\n * extension process by determining the target key and value for the extension and\n * ensuring the target property is writable and configurable. If these conditions\n * are not met, the class throws a CannotBeExtendedError. This class is useful\n * in scenarios like testing, dynamic behavior adjustments, or managing complex\n * object configurations.\n */\nexport class Extension extends Patch {\n /**\n * Constructs a new Extension instance. This constructor initializes the extension\n * by determining the target key and value for the extension and ensuring that\n * the property to be extended is configurable and writable. It throws an error\n * if these conditions are not satisfied. The constructor leverages the Patch\n * class's functionalities to manage the extension effectively.\n *\n * @param {Function|string} keyClassOrFn - The key, class, or function to be\n * used for the extension. If a function or class is provided, its name is used\n * as the key.\n * @param {*} value - The value or method to be used for the extension.\n * @param {object} [owner=globalThis] - The object to which the extension will\n * be applied.\n * @param {object} [options={}] - Additional options for the extension behavior.\n * @throws {CannotBeExtendedError} If the target property is not writable or\n * configurable.\n * @throws {MissingOwnerValue} If the `keyClassOrFn` value is null or there\n * is an error determining the key and extension values, MissingOwnerValue is\n * thrown.\n */\n constructor(keyClassOrFn, value, owner = globalThis, options = {}) {\n let { key, extension, valid } = Extension.determineInput(keyClassOrFn);\n extension = value || extension;\n if (!valid) {\n throw new MissingOwnerValue(owner, key);\n }\n const descriptor = Object.getOwnPropertyDescriptor(owner, key);\n if (descriptor) {\n if ((Reflect.has(descriptor, 'writable') && !descriptor.writable) ||\n (Reflect.has(descriptor, 'configurable') && !descriptor.configurable)) {\n throw new CannotBeExtendedError(owner, key);\n }\n }\n super(owner, { [key]: extension }, options);\n this.key = key;\n }\n /**\n * Determines the input type for the extension. This method processes the input\n * and identifies the key for the extension and the associated value or method.\n * It supports inputs as either a string key or a function/class, providing\n * flexibility in defining extensions.\n *\n * @param {Function|string} keyClassOrFn - The key, class, or function provided\n * as input. If a function or class is provided, its name is used as the key.\n * containing the determined key, the extension value/method, and a validity flag\n * indicating whether the input is usable.\n * @returns {{key: string|null, extension: *|null, valid: boolean}} An object\n */\n static determineInput(keyClassOrFn) {\n let input = { key: null, extension: null, valid: false };\n if (keyClassOrFn instanceof Function) {\n input = { key: keyClassOrFn.name, extension: keyClassOrFn, valid: true };\n }\n else if (typeof keyClassOrFn === 'string' || keyClassOrFn instanceof String) {\n input = { key: keyClassOrFn, extension: null, valid: true };\n }\n return input;\n }\n /**\n * Custom inspect function for Node.js that provides a formatted representation\n * of the Extension instance, primarily for debugging purposes.\n *\n * @param {number} depth The depth to which the object should be formatted.\n * @param {object} options Formatting options.\n * @param {function} inspect The inspection function to format the object.\n * @returns {string} A formatted string representing the Extension instance.\n */\n [Symbol.for('nodejs.util.inspect.custom')](depth, options, inspect) {\n return `Extension<${this.key}>`;\n }\n /**\n * Custom getter for the toStringTag symbol. Provides the class name when the\n * object is converted to a string, typically used for debugging and logging.\n *\n * @returns {string} The class name of the Extension instance.\n */\n get [Symbol.toStringTag]() {\n return this.constructor.name;\n }\n}\n", "import { Patch } from '@nejs/extension'\n\n/**\n * The `FunctionExtensions` class is a patch applied to the built-in JavaScript `Function`\n * constructor. It extends `Function` with additional utility methods for determining the\n * specific type or nature of function-like objects. These methods allow developers to\n * distinguish between classes, regular functions, async functions, and arrow functions\n * in a more intuitive and straightforward manner. This class is part of the `@nejs/extension`\n * library and enhances the capabilities of function handling and introspection in JavaScript.\n */\nexport const FunctionExtensions = new Patch(Function, {\n /**\n * Determines if a given value is a class. It checks if the value is an instance of\n * `Function` and if its string representation includes the keyword 'class'. This method\n * is useful for distinguishing classes from other function types in JavaScript.\n *\n * @param {*} value - The value to be checked.\n * @returns {boolean} Returns `true` if the value is a class, otherwise `false`.\n */\n isClass(value) {\n return value instanceof Function && !!/^class\\s/.exec(String(value))\n },\n\n /**\n * Checks if a given value is a regular function. This method verifies if the value is\n * an instance of `Function`, which includes regular functions, classes, and async\n * functions but excludes arrow functions.\n *\n * @param {*} value - The value to be checked.\n * @returns {boolean} Returns `true` if the value is a regular function, otherwise `false`.\n */\n isFunction(value) {\n return value instanceof Function;\n },\n\n /**\n * Determines if a given value is an asynchronous function. It checks if the value is an\n * instance of `Function` and if its string representation includes the keyword 'Async'.\n * This method is particularly useful for identifying async functions.\n *\n * @param {*} value - The value to be checked.\n * @returns {boolean} Returns `true` if the value is an async function, otherwise `false`.\n */\n isAsync(value) {\n const stringTag = /(\\w+)]/g.exec(Object.prototype.toString.call(value))[1]\n return (\n value instanceof Function &&\n stringTag.includes('Async')\n )\n },\n\n /**\n * Checks if a given value is an arrow function. It verifies if the value is an instance\n * of `Function`, if its string representation includes the '=>' symbol, and if it lacks\n * a prototype, which is a characteristic of arrow functions in JavaScript.\n *\n * @param {*} value - The value to be checked.\n * @returns {boolean} Returns `true` if the value is an arrow function, otherwise `false`.\n */\n isBigArrow(value) {\n return (\n value instanceof Function &&\n String(value).includes('=>') &&\n !String(value).startsWith('bound') &&\n !Reflect.has(value, 'prototype')\n );\n },\n\n /**\n * Determines if a given value is a bound function. Bound functions are created using\n * the `Function.prototype.bind` method, which allows setting the `this` value at the\n * time of binding. This method checks if the value is an instance of `Function`, if\n * its string representation starts with 'bound', and if it lacks a `prototype`\n * property. These characteristics are indicative of bound functions in JavaScript.\n *\n * @param {*} value - The value to be checked, typically a function.\n * @returns {boolean} Returns `true` if the value is a bound function, otherwise\n * `false`. Bound functions have a specific format in their string representation\n * and do not have their own `prototype` property.\n */\n isBound(value) {\n return (\n value instanceof Function &&\n String(value).startsWith('bound') &&\n !Reflect.has(value, 'prototype')\n )\n },\n})\n", "import { Patch } from '@nejs/extension';\n\n/**\n * `ObjectExtensions` is a patch for the JavaScript built-in `Object` class. It\n * adds utility methods to the `Object` class without modifying the global namespace\n * directly. This patch includes methods for key validation, object type checking,\n * and retrieving the string tag of an object. These methods are useful for\n * enhancing the capabilities of the standard `Object` class with additional\n * utility functions.\n */\nexport const ObjectExtensions = new Patch(Object, {\n /**\n * Retrieves the string tag of an object. The string tag is a representation of\n * the object's type, as defined by its `Object.prototype.toString` method. This\n * utility method is helpful for getting a more descriptive type of an object than\n * what is returned by the `typeof` operator, especially for custom objects.\n *\n * @param {*} value - The object whose string tag is to be retrieved.\n * @returns {string} - The string tag of the object, indicating its type.\n */\n getStringTag(value) {\n return /\\s(.+)]/.exec(Object.prototype.toString.call(value))[1];\n },\n\n /**\n * Determines the type of the given value based on its string tag. This method\n * uses `Object.getStringTag` to obtain the string tag of the value, which\n * represents its more specific type (e.g., Array, Map, Set) rather than just\n * 'object'. The method then maps this string tag to the corresponding type\n * present in the provided `owner` object, which defaults to `globalThis`.\n * This utility method is especially useful for identifying the specific\n * constructor or class of an object, beyond the basic types identified by\n * the `typeof` operator.\n *\n * @param {any} value - The value whose type is to be determined.\n * @param {object} [owner=globalThis] - The object in which to look up the\n * constructor corresponding to the string tag. Defaults to `globalThis`, which\n * covers global constructors like `Array`, `Object`, etc.\n * @returns {Function|object|null|undefined} - Returns the constructor or type\n * of the value based on its string tag. For 'Null' and 'Undefined', it returns\n * `null` and `undefined`, respectively. For other types, it returns the\n * corresponding constructor (e.g., `Array` for arrays) if available in the\n * `owner` object.\n */\n getType(value, owner = globalThis) {\n const stringTag = Object.getStringTag(value)\n\n switch (stringTag) {\n case 'Null': return null\n case 'Undefined': return undefined\n default:\n return owner[stringTag]\n }\n },\n\n /**\n * Determines if the provided value is an object. This method checks whether the\n * value is an instance of `Object` or if its type is 'object'. It's a utility\n * method for type-checking, ensuring that a value is an object before performing\n * operations that are specific to objects.\n *\n * @param {*} value - The value to be checked.\n * @returns {boolean} - Returns `true` if the value is an object, otherwise `false`.\n */\n isObject(value) {\n return value && (value instanceof Object || typeof value === 'object');\n },\n\n /**\n * Checks to see if the supplied value is a primitive value.\n *\n * @param {any} value the value to test to see if it is a primitive value type\n * @returns true if the object is considered widely to be a primitive value,\n * false otherwise.\n */\n isPrimitive(value) {\n // Check for null as a special case because typeof null\n // is 'object'\n if (value === null) {\n return true;\n }\n\n // Check for other primitives\n switch (typeof value) {\n case 'string':\n case 'number':\n case 'bigint':\n case 'boolean':\n case 'undefined':\n case 'symbol':\n return true;\n default:\n return false;\n }\n },\n\n /**\n * Checks if the given value is a valid key for an object. In JavaScript, a valid\n * key can be either a string or a symbol. This method is useful for validating\n * object keys before using them in operations like setting or getting object properties.\n *\n * @param {*} value - The value to be checked.\n * @returns {boolean} - Returns `true` if the value is a valid object key (string or symbol),\n * otherwise `false`.\n */\n isValidKey(value) {\n return (typeof value === 'string' || typeof value === 'symbol');\n },\n\n /**\n * Strips an object down to only the keys specified. Optionally, any\n * accessors can be made to retain their context on the source object.\n *\n * @param {object} object the object to pare down\n * @param {Array<string|symbol>} keys the keys that should appear in the\n * final reduced object\n * @param {boolean} [bindAccessors = true] if this value is true\n * then any accessors from the source object will continue to have their\n * `this` value bound to the source. If the getter or setter on that object\n * is defined using an arrow function, this will not work as intended.\n * @returns {object} an object containing only the keys and symbols specified\n * in the `keys` parameter.\n */\n stripTo(object, keys, bindAccessors = true) {\n const result = {}\n\n if (!Array.isArray(keys)) {\n return result\n }\n\n for (let key of keys) {\n if (Reflect.has(object, key)) {\n const descriptor = Object.getOwnPropertyDescriptor(object, key)\n if (Reflect.has(descriptor, 'get') || Reflect.has(descriptor, 'set')) {\n if (bindAccessors) {\n descriptor.get = descriptor?.get?.bind(object)\n descriptor.set = descriptor?.set?.bind(object)\n }\n Object.defineProperty(result, descriptor)\n }\n else {\n Object.defineProperty(result, descriptor)\n }\n }\n }\n\n return result\n },\n\n});\n", "import { Patch } from '@nejs/extension'\nimport { ObjectExtensions } from './objectextensions.js'\n\n/**\n * The `ReflectExtensions` class is a patch applied to the built-in JavaScript\n * `Reflect` object. It extends `Reflect` with additional utility methods that\n * enhance its capabilities. These methods provide more advanced ways of\n * interacting with object properties, such as checking for the presence of\n * multiple keys at once (`hasAll`) or verifying if at least one specified key\n * exists in an object (`hasSome`). This class is part of the `@nejs/extension`\n * library and is designed to offer these extended functionalities in a way\n * that is consistent with the existing `Reflect` API, making it intuitive for\n * developers who are already familiar with standard reflection methods in\n * JavaScript.\n */\nexport const ReflectExtensions = new Patch(Reflect, {\n /**\n * The function checks if an object has all the specified keys.\n *\n * @param object - The `object` parameter is the object that we want to\n * check if it has all the specified keys.\n * @param keys - The `keys` parameter is a rest parameter, which means\n * it can accept any number of arguments. In this case, it is expected\n * to receive multiple keys as arguments.\n * @returns a boolean value.\n */\n hasAll(object, ...keys) {\n return Object.isObject(object) && (keys.flat(Infinity)\n .map(key => Reflect.has(object, key))\n .every(has => has)\n )\n },\n\n ownDescriptors(object) {\n const result = {}\n const revertOnDone = () => revertOnDone.doIt ? ObjectExtensions.revert() : ''\n revertOnDone.doIt = false\n\n if (!Object.isObject) {\n revertOnDone.doIt = true\n ObjectExtensions.apply()\n }\n\n if (!Object.isObject(object)) {\n revertOnDone()\n return {}\n }\n\n const keys = Reflect.ownKeys(object)\n\n for (const key of keys) {\n result[key] = Object.getOwnPropertyDescriptor(key)\n }\n\n revertOnDone()\n\n return result\n },\n\n /**\n * The function checks if an object has at least one of the specified keys.\n *\n * @param object - The `object` parameter is the object that we want to check\n * for the presence of certain keys.\n * @param keys - The `keys` parameter is a rest parameter, which means it can\n * accept any number of arguments. These arguments are the keys that we want\n * to check if they exist in the `object`.\n * @returns The function `hasSome` returns a boolean value indicating whether\n * at least one of the keys provided as arguments exists in the given object.\n */\n hasSome(object, ...keys) {\n return Object.isObject(object) && (keys.flat(Infinity)\n .map(key => Reflect.has(object, key))\n .some(has => has)\n )\n },\n\n /**\n * Retrieves an array of [key, descriptor] pairs for each property of the\n * provided object. This method is akin to `Object.entries` but includes\n * property descriptors instead of the property values. It's useful for cases\n * where you need detailed information about properties, including their\n * configurability, enumerability, and accessors.\n *\n * @param {object} object - The object whose property entries are to be\n * retrieved.\n * @returns {Array} An array of [key, descriptor] pairs, where each pair\n * consists of the property name (key) and its descriptor. Returns an empty\n * array if the input is not a valid object.\n */\n entries(object) {\n if (!object || typeof object !== 'object') { return [] }\n\n return Reflect.ownKeys(object).map(key => [\n key, Object.getOwnPropertyDescriptor(object, key)\n ])\n },\n\n /**\n * Retrieves an array of values from the property descriptors of the given\n * object. This method works similarly to `Object.values` but operates on\n * property descriptors instead. It's useful when you need the values of\n * properties including getters, setters, and other descriptor-specific\n * attributes.\n *\n * @param {object} object - The object whose property values are to be\n * retrieved.\n * @returns {Array} An array of values extracted from the object's property\n * descriptors. The values correspond to the `value` attribute in each\n * property's descriptor. Returns an empty array if the input is not a valid\n * object.\n */\n values(object) {\n return Reflect.entries.map(([,value]) => value)\n }\n})\n", "import { Patch } from '@nejs/extension';\n\n/**\n * `StringExtensions` is a patch for the JavaScript built-in `String` class. It\n * adds utility methods to the `String` class without modifying the global namespace\n * directly. This patch includes methods for key validation, object type checking,\n * and retrieving the string tag of an object. These methods are useful for\n * enhancing the capabilities of the standard `String` class with additional\n * utility functions.\n */\nexport const StringExtensions = new Patch(String, {\n /**\n * The `isString` method does exactly what one would it expect. It returns\n * true if the string matches typeof or instanceof as a string.\n *\n * @param {*} value checks to see if the `value` is a string\n * @returns {boolean} `true` if it is a `String`, `false` otherwise\n */\n isString(value) {\n if (value && (typeof value === 'string' || value instanceof String)) {\n return value.length > 0\n }\n return false\n },\n});\n", "import { Patch } from '@nejs/extension';\n\n/**\n * `SymbolExtensions` is a patch for the JavaScript built-in `Symbol` class. It\n * adds utility methods to the `Symbol` class without modifying the global namespace\n * directly. This patch includes methods for key validation, object type checking,\n * and retrieving the string tag of an object. These methods are useful for\n * enhancing the capabilities of the standard `Symbol` class with additional\n * utility functions.\n */\nexport const SymbolExtensions = new Patch(Symbol, {\n /**\n * The `isSymbol` method does exactly what one would it expect. It returns\n * true if the string matches typeof or instanceof as a symbol.\n *\n * @param {*} value checks to see if the `value` is a string\n * @returns {boolean} `true` if it is a `Symbol`, `false` otherwise\n */\n isSymbol(value) {\n if (value && (typeof value === 'symbol')) {\n return true\n }\n return false\n },\n});\n", "import { Patch } from '@nejs/extension'\n\n/**\n * The `ArrayPrototypeExtensions` patch extends the prototype of the built-in\n * JavaScript `Array` with additional properties for convenience and improved\n * readability. By applying this patch, all array instances gain new getter\n * properties `first` and `last`, which provide quick access to the first and\n * last elements of the array, respectively. This enhancement simplifies common\n * operations on arrays and makes code more expressive and concise.\n */\nexport const ArrayPrototypeExtensions = new Patch(Array.prototype, {\n /**\n * Sometimes defining even a short function for the invocation of `find`\n * can be troublesome. This helper function performs that job for you. If\n * the specified element is in the array, `true` will be returned.\n *\n * @param {*} value the value to search for. This value must triple equals\n * the array element in order to return true.\n * @returns true if the exact element exists in the array, false otherwise\n */\n contains(value) {\n return !!this.find(entry => entry === value)\n },\n\n /**\n * The `findEntry` function searches the entries of the object and returns\n * the `[index, value]` entry array for the first matching value found.\n *\n * @param {function} findFn a function that takes the element to be checked\n * and returns a boolean value\n * @returns if `findFn` returns `true`, an array with two elements, the first\n * being the index, the second being the value, is returned.\n */\n findEntry(findFn) {\n const entries = this.entries()\n const VALUE = 1\n\n for (let entry of entries) {\n if (findFn(entry[VALUE])) {\n return entry\n }\n }\n\n return undefined\n },\n\n /**\n * A getter property that returns the first element of the array. If the\n * array is empty, it returns `undefined`. This property is useful for\n * scenarios where you need to quickly access the first item of an array\n * without the need for additional checks or method calls.\n *\n * @returns {*} The first element of the array or `undefined` if the array\n * is empty.\n */\n get first() {\n return this[0];\n },\n\n /**\n * A getter property that returns the last element of the array. It\n * calculates the last index based on the array's length. If the array is\n * empty, it returns `undefined`. This property is beneficial when you need\n * to access the last item in an array, improving code readability and\n * avoiding manual index calculation.\n *\n * @returns {*} The last element of the array or `undefined` if the\n * array is empty.\n */\n get last() {\n return this[this.length - 1];\n },\n\n})", "import { Extension } from '@nejs/extension'\nimport { ObjectExtensions } from './objectextensions.js'\nimport { StringExtensions } from './stringextensions.js'\nimport { ReflectExtensions } from './reflectextensions.js'\n\nconst isObject = ObjectExtensions.patchEntries?.isObject?.computed\nconst isValidKey = ObjectExtensions.patchEntries?.isValidKey?.computed\nconst isString = StringExtensions.patchEntries?.isString?.computed\nconst hasSome = ReflectExtensions.patchEntries?.hasSome?.computed\n\nclass Descriptor {\n #desc = Descriptor.enigmatic\n\n /**\n * Creates a new instance of Descriptor either from another object or\n * around the supplied object descriptor value.\n *\n * @param {object} object either an object descriptor or the object\n * from which to get the descriptor\n * @param {symbol|string} key a valid key for accessing the descriptor\n * on the aforesupplied object.\n */\n constructor(object, key) {\n this.#desc = object\n\n if (isObject(object) && isValidKey(key)) {\n this.#desc = Object.getOwnPropertyDescriptor(object, key)\n }\n\n if (!this.isDescriptor) {\n throw new Error(`Not a valid descriptor:`, this.#desc)\n }\n }\n\n /**\n * Detects whether or not this instance is an accessor object descriptor\n *\n * @returns {boolean} true if this object has a getter or setter and is not\n * a data descriptor\n */\n get isAccessor() {\n return Descriptor.isAccessor(this.#desc)\n }\n\n /**\n * Detects whether or not this instance is an data object descriptor\n *\n * @returns {boolean} true if this object has a value property and is not\n * an accessor descriptor\n */\n get isData() {\n return Descriptor.isData(this.#desc)\n }\n\n /**\n * Detects whether or not this instance is a valid object descriptor\n *\n * @returns {boolean} true if this descriptor store is a valid descriptor\n */\n get isDescriptor() {\n return Descriptor.isDescriptor(this.#desc)\n }\n\n /**\n * Getter around the `configurable` object descriptor property of\n * this instance of Descriptor.\n *\n * @returns {boolean} a boolean value or undefined if the internal\n * descriptor store is invalid.\n */\n get configurable() {\n return !!this.#desc?.configurable\n }\n\n /**\n * Sets the `configurable` value of this object. If the internal descriptor\n * store store is invalid, the value is thrown away\n *\n * @param {boolean} value the value to set for the `configurable` descriptor\n * property. If this value is not a `boolean` it will be converted to one\n */\n set configurable(value) {\n (this.#desc || {}).configurable = !!value\n }\n\n /**\n * Getter around the `enumerable` object descriptor property of\n * this instance of Descriptor.\n *\n * @returns {boolean} a boolean value or undefined if the internal\n * descriptor store is invalid.\n */\n get enumerable() {\n return this.#desc?.enumerable\n }\n\n /**\n * Sets the `enumerable` value of this object. If the internal descriptor\n * store is invalid, the value is thrown away\n *\n * @param {boolean} value the value to set for the `enumerable` descriptor\n * property. If this value is not a `boolean` it will be converted to one\n */\n set enumerable(value) {\n (this.#desc || {}).enumerable = value\n }\n\n /**\n * Getter around the `writable` object descriptor property of\n * this instance of Descriptor.\n *\n * @returns {boolean} a boolean value or undefined if the internal\n * descriptor store is invalid.\n */\n get writable() {\n return this.#desc?.writable\n }\n\n /**\n * Sets the `writable` value of this object. If the internal descriptor\n * store is invalid, the value is thrown away\n *\n * @param {boolean} value the value to set for the `writable` descriptor\n * property. If this value is not a `boolean` it will be converted to one\n */\n set writable(value) {\n (this.#desc || {}).writable = value\n }\n\n /**\n * Getter around the `value` object descriptor property of\n * this instance of Descriptor.\n *\n * @returns {any} any value stored in this descriptor\n */\n get value() {\n return this.#desc?.value\n }\n\n /**\n * Sets the `value` value of this object. If the internal descriptor\n * store is invalid, the value is thrown away\n *\n * @param {any} value the value to set for the `value` descriptor\n * property.\n */\n set value(value) {\n (this.#desc || {}).value = value\n }\n\n /**\n * Getter around the `get` object descriptor property of\n * this instance of Descriptor.\n *\n * @returns {function} a function if the getter for this descriptor is\n * defined or `undefined` if the internal descriptor object or the getter\n * is undefined.\n */\n get get() {\n return this.#desc?.get\n }\n\n /**\n * Sets the `get` value of this object. If the internal descriptor\n * store is invalid, the value is thrown away\n *\n * @param {function} value the getter function for this descriptor\n */\n set get(value) {\n (this.#desc || {}).get = value\n }\n\n /**\n * Getter around the `set` object descriptor property of\n * this instance of Descriptor.\n *\n * @returns {function} a function if the setter for this descriptor is\n * defined or `undefined` if the internal descriptor object or the setter\n * is undefined.\n */\n get set() {\n return this.#desc?.writable\n }\n\n /**\n * Sets the `set` value of this object. If the internal descriptor\n * store is invalid, the value is thrown away\n *\n * @param {function} value the setter function for this descriptor\n */\n set set(value) {\n (this.#desc || {}).set = value\n }\n\n /**\n * Shorthand for Object.getOwnPropertyDescriptor()\n *\n * @param {object} object a non-null object instance\n * @param {string|symbol} key a symbol or string referencing which key on the\n * object to return a descriptor for.\n * @returns an object descriptor for the requested field or null\n */\n static for(object, key) {\n if (!isObject(object) && !isValidKey(key)) {\n return null\n }\n\n return Object.getOwnPropertyDescriptor(object, key)\n }\n\n /**\n * Take the descriptor defined by this objects values and apply them to\n * the specified object using the specified key.\n *\n * @param {object} object the object to apply this descriptor to\n * @param {string|symbol} forKey the string or symbol for which this\n * descriptor will abe applied\n */\n applyTo(object, forKey) {\n if (!isObject(object) || !isValidKey(forKey)) {\n throw new Error(`Cannot apply descriptor to non-object or invalid key`)\n }\n\n return Object.defineProperty(object, forKey, this.#desc)\n }\n\n /**\n * Converts this descriptor object into a base representation\n *\n * @param {string} hint one of `string`, `number` or default;\n * @returns if the hint is 'string', then a string identifying the enum\n * and its type is returned. `number` will always be NaN since it is incoret\n */\n [Symbol.toPrimitive](hint) {\n switch (hint) {\n case 'string':\n if (this.isAccessor) {\n const hasGetter = Reflect.has(this.#desc, 'get') ? `getter` : ''\n const hasSetter = Reflect.has(this.#desc, 'set') ? `setter` : ''\n const separator = hasGetter && hasSetter ? ', ' : ''\n\n return `Accessor (${hasGetter}${separator}${hasSetter})`\n }\n else if (this.isData) {\n const hasGetter = Reflect.has(this.#desc, 'value') ? `value` : ''\n const hasSetter = Reflect.has(this.#desc, 'writable') ? `writable` : ''\n const separator = hasGetter && hasSetter ? ', ' : ''\n\n return `Data (${hasGetter}${separator}${hasSetter})`\n }\n break\n\n case 'number':\n return NaN\n\n default:\n return this.#desc\n }\n }\n\n /**\n * The function `getData` retrieves the value of a property from an object if it\n * exists and is a data property.\n *\n * @param object - The \"object\" parameter is the object from which we want to\n * retrieve data.\n * @param property - The `property` parameter is the name of the property that\n * you want to retrieve the data from.\n * @returns either the value of the specified property if it exists and is a data\n * property, or undefined if the property does not exist or is not a data\n * property.\n */\n static getData(object, property) {\n if (!isObject(object) || !isString(property)) {\n return null;\n }\n\n const descriptors = Descriptor.all(object)\n if (descriptors.has(property)) {\n const descriptor = descriptors.get(property)\n\n if (Descriptor.isData(descriptor)) {\n return descriptor.value\n }\n }\n\n return undefined\n }\n\n /**\n * The function `getAccessor` checks if an object has a getter/setter accessor\n * for a given property and returns the accessor functions if found.\n *\n * @param object - The `object` parameter is the object from which we want to\n * retrieve the accessor for a specific property.\n * @param property - The `property` parameter is the name of the property for\n * which we want to get the accessor.\n * @returns an object that contains the getter and setter functions for the\n * specified property of the given object. If the property is an accessor\n * property (defined with a getter and/or setter), the returned object will also\n * have additional properties such as \"accessor\" and \"descriptor\". If the\n * property is not found or is not an accessor property, the function returns\n * undefined.\n */\n static getAccessor(object, property) {\n if (!isObject(object))\n return null\n\n const [GETTER, SETTER, OBJECT] = [0, 1, 2]\n const results = [undefined, undefined, undefined]\n const descriptors = this.all(object)\n const isDescriptor = Descriptor.isDescriptor(object)\n\n if (descriptors.has(property) || isDescriptor) {\n const descriptor = isDescriptor ? object : descriptors.get(property)\n\n if (Descriptor.isAccessor(descriptor)) {\n results[OBJECT] = descriptors.object(property)\n results[GETTER] = descriptor?.get\n results[SETTER] = descriptor?.set\n\n Object.assign(results, {\n get() { this[GETTER].bind(this[OBJECT])() },\n set(value) { this[SETTER].bind(this[OBJECT])(value) },\n get accessor() { return true },\n get descriptor() { return descriptor },\n get boundDescriptor() {\n return {\n ...descriptor,\n get: descriptor.get?.bind(object),\n set: descriptor.set?.bind(object),\n }\n }\n })\n\n return results\n }\n }\n\n return undefined\n }\n\n /**\n * The function returns an object with enumerable and configurable properties\n * based on the input parameters.\n *\n * @param [enumerable=false] - A boolean value indicating whether the property\n * can be enumerated (listed) when iterating over the object's properties.\n * @param [configurable=false] - The `configurable` parameter determines whether\n * the property can be deleted or its attributes can be modified. If\n * `configurable` is set to `true`, the property can be deleted and its\n * attributes can be changed. If `configurable` is set to `false`, the property\n * cannot be deleted and\n * @returns An object with the properties `enumerable` and `configurable` is\n * being returned. The values of these properties are determined by the arguments\n * passed to the `base` function.\n */\n static base(enumerable = false, configurable = false) {\n return {\n enumerable,\n configurable\n }\n }\n\n /**\n * The function \"newAccessor\" creates a new property descriptor object with a\n * getter and setter function, along with optional enumerable and configurable\n * flags.\n *\n * @param getter - The getter parameter is a function that will be used as the\n * getter for the property. It will be called when the property is accessed.\n * @param setter - The `setter` parameter is a function that will be used as the\n * setter for the property. It will be called whenever the property is assigned a\n * new value.\n * @param [] - - `getter`: A function that will be used as the getter for the\n * property.\n * @returns an object with properties \"get\", \"set\", \"enumerable\", and\n * \"configurable\".\n */\n static accessor(\n getter,\n setter,\n { enumerable, configurable } = Descriptor.base()\n ) {\n return {\n get: getter,\n set: setter,\n enumerable,\n configurable\n }\n }\n\n /**\n * The function \"newData\" creates a new data object with customizable properties.\n *\n * @param value - The value parameter represents the value that will be assigned\n * to the property.\n * @param [writable=true] - The `writable` parameter determines whether the value\n * of the property can be changed. If `writable` is set to `true`, the value can\n * be changed. If `writable` is set to `false`, the value cannot be changed.\n * @param [] - - `value`: The value to be assigned to the property.\n * @returns an object with properties `value`, `enumerable`, `writable`, and\n * `configurable`.\n */\n static data(\n value,\n writable = true,\n { enumerable, configurable } = Descriptor.base()\n ) {\n return {\n value,\n enumerable,\n writable,\n configurable\n }\n }\n\n /**\n * The function checks if an object is a valid object descriptor in JavaScript.\n *\n * @param object - The `object` parameter is the object that we want to check if\n * it is a descriptor.\n * @returns a boolean value.\n */\n static isDescriptor(object) {\n const knownKeys = [\n ...Descriptor.SHARED_KEYS,\n ...Descriptor.ACCESSOR_KEYS,\n ...Descriptor.DATA_KEYS,\n ]\n\n return hasSome(object, knownKeys)\n }\n\n /**\n * The function checks if a given property or descriptor is a data property.\n *\n * @param descriptor_orProp - The `descriptor_orProp` parameter can be either a\n * descriptor or a property name.\n * @param object - The `object` parameter is the object that you want to check\n * for data properties.\n * @returns a boolean value. It returns `true` if the `descriptor` object has any\n * keys that match the `DATA_KEYS` array, otherwise it returns `false`.\n */\n static isData(object_orProp, property) {\n const needsDescriptor = (\n ((typeof object_orProp === 'object') || object_orProp instanceof Object) &&\n property instanceof String\n )\n\n const descriptor = (needsDescriptor\n ? Descriptor.for(object_orProp, property)\n : object_orProp\n )\n\n const { ACCESSOR_KEYS, DATA_KEYS } = this\n let validData = false\n\n if (hasSome(descriptor, ACCESSOR_KEYS)) {\n validData = false\n }\n else if (hasSome(descriptor, DATA_KEYS)) {\n validData = true\n }\n\n return validData\n }\n\n /**\n * The function checks if a given property descriptor or property of an object is\n * an accessor.\n *\n * @param object_orProp - The `descriptor_orProp` parameter can be either a\n * descriptor object or a property name.\n * @param property - The `object` parameter is the object that you want to check\n * for accessor properties.\n * @returns a boolean value. It returns true if the descriptor or property passed\n * as an argument is an accessor descriptor, and false otherwise.\n */\n static isAccessor(object_orProp, property) {\n const needsDescriptor = (\n (object_orProp && property) &&\n ((typeof object_orProp === 'object') || object_orProp instanceof Object) &&\n (property instanceof String || (typeof property === 'symbol'))\n )\n\n const descriptor = (needsDescriptor\n ? Descriptor.for(object_orProp, property)\n : object_orProp)\n\n const { ACCESSOR_KEYS, DATA_KEYS } = this\n let validAccessor = false\n\n if (hasSome(descriptor, DATA_KEYS)) {\n validAccessor = false\n }\n else if (hasSome(descriptor, ACCESSOR_KEYS)) {\n validAccessor = true\n }\n\n return validAccessor\n }\n\n /**\n * A base descriptor (new for each read) that is both enumerable and configurable\n *\n * @returns The method `flexible` is returning the result of calling the `base`\n * method with the arguments `true` and `true`.\n */\n static get flexible() {\n return this.base(true, true)\n }\n\n /**\n * A base descriptor (new for each read) that is not enumerable but is configurable\n *\n * @returns The method `enigmatic` is returning the result of calling the `base`\n * method with the arguments `false` and `true`.\n */\n static get enigmatic() {\n return this.base(false, true)\n }\n\n /**\n * A base descriptor (new for each read) that is neither enumerable nor configurable\n *\n * @returns The code is returning the result of calling the `base` method with\n * the arguments `false` and `false`.\n */\n static get intrinsic() {\n return this.base(false, false)\n }\n\n /**\n * A base descriptor (new for each read) that enumerable but not configurable\n *\n * @returns The method is returning the result of calling the `base` method with\n * the arguments `true` and `false`.\n */\n static get transparent() {\n return this.base(true, false)\n }\n\n /**\n * The function returns an array of shared descriptor keys.\n *\n * @returns An array containing the strings 'configurable' and 'enumerable'.\n */\n static get SHARED_KEYS() {\n return ['configurable', 'enumerable']\n }\n\n /**\n * The function returns an array of accessor descriptor keys.\n *\n * @returns An array containing the strings 'get' and 'set' is being returned.\n */\n static get ACCESSOR_KEYS() {\n return ['get', 'set']\n }\n\n /**\n * The function returns an array of data descriptor keys.\n *\n * @returns An array containing the strings 'value' and 'writable' is being\n * returned.\n */\n static get DATA_KEYS() {\n return ['value', 'writable']\n }\n}\n\nexport const DescriptorExtension = new Extension(Descriptor)", "import { Patch } from '@nejs/extension'\nimport { FunctionExtensions } from './functionextensions.js'\n\nconst { isClass, isFunction } = FunctionExtensions.patchEntries.isClass.computed\nconst CustomInspect = Symbol.for('nodejs.util.inspect.custom')\n\nexport const GlobalFunctionsAndProps = new Patch(globalThis, {\n asBigIntObject(\n bigIntPrimitive\n ) {\n const base = { configurable: true, enumerable: false }\n const object = { value: bigIntPrimitive }\n\n Object.defineProperties(object, {\n // @ts-ignore\n [Symbol.toPrimitive]: { value: function() { return bigIntPrimitive }, ...base },\n [Symbol.toStringTag]: { value: BigInt.name, ...base },\n [Symbol.species]: { get() { return BigInt }, ...base },\n [CustomInspect]: { ...base, value(depth, opts, inspect) {\n return inspect(this[Symbol.toPrimitive](), { ...opts, depth })\n }}\n })\n\n Object.setPrototypeOf(object, BigInt.prototype)\n\n Reflect.ownKeys(BigInt.prototype).forEach(key => {\n if (typeof object[key] !== 'function') {\n return\n }\n\n object[key] = (function (...args) {\n return BigInt.prototype[key].apply(this, args)\n }).bind(object.value)\n })\n\n return object\n },\n\n /**\n * Transforms an object to mimic a specified prototype, altering its type conversion\n * and inspection behaviors. This function is especially useful for creating objects\n * that need to behave like different primitive types under various operations.\n *\n * @param {Object} object - The object to be transformed.\n * @param {Function|Object} [prototype=String.prototype] - The prototype or class to\n * emulate. If a function is provided, its prototype is used. Defaults to\n * String.prototype.\n * @param {Function} [toPrimitive=(hint, val) => String(val)] - A function defining how\n * the object should be converted to a primitive value. It receives a type hint\n * ('number', 'string', or 'default') and the object, returning the primitive value.\n * @returns {Object|null} The transformed object, or null if neither a class nor a\n * prototype could be derived from the provided prototype parameter.\n */\n maskAs(object, classPrototype, options) {\n const {\n prototype,\n toPrimitive\n } = GenericMask({...options, prototype: classPrototype})\n\n const base = { configurable: true, enumerable: false }\n const proto = isFunction(prototype) ? prototype.prototype : prototype\n const klass = isClass(prototype) ? prototype : proto?.constructor\n\n if (!klass && !proto) {\n return null\n }\n\n Object.setPrototypeOf(object, proto)\n Object.defineProperties(object, {\n valueOf: { value() { return String(toPrimitive('default', object)) }, ...base },\n\n [Symbol.toPrimitive]: { value(hint) { return toPrimitive(hint, object) }, ...base },\n [Symbol.toStringTag]: { value: klass.name, ...base },\n [Symbol.species]: { get() { return klass }, ...base },\n [CustomInspect]: { ...base, value(depth, opts, inspect) {\n return inspect(this[Symbol.toPrimitive](), { ...opts, depth })\n }}\n })\n\n return object\n },\n\n /**\n * Masks an object as a string-like object by setting its prototype to String and\n * defining how it converts to primitive types. This is particularly useful when an\n * object needs to behave like a string in certain contexts, such as type coercion or\n * logging.\n *\n * @param {Object} object - The object to be masked as a string.\n * @param {string} [stringKey='value'] - The object property key used for the string\n * representation. Defaults to 'value'.\n * @param {Function} [toPrimitive] - Optional custom function for primitive conversion.\n * If omitted, a default function handling various conversion hints is used.\n * @returns {Object|null} The string-masked object, or null if the object doesn't have\n * the specified stringKey property.\n */\n maskAsString(\n object,\n stringKey,\n toPrimitive\n ) {\n if (object && Reflect.has(object, stringKey)) {\n return maskAs(object, StringMask(stringKey ?? 'value', toPrimitive))\n }\n\n return null\n },\n\n /**\n * Masks an object as a number-like object. This allows the object to behave like a\n * number in operations like arithmetic and type coercion. It sets the prototype to\n * Number and defines custom conversion behavior.\n *\n * @param {Object} object - The object to be masked as a number representation.\n * Defaults to 'value'.\n * @param {Function} [toPrimitive] - Optional custom function for primitive\n * conversion. If not provided, a default function handling different conversion\n * hints is used.\n * @returns {Object|null} The number-masked object, or null if the object doesn't\n * have the specified numberKey property.\n */\n maskAsNumber(\n object,\n numberKey,\n toPrimitive\n ) {\n if (object && Reflect.has(object, numberKey)) {\n return maskAs(object, NumberMask(numberKey ?? 'value', toPrimitive))\n }\n\n return null\n },\n\n /**\n * Generates options for generic masking of an object, providing defaults for\n * prototype and toPrimitive function if not specified.\n *\n * @param {Object} options - The options object including prototype, targetKey,\n * and toPrimitive function.\n * @returns {Object} The options object with defaults applied as necessary.\n */\n GenericMask({ prototype, targetKey = 'value', toPrimitive }) {\n const options = { targetKey, toPrimitive, prototype };\n\n if (!isFunction(toPrimitive)) {\n options.toPrimitive = (hint, object) => {\n let property = object[targetKey];\n let isNum = (typeof property === 'number' && Number.isFinite(property)) ||\n (typeof property === 'string' &&\n !isNaN(parseFloat(property)) && isFinite(property)\n );\n\n switch (hint) {\n case 'string': return isNum ? String(property) : (property ?? String(object));\n case 'number': return isNum ? Number(property) : NaN;\n case 'default':\n default:\n return isNum ? Number(property) : property;\n }\n }\n }\n\n return options;\n },\n\n /**\n * Generates options for string masking of an object, providing a default toPrimitive\n * function if not specified.\n *\n * @param {string} targetKey - The object property key for string representation.\n * @param {Function} toPrimitive - Custom function for primitive conversion.\n * @returns {Object} Options for string masking.\n */\n StringMask(targetKey, toPrimitive) {\n const options = { targetKey, toPrimitive, prototype: String.prototype }\n\n if (!isFunction(toPrimitive)) {\n options.toPrimitive = function toPrimitive(hint, object) {\n switch (hint) {\n case 'default': return object[targetKey]\n case 'number': return parseInt(object[targetKey], 36)\n case 'string': return String(object[targetKey])\n default: return object\n }\n }\n }\n\n return options\n },\n\n /**\n * Generates options for number masking of an object, providing a default toPrimitive\n * function if not specified.\n *\n * @param {string} targetKey - The object property key for number representation.\n * @param {Function} toPrimitive - Custom function for primitive conversion.\n * @returns {Object} Options for number masking.\n */\n NumberMask(targetKey, toPrimitive) {\n const options = { targetKey, toPrimitive, prototype: Number.prototype }\n\n if (!isFunction(toPrimitive)) {\n options.toPrimitive = function toPrimitive(hint, object) {\n switch (hint) {\n case 'default': return object[targetKey]\n case 'number': return Number(object[targetKey])\n case 'string': return String(object[targetKey])\n default: return object\n }\n }\n }\n\n return options\n },\n\n})\n"],
|
|
5
|
+
"mappings": "0bAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8BAAAE,EAAA,wBAAAC,EAAA,uBAAAC,EAAA,4BAAAC,EAAA,qBAAAC,EAAA,sBAAAC,EAAA,qBAAAC,EAAA,qBAAAC,EAAA,QAAAC,EAAA,eAAAC,EAAA,cAAAC,ICCA,IAAMC,EAASC,GAAK,SAAS,KAAK,OAAO,UAAU,SAAS,KAAKA,CAAC,CAAC,EAAE,CAAC,EASzDC,EAAN,cAAoC,KAAM,CAS7C,YAAYC,EAAOC,EAAK,CACpB,MAAM,GAAGJ,EAAOG,CAAK,CAAC,6BAA6BC,CAAG,GAAG,EACzD,OAAO,OAAO,KAAM,CAAE,MAAAD,EAAO,IAAAC,CAAI,CAAC,CACtC,CAOA,IAAK,OAAO,WAAW,GAAI,CACvB,OAAO,KAAK,YAAY,IAC5B,CACJ,EC/BA,IAAMC,EAASC,GAAK,SAAS,KAAK,OAAO,UAAU,SAAS,KAAKA,CAAC,CAAC,EAAE,CAAC,EAOzDC,EAAN,cAAgC,KAAM,CAQzC,YAAYC,EAAOC,EAAK,CACpB,MAAM,GAAGJ,EAAOG,CAAK,CAAC,oCAAoCC,CAAG,IAAI,EACjE,OAAO,OAAO,KAAM,CAAE,MAAAD,EAAO,IAAAC,CAAI,CAAC,CACtC,CAQA,IAAK,OAAO,WAAW,GAAI,C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,CACxB,CAAC,EAEDN,EAAO,QAAQQ,GAAa,CAC1BA,EAAU,OAAO,CACnB,CAAC,CACH,CAEO,IAAME,EACM,CACfC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEAf,EACAC,CACF,EAEwB,OAAO,CAACe,EAAaT,KAC3C,QAAQ,QAAQA,EAAU,YAAY,EAAE,OAAO,CAACU,EAAGC,KACjDF,EAAYE,CAAG,EAAIX,EAAU,aAAaW,CAAG,EAAE,SACxCF,GACNA,CAAW,EAEPA,GACN,CAAC,CAAC",
|
|
6
|
+
"names": ["src_exports", "__export", "ArrayPrototypeExtensions", "DescriptorExtension", "FunctionExtensions", "GlobalFunctionsAndProps", "ObjectExtensions", "ReflectExtensions", "StringExtensions", "SymbolExtensions", "all", "disableAll", "enableAll", "typeOf", "o", "CannotBeExtendedError", "owner", "key", "typeOf", "o", "MissingOwnerValue", "owner", "key", "PatchToggle", "patch", "preventRevert", "depth", "options", "inspect", "objName", "status", "Patch", "_Patch", "owner", "patches", "options", "key", "#PatchEntry", "patch", "preventRevert", "PatchToggle", "e", "property", "owningObject", "depth", "inspect", "Extension", "_Extension", "Patch", "keyClassOrFn", "value", "owner", "options", "key", "extension", "valid", "MissingOwnerValue", "descriptor", "CannotBeExtendedError", "input", "depth", "inspect", "FunctionExtensions", "Patch", "value", "stringTag", "ObjectExtensions", "Patch", "value", "owner", "stringTag", "object", "keys", "bindAccessors", "result", "key", "descriptor", "ReflectExtensions", "Patch", "object", "keys", "key", "has", "result", "revertOnDone", "ObjectExtensions", "value", "StringExtensions", "Patch", "value", "SymbolExtensions", "Patch", "value", "ArrayPrototypeExtensions", "Patch", "value", "entry", "findFn", "entries", "VALUE", "isObject", "ObjectExtensions", "isValidKey", "isString", "StringExtensions", "hasSome", "ReflectExtensions", "Descriptor", "_Descriptor", "#desc", "object", "key", "value", "forKey", "hint", "hasGetter", "hasSetter", "property", "descriptors", "descriptor", "GETTER", "SETTER", "OBJECT", "results", "isDescriptor", "enumerable", "configurable", "getter", "setter", "writable", "knownKeys", "object_orProp", "ACCESSOR_KEYS", "DATA_KEYS", "validData", "validAccessor", "DescriptorExtension", "Extension", "isClass", "isFunction", "FunctionExtensions", "CustomInspect", "GlobalFunctionsAndProps", "Patch", "bigIntPrimitive", "base", "object", "depth", "opts", "inspect", "key", "args", "classPrototype", "options", "prototype", "toPrimitive", "proto", "klass", "hint", "stringKey", "numberKey", "targetKey", "property", "isNum", "Owners", "NetNew", "GlobalFunctionsAndProps", "DescriptorExtension", "enableAll", "owners", "list", "owner", "Patch", "extension", "disableAll", "all", "ObjectExtensions", "FunctionExtensions", "ReflectExtensions", "StringExtensions", "SymbolExtensions", "ArrayPrototypeExtensions", "accumulator", "_", "key"]
|
|
7
|
+
}
|
package/dist/cjs/descriptor.js
CHANGED
|
@@ -15,11 +15,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.DescriptorExtension = void 0;
|
|
16
16
|
const extension_1 = require("@nejs/extension");
|
|
17
17
|
const objectextensions_js_1 = require("./objectextensions.js");
|
|
18
|
+
const stringextensions_js_1 = require("./stringextensions.js");
|
|
18
19
|
const reflectextensions_js_1 = require("./reflectextensions.js");
|
|
19
|
-
const isObject = objectextensions_js_1.ObjectExtensions.patchEntries
|
|
20
|
-
const isValidKey = objectextensions_js_1.ObjectExtensions.patchEntries
|
|
21
|
-
const isString =
|
|
22
|
-
const hasSome = reflectextensions_js_1.ReflectExtensions.patchEntries
|
|
20
|
+
const isObject = objectextensions_js_1.ObjectExtensions.patchEntries?.isObject?.computed;
|
|
21
|
+
const isValidKey = objectextensions_js_1.ObjectExtensions.patchEntries?.isValidKey?.computed;
|
|
22
|
+
const isString = stringextensions_js_1.StringExtensions.patchEntries?.isString?.computed;
|
|
23
|
+
const hasSome = reflectextensions_js_1.ReflectExtensions.patchEntries?.hasSome?.computed;
|
|
23
24
|
class Descriptor {
|
|
24
25
|
/**
|
|
25
26
|
* Creates a new instance of Descriptor either from another object or
|
|
@@ -43,13 +44,39 @@ class Descriptor {
|
|
|
43
44
|
*/
|
|
44
45
|
);
|
|
45
46
|
__classPrivateFieldSet(this, _Descriptor_desc, object, "f");
|
|
46
|
-
if (object && key) {
|
|
47
|
+
if (isObject(object) && isValidKey(key)) {
|
|
47
48
|
__classPrivateFieldSet(this, _Descriptor_desc, Object.getOwnPropertyDescriptor(object, key), "f");
|
|
48
49
|
}
|
|
49
|
-
if (!
|
|
50
|
+
if (!this.isDescriptor) {
|
|
50
51
|
throw new Error(`Not a valid descriptor:`, __classPrivateFieldGet(this, _Descriptor_desc, "f"));
|
|
51
52
|
}
|
|
52
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Detects whether or not this instance is an accessor object descriptor
|
|
56
|
+
*
|
|
57
|
+
* @returns {boolean} true if this object has a getter or setter and is not
|
|
58
|
+
* a data descriptor
|
|
59
|
+
*/
|
|
60
|
+
get isAccessor() {
|
|
61
|
+
return _a.isAccessor(__classPrivateFieldGet(this, _Descriptor_desc, "f"));
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Detects whether or not this instance is an data object descriptor
|
|
65
|
+
*
|
|
66
|
+
* @returns {boolean} true if this object has a value property and is not
|
|
67
|
+
* an accessor descriptor
|
|
68
|
+
*/
|
|
69
|
+
get isData() {
|
|
70
|
+
return _a.isData(__classPrivateFieldGet(this, _Descriptor_desc, "f"));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Detects whether or not this instance is a valid object descriptor
|
|
74
|
+
*
|
|
75
|
+
* @returns {boolean} true if this descriptor store is a valid descriptor
|
|
76
|
+
*/
|
|
77
|
+
get isDescriptor() {
|
|
78
|
+
return _a.isDescriptor(__classPrivateFieldGet(this, _Descriptor_desc, "f"));
|
|
79
|
+
}
|
|
53
80
|
/**
|
|
54
81
|
* Getter around the `configurable` object descriptor property of
|
|
55
82
|
* this instance of Descriptor.
|
|
@@ -58,7 +85,7 @@ class Descriptor {
|
|
|
58
85
|
* descriptor store is invalid.
|
|
59
86
|
*/
|
|
60
87
|
get configurable() {
|
|
61
|
-
return !!__classPrivateFieldGet(this, _Descriptor_desc, "f")?.configurable
|
|
88
|
+
return !!__classPrivateFieldGet(this, _Descriptor_desc, "f")?.configurable;
|
|
62
89
|
}
|
|
63
90
|
/**
|
|
64
91
|
* Sets the `configurable` value of this object. If the internal descriptor
|
|
@@ -169,6 +196,20 @@ class Descriptor {
|
|
|
169
196
|
set set(value) {
|
|
170
197
|
(__classPrivateFieldGet(this, _Descriptor_desc, "f") || {}).set = value;
|
|
171
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Shorthand for Object.getOwnPropertyDescriptor()
|
|
201
|
+
*
|
|
202
|
+
* @param {object} object a non-null object instance
|
|
203
|
+
* @param {string|symbol} key a symbol or string referencing which key on the
|
|
204
|
+
* object to return a descriptor for.
|
|
205
|
+
* @returns an object descriptor for the requested field or null
|
|
206
|
+
*/
|
|
207
|
+
static for(object, key) {
|
|
208
|
+
if (!isObject(object) && !isValidKey(key)) {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
return Object.getOwnPropertyDescriptor(object, key);
|
|
212
|
+
}
|
|
172
213
|
/**
|
|
173
214
|
* Take the descriptor defined by this objects values and apply them to
|
|
174
215
|
* the specified object using the specified key.
|
|
@@ -181,7 +222,7 @@ class Descriptor {
|
|
|
181
222
|
if (!isObject(object) || !isValidKey(forKey)) {
|
|
182
223
|
throw new Error(`Cannot apply descriptor to non-object or invalid key`);
|
|
183
224
|
}
|
|
184
|
-
Object.defineProperty(object, forKey, __classPrivateFieldGet(this, _Descriptor_desc, "f"));
|
|
225
|
+
return Object.defineProperty(object, forKey, __classPrivateFieldGet(this, _Descriptor_desc, "f"));
|
|
185
226
|
}
|
|
186
227
|
/**
|
|
187
228
|
* Converts this descriptor object into a base representation
|
|
@@ -360,9 +401,7 @@ class Descriptor {
|
|
|
360
401
|
..._a.ACCESSOR_KEYS,
|
|
361
402
|
..._a.DATA_KEYS,
|
|
362
403
|
];
|
|
363
|
-
|
|
364
|
-
_a.isData(object)));
|
|
365
|
-
return isa;
|
|
404
|
+
return hasSome(object, knownKeys);
|
|
366
405
|
}
|
|
367
406
|
/**
|
|
368
407
|
* The function checks if a given property or descriptor is a data property.
|
|
@@ -388,7 +427,7 @@ class Descriptor {
|
|
|
388
427
|
else if (hasSome(descriptor, DATA_KEYS)) {
|
|
389
428
|
validData = true;
|
|
390
429
|
}
|
|
391
|
-
return
|
|
430
|
+
return validData;
|
|
392
431
|
}
|
|
393
432
|
/**
|
|
394
433
|
* The function checks if a given property descriptor or property of an object is
|
|
@@ -20,7 +20,7 @@ exports.FunctionExtensions = new extension_1.Patch(Function, {
|
|
|
20
20
|
* @returns {boolean} Returns `true` if the value is a class, otherwise `false`.
|
|
21
21
|
*/
|
|
22
22
|
isClass(value) {
|
|
23
|
-
return value instanceof Function && String(value)
|
|
23
|
+
return value instanceof Function && !!/^class\s/.exec(String(value));
|
|
24
24
|
},
|
|
25
25
|
/**
|
|
26
26
|
* Checks if a given value is a regular function. This method verifies if the value is
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GlobalFunctionsAndProps = void 0;
|
|
4
|
+
const extension_1 = require("@nejs/extension");
|
|
5
|
+
const functionextensions_js_1 = require("./functionextensions.js");
|
|
6
|
+
const { isClass, isFunction } = functionextensions_js_1.FunctionExtensions.patchEntries.isClass.computed;
|
|
7
|
+
const CustomInspect = Symbol.for('nodejs.util.inspect.custom');
|
|
8
|
+
exports.GlobalFunctionsAndProps = new extension_1.Patch(globalThis, {
|
|
9
|
+
asBigIntObject(bigIntPrimitive) {
|
|
10
|
+
const base = { configurable: true, enumerable: false };
|
|
11
|
+
const object = { value: bigIntPrimitive };
|
|
12
|
+
Object.defineProperties(object, {
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
[Symbol.toPrimitive]: { value: function () { return bigIntPrimitive; }, ...base },
|
|
15
|
+
[Symbol.toStringTag]: { value: BigInt.name, ...base },
|
|
16
|
+
[Symbol.species]: { get() { return BigInt; }, ...base },
|
|
17
|
+
[CustomInspect]: { ...base, value(depth, opts, inspect) {
|
|
18
|
+
return inspect(this[Symbol.toPrimitive](), { ...opts, depth });
|
|
19
|
+
} }
|
|
20
|
+
});
|
|
21
|
+
Object.setPrototypeOf(object, BigInt.prototype);
|
|
22
|
+
Reflect.ownKeys(BigInt.prototype).forEach(key => {
|
|
23
|
+
if (typeof object[key] !== 'function') {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
object[key] = (function (...args) {
|
|
27
|
+
return BigInt.prototype[key].apply(this, args);
|
|
28
|
+
}).bind(object.value);
|
|
29
|
+
});
|
|
30
|
+
return object;
|
|
31
|
+
},
|
|
32
|
+
/**
|
|
33
|
+
* Transforms an object to mimic a specified prototype, altering its type conversion
|
|
34
|
+
* and inspection behaviors. This function is especially useful for creating objects
|
|
35
|
+
* that need to behave like different primitive types under various operations.
|
|
36
|
+
*
|
|
37
|
+
* @param {Object} object - The object to be transformed.
|
|
38
|
+
* @param {Function|Object} [prototype=String.prototype] - The prototype or class to
|
|
39
|
+
* emulate. If a function is provided, its prototype is used. Defaults to
|
|
40
|
+
* String.prototype.
|
|
41
|
+
* @param {Function} [toPrimitive=(hint, val) => String(val)] - A function defining how
|
|
42
|
+
* the object should be converted to a primitive value. It receives a type hint
|
|
43
|
+
* ('number', 'string', or 'default') and the object, returning the primitive value.
|
|
44
|
+
* @returns {Object|null} The transformed object, or null if neither a class nor a
|
|
45
|
+
* prototype could be derived from the provided prototype parameter.
|
|
46
|
+
*/
|
|
47
|
+
maskAs(object, classPrototype, options) {
|
|
48
|
+
const { prototype, toPrimitive } = GenericMask({ ...options, prototype: classPrototype });
|
|
49
|
+
const base = { configurable: true, enumerable: false };
|
|
50
|
+
const proto = isFunction(prototype) ? prototype.prototype : prototype;
|
|
51
|
+
const klass = isClass(prototype) ? prototype : proto?.constructor;
|
|
52
|
+
if (!klass && !proto) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
Object.setPrototypeOf(object, proto);
|
|
56
|
+
Object.defineProperties(object, {
|
|
57
|
+
valueOf: { value() { return String(toPrimitive('default', object)); }, ...base },
|
|
58
|
+
[Symbol.toPrimitive]: { value(hint) { return toPrimitive(hint, object); }, ...base },
|
|
59
|
+
[Symbol.toStringTag]: { value: klass.name, ...base },
|
|
60
|
+
[Symbol.species]: { get() { return klass; }, ...base },
|
|
61
|
+
[CustomInspect]: { ...base, value(depth, opts, inspect) {
|
|
62
|
+
return inspect(this[Symbol.toPrimitive](), { ...opts, depth });
|
|
63
|
+
} }
|
|
64
|
+
});
|
|
65
|
+
return object;
|
|
66
|
+
},
|
|
67
|
+
/**
|
|
68
|
+
* Masks an object as a string-like object by setting its prototype to String and
|
|
69
|
+
* defining how it converts to primitive types. This is particularly useful when an
|
|
70
|
+
* object needs to behave like a string in certain contexts, such as type coercion or
|
|
71
|
+
* logging.
|
|
72
|
+
*
|
|
73
|
+
* @param {Object} object - The object to be masked as a string.
|
|
74
|
+
* @param {string} [stringKey='value'] - The object property key used for the string
|
|
75
|
+
* representation. Defaults to 'value'.
|
|
76
|
+
* @param {Function} [toPrimitive] - Optional custom function for primitive conversion.
|
|
77
|
+
* If omitted, a default function handling various conversion hints is used.
|
|
78
|
+
* @returns {Object|null} The string-masked object, or null if the object doesn't have
|
|
79
|
+
* the specified stringKey property.
|
|
80
|
+
*/
|
|
81
|
+
maskAsString(object, stringKey, toPrimitive) {
|
|
82
|
+
if (object && Reflect.has(object, stringKey)) {
|
|
83
|
+
return maskAs(object, StringMask(stringKey ?? 'value', toPrimitive));
|
|
84
|
+
}
|
|
85
|
+
return null;
|
|
86
|
+
},
|
|
87
|
+
/**
|
|
88
|
+
* Masks an object as a number-like object. This allows the object to behave like a
|
|
89
|
+
* number in operations like arithmetic and type coercion. It sets the prototype to
|
|
90
|
+
* Number and defines custom conversion behavior.
|
|
91
|
+
*
|
|
92
|
+
* @param {Object} object - The object to be masked as a number representation.
|
|
93
|
+
* Defaults to 'value'.
|
|
94
|
+
* @param {Function} [toPrimitive] - Optional custom function for primitive
|
|
95
|
+
* conversion. If not provided, a default function handling different conversion
|
|
96
|
+
* hints is used.
|
|
97
|
+
* @returns {Object|null} The number-masked object, or null if the object doesn't
|
|
98
|
+
* have the specified numberKey property.
|
|
99
|
+
*/
|
|
100
|
+
maskAsNumber(object, numberKey, toPrimitive) {
|
|
101
|
+
if (object && Reflect.has(object, numberKey)) {
|
|
102
|
+
return maskAs(object, NumberMask(numberKey ?? 'value', toPrimitive));
|
|
103
|
+
}
|
|
104
|
+
return null;
|
|
105
|
+
},
|
|
106
|
+
/**
|
|
107
|
+
* Generates options for generic masking of an object, providing defaults for
|
|
108
|
+
* prototype and toPrimitive function if not specified.
|
|
109
|
+
*
|
|
110
|
+
* @param {Object} options - The options object including prototype, targetKey,
|
|
111
|
+
* and toPrimitive function.
|
|
112
|
+
* @returns {Object} The options object with defaults applied as necessary.
|
|
113
|
+
*/
|
|
114
|
+
GenericMask({ prototype, targetKey = 'value', toPrimitive }) {
|
|
115
|
+
const options = { targetKey, toPrimitive, prototype };
|
|
116
|
+
if (!isFunction(toPrimitive)) {
|
|
117
|
+
options.toPrimitive = (hint, object) => {
|
|
118
|
+
let property = object[targetKey];
|
|
119
|
+
let isNum = (typeof property === 'number' && Number.isFinite(property)) ||
|
|
120
|
+
(typeof property === 'string' &&
|
|
121
|
+
!isNaN(parseFloat(property)) && isFinite(property));
|
|
122
|
+
switch (hint) {
|
|
123
|
+
case 'string': return isNum ? String(property) : (property ?? String(object));
|
|
124
|
+
case 'number': return isNum ? Number(property) : NaN;
|
|
125
|
+
case 'default':
|
|
126
|
+
default:
|
|
127
|
+
return isNum ? Number(property) : property;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return options;
|
|
132
|
+
},
|
|
133
|
+
/**
|
|
134
|
+
* Generates options for string masking of an object, providing a default toPrimitive
|
|
135
|
+
* function if not specified.
|
|
136
|
+
*
|
|
137
|
+
* @param {string} targetKey - The object property key for string representation.
|
|
138
|
+
* @param {Function} toPrimitive - Custom function for primitive conversion.
|
|
139
|
+
* @returns {Object} Options for string masking.
|
|
140
|
+
*/
|
|
141
|
+
StringMask(targetKey, toPrimitive) {
|
|
142
|
+
const options = { targetKey, toPrimitive, prototype: String.prototype };
|
|
143
|
+
if (!isFunction(toPrimitive)) {
|
|
144
|
+
options.toPrimitive = function toPrimitive(hint, object) {
|
|
145
|
+
switch (hint) {
|
|
146
|
+
case 'default': return object[targetKey];
|
|
147
|
+
case 'number': return parseInt(object[targetKey], 36);
|
|
148
|
+
case 'string': return String(object[targetKey]);
|
|
149
|
+
default: return object;
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
return options;
|
|
154
|
+
},
|
|
155
|
+
/**
|
|
156
|
+
* Generates options for number masking of an object, providing a default toPrimitive
|
|
157
|
+
* function if not specified.
|
|
158
|
+
*
|
|
159
|
+
* @param {string} targetKey - The object property key for number representation.
|
|
160
|
+
* @param {Function} toPrimitive - Custom function for primitive conversion.
|
|
161
|
+
* @returns {Object} Options for number masking.
|
|
162
|
+
*/
|
|
163
|
+
NumberMask(targetKey, toPrimitive) {
|
|
164
|
+
const options = { targetKey, toPrimitive, prototype: Number.prototype };
|
|
165
|
+
if (!isFunction(toPrimitive)) {
|
|
166
|
+
options.toPrimitive = function toPrimitive(hint, object) {
|
|
167
|
+
switch (hint) {
|
|
168
|
+
case 'default': return object[targetKey];
|
|
169
|
+
case 'number': return Number(object[targetKey]);
|
|
170
|
+
case 'string': return String(object[targetKey]);
|
|
171
|
+
default: return object;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
return options;
|
|
176
|
+
},
|
|
177
|
+
});
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
export function enableAll(owners: any): void;
|
|
2
2
|
export function disableAll(owners: any): void;
|
|
3
|
+
export const all: {};
|
|
3
4
|
import { ObjectExtensions } from './objectextensions.js';
|
|
4
5
|
import { FunctionExtensions } from './functionextensions.js';
|
|
5
6
|
import { ReflectExtensions } from './reflectextensions.js';
|
|
6
7
|
import { StringExtensions } from './stringextensions.js';
|
|
7
8
|
import { SymbolExtensions } from './symbolextensions.js';
|
|
8
9
|
import { ArrayPrototypeExtensions } from './arrayextensions.js';
|
|
9
|
-
|
|
10
|
+
import { GlobalFunctionsAndProps } from './globals.js';
|
|
11
|
+
import { DescriptorExtension } from './descriptor.js';
|
|
12
|
+
export { ObjectExtensions, FunctionExtensions, ReflectExtensions, StringExtensions, SymbolExtensions, ArrayPrototypeExtensions, GlobalFunctionsAndProps, DescriptorExtension };
|