New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@nejs/basic-extensions

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nejs/basic-extensions - npm Package Compare versions

Comparing version 1.10.0 to 2.0.0

dist/@nejs/basic-extensions.bundle.1.10.0.js

16

dist/cjs/index.d.ts

@@ -1,2 +0,6 @@

export const all: any;
export namespace all {
let patches: {};
let classes: {};
let global: {};
}
export default results;

@@ -6,2 +10,3 @@ declare namespace results {

export { Patches };
export { GlobalFunctionsAndProps };
export { StaticPatches };

@@ -14,9 +19,8 @@ export { InstancePatches };

}
export namespace Extensions {
export { GlobalFunctionsAndProps as global };
}
export const Extensions: {};
export const Patches: Map<any, any>;
export const StaticPatches: ((import("@nejs/extension").Patch | ObjectConstructor)[] | (import("@nejs/extension").Patch | FunctionConstructor)[] | (import("@nejs/extension").Patch | typeof Reflect)[] | (import("@nejs/extension").Patch | StringConstructor)[] | (import("@nejs/extension").Patch | SymbolConstructor)[])[];
export const InstancePatches: Object[][];
export const StaticPatches: ((string | import("@nejs/extension").Patch | ObjectConstructor)[] | (string | import("@nejs/extension").Patch | FunctionConstructor)[] | (string | import("@nejs/extension").Patch | typeof Reflect)[] | (string | import("@nejs/extension").Patch | StringConstructor)[] | (string | import("@nejs/extension").Patch | SymbolConstructor)[])[];
export const InstancePatches: (string | Object)[][];
export const Controls: {};
import { GlobalFunctionsAndProps } from './globals.js';
export { GlobalFunctionsAndProps };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Controls = exports.InstancePatches = exports.StaticPatches = exports.Patches = exports.Extensions = exports.all = void 0;
exports.GlobalFunctionsAndProps = exports.Controls = exports.InstancePatches = exports.StaticPatches = exports.Patches = exports.Extensions = exports.all = void 0;
const functionextensions_js_1 = require("./functionextensions.js");

@@ -14,2 +14,3 @@ const objectextensions_js_1 = require("./objectextensions.js");

const globals_js_1 = require("./globals.js");
Object.defineProperty(exports, "GlobalFunctionsAndProps", { enumerable: true, get: function () { return globals_js_1.GlobalFunctionsAndProps; } });
const refset_js_1 = require("./newClasses/refset.js");

@@ -21,15 +22,15 @@ const refmap_js_1 = require("./newClasses/refmap.js");

const StaticPatches = [
[Object, objectextensions_js_1.ObjectExtensions],
[Function, functionextensions_js_1.FunctionExtensions],
[Reflect, reflectextensions_js_1.ReflectExtensions],
[String, stringextensions_js_1.StringExtensions],
[Symbol, symbolextensions_js_1.SymbolExtensions],
[Object, objectextensions_js_1.ObjectExtensions, Object.name],
[Function, functionextensions_js_1.FunctionExtensions, Function.name],
[Reflect, reflectextensions_js_1.ReflectExtensions, 'Reflect'], // Missing a .name property
[String, stringextensions_js_1.StringExtensions, String.name],
[Symbol, symbolextensions_js_1.SymbolExtensions, 'Symbol'], // Missing a .name property
];
exports.StaticPatches = StaticPatches;
const InstancePatches = [
[Object.prototype, objectextensions_js_1.ObjectPrototypeExtensions],
[Function.prototype, functionextensions_js_1.FunctionPrototypeExtensions],
[Array.prototype, arrayextensions_js_1.ArrayPrototypeExtensions],
[Map.prototype, mapextensions_js_1.MapPrototypeExtensions],
[Set.prototype, setextensions_js_1.SetPrototypeExtensions],
[Object.prototype, objectextensions_js_1.ObjectPrototypeExtensions, Object.name],
[Function.prototype, functionextensions_js_1.FunctionPrototypeExtensions, Function.name],
[Array.prototype, arrayextensions_js_1.ArrayPrototypeExtensions, Array.name],
[Map.prototype, mapextensions_js_1.MapPrototypeExtensions, Map.name],
[Set.prototype, setextensions_js_1.SetPrototypeExtensions, Set.name],
];

@@ -43,3 +44,2 @@ exports.InstancePatches = InstancePatches;

const Extensions = {
global: globals_js_1.GlobalFunctionsAndProps,
[asyncIterable_js_1.AsyncIterableExtensions.key]: asyncIterable_js_1.AsyncIterableExtensions,

@@ -77,2 +77,3 @@ [asyncIterable_js_1.AsyncIteratorExtensions.key]: asyncIterable_js_1.AsyncIteratorExtensions,

Object.values(Extensions).forEach((extension) => { extension.apply(); });
globals_js_1.GlobalFunctionsAndProps.apply();
},

@@ -98,20 +99,40 @@ disableAll() {

Object.values(Extensions).forEach((extension) => { extension.revert(); });
globals_js_1.GlobalFunctionsAndProps.revert();
},
});
exports.all = (() => {
const extensions = [
...Array.from(Patches.values()),
...Array.from(Object.values(Extensions)),
];
const dest = extensions.reduce((accumulator, extension) => {
Reflect.ownKeys(extension.patchEntries).reduce((_, key) => {
const entry = extension.patchEntries[key];
if (entry.isAccessor)
accumulator[key] = new descriptor_js_1.Descriptor(entry.descriptor);
else
accumulator[key] = entry.computed;
return accumulator;
}, accumulator);
const dest = {
patches: {},
classes: {},
global: {},
};
const entriesReducer = (accumulator, [key, entry]) => {
const descriptor = new descriptor_js_1.Descriptor(entry.descriptor, entry.owner);
descriptor.applyTo(accumulator, key, true);
return accumulator;
}, {});
};
const staticPatchReducer = (accumulator, [_, patch, ownerName]) => {
if (!accumulator?.[ownerName]) {
accumulator[ownerName] = {};
}
[...patch].reduce(entriesReducer, accumulator[ownerName]);
return accumulator;
};
const instancePatchReducer = (accumulator, [_, patch, ownerName]) => {
if (!accumulator?.[ownerName])
accumulator[ownerName] = {};
if (!accumulator[ownerName]?.prototype)
accumulator[ownerName].prototype = {};
[...patch].reduce(entriesReducer, accumulator[ownerName].prototype);
return accumulator;
};
StaticPatches.reduce(staticPatchReducer, dest.patches);
InstancePatches.reduce(instancePatchReducer, dest.patches);
(Object.entries(Extensions)
.map(([k, v]) => [k, v, k])
.reduce(staticPatchReducer, dest.classes));
for (const [key, entry] of globals_js_1.GlobalFunctionsAndProps) {
const descriptor = new descriptor_js_1.Descriptor(entry.descriptor, entry.owner);
Object.defineProperty(dest.global, key, descriptor.toObject(true));
}
return dest;

@@ -123,2 +144,3 @@ })();

Patches,
GlobalFunctionsAndProps: globals_js_1.GlobalFunctionsAndProps,
StaticPatches,

@@ -125,0 +147,0 @@ InstancePatches,

@@ -27,15 +27,17 @@ /**

* Constructs an instance of AsyncIterable. Similar to Iterable, it can be
* initialized with either an iterable object or individual elements. The
* elements can be promises, direct values, or a mix of both. If the first
* argument is an iterable, the instance is initialized with the elements
* from the iterable, followed by any additional arguments. If the first
* argument is not an iterable, all arguments are treated as individual
* elements.
* initialized with either an iterable object, an async generator function,
* or individual elements. The elements can be promises, direct values, or a
* mix of both. If the first argument is an iterable or an async generator
* function, the instance is initialized with the elements from the iterable
* or the generated elements from the async generator function, followed by
* any additional arguments. If the first argument is not an iterable or an
* async generator function, all arguments are treated as individual elements.
*
* @param {Iterable|Promise|*} elementsOrFirstElement - An iterable object,
* a Promise, or the first element.
* @param {Iterable|AsyncGeneratorFunction|Promise|*} elementsOrFirstElement -
* An iterable object, an async generator function, a Promise, or the first
* element.
* @param {...Promise|*} moreElements - Additional elements if the first
* argument is not an iterable.
* argument is not an iterable or an async generator function.
*/
constructor(elementsOrFirstElement: Iterable<any> | Promise<any> | any, ...moreElements: (Promise<any> | any)[]);
constructor(elementsOrFirstElement: Iterable<any> | AsyncGeneratorFunction | Promise<any> | any, ...moreElements: (Promise<any> | any)[]);
/**

@@ -71,6 +73,7 @@ * Implements the async iterable protocol. When an instance of AsyncIterable

*
* @param {object} asyncIterable any object that has a
* `[Symbol.asyncIterable]` property assigned to a generator function.
* @param {object|AsyncGeneratorFunction} asyncIterable any object that has a
* `[Symbol.asyncIterable]` property assigned to a generator function or an
* async generator function itself.
*/
constructor(asyncIterable: object);
constructor(asyncIterable: object | AsyncGeneratorFunction);
/**

@@ -77,0 +80,0 @@ * Returns a new `Array` derived from the iterable this object

@@ -28,13 +28,15 @@ "use strict";

* Constructs an instance of AsyncIterable. Similar to Iterable, it can be
* initialized with either an iterable object or individual elements. The
* elements can be promises, direct values, or a mix of both. If the first
* argument is an iterable, the instance is initialized with the elements
* from the iterable, followed by any additional arguments. If the first
* argument is not an iterable, all arguments are treated as individual
* elements.
* initialized with either an iterable object, an async generator function,
* or individual elements. The elements can be promises, direct values, or a
* mix of both. If the first argument is an iterable or an async generator
* function, the instance is initialized with the elements from the iterable
* or the generated elements from the async generator function, followed by
* any additional arguments. If the first argument is not an iterable or an
* async generator function, all arguments are treated as individual elements.
*
* @param {Iterable|Promise|*} elementsOrFirstElement - An iterable object,
* a Promise, or the first element.
* @param {Iterable|AsyncGeneratorFunction|Promise|*} elementsOrFirstElement -
* An iterable object, an async generator function, a Promise, or the first
* element.
* @param {...Promise|*} moreElements - Additional elements if the first
* argument is not an iterable.
* argument is not an iterable or an async generator function.
*/

@@ -48,5 +50,10 @@ constructor(elementsOrFirstElement, ...moreElements) {

if (elementsOrFirstElement != null &&
typeof elementsOrFirstElement[Symbol.iterator] === 'function') {
(typeof elementsOrFirstElement[Symbol.iterator] === 'function' ||
typeof elementsOrFirstElement[Symbol.asyncIterator] === 'function')) {
__classPrivateFieldSet(this, _AsyncIterable_elements, [...elementsOrFirstElement, ...moreElements], "f");
}
else if (typeof elementsOrFirstElement === 'function' &&
elementsOrFirstElement.constructor.name === 'AsyncGeneratorFunction') {
__classPrivateFieldSet(this, _AsyncIterable_elements, elementsOrFirstElement(), "f");
}
else {

@@ -67,6 +74,6 @@ __classPrivateFieldSet(this, _AsyncIterable_elements, [elementsOrFirstElement, ...moreElements], "f");

async *[(_AsyncIterable_elements = new WeakMap(), Symbol.asyncIterator)]() {
for (const element of __classPrivateFieldGet(this, _AsyncIterable_elements, "f")) {
// Treat each element as a promise. If it's not, it's automatically
// wrapped as a resolved promise.
yield Promise.resolve(element);
for await (const element of __classPrivateFieldGet(this, _AsyncIterable_elements, "f")) {
// No need to wrap as a promise here since `for await...of` can handle
// both Promises and non-Promise values.
yield element;
}

@@ -113,4 +120,5 @@ }

*
* @param {object} asyncIterable any object that has a
* `[Symbol.asyncIterable]` property assigned to a generator function.
* @param {object|AsyncGeneratorFunction} asyncIterable any object that has a
* `[Symbol.asyncIterable]` property assigned to a generator function or an
* async generator function itself.
*/

@@ -133,7 +141,14 @@ constructor(asyncIterable) {

_AsyncIterator_asyncIterator.set(this, null);
if (!asyncIterable || !Reflect.has(asyncIterable, Symbol.asyncIterator)) {
if (typeof asyncIterable === 'function' &&
asyncIterable.constructor.name === 'AsyncGeneratorFunction') {
__classPrivateFieldSet(this, _AsyncIterator_asyncIterable, asyncIterable(), "f");
}
else if (!asyncIterable ||
!Reflect.has(asyncIterable, Symbol.asyncIterator)) {
throw new TypeError('Value used to instantiate AsyncIterator is not an async iterable');
}
__classPrivateFieldSet(this, _AsyncIterator_asyncIterable, asyncIterable, "f");
__classPrivateFieldSet(this, _AsyncIterator_asyncIterator, asyncIterable[Symbol.asyncIterator](), "f");
else {
__classPrivateFieldSet(this, _AsyncIterator_asyncIterable, asyncIterable, "f");
}
__classPrivateFieldSet(this, _AsyncIterator_asyncIterator, __classPrivateFieldGet(this, _AsyncIterator_asyncIterable, "f")[Symbol.asyncIterator](), "f");
}

@@ -140,0 +155,0 @@ /**

@@ -207,11 +207,18 @@ export class Descriptor {

/**
* Creates a new instance of Descriptor either from another object or
* around the supplied object descriptor value.
* Constructs a Descriptor instance which wraps and manages an object
* property descriptor. The constructor can handle an existing descriptor
* object or create a new one based on an object and a property key.
*
* @param {object} object either an object descriptor or the object
* from which to get the descriptor
* @param {symbol|string} key a valid key for accessing the descriptor
* on the aforesupplied object.
* @param {object|Descriptor} object - The target object or an existing
* Descriptor instance. If it's an object, it is used in conjunction with
* `key` to create a descriptor. If it's a Descriptor instance, it is used
* directly as the descriptor.
* @param {string|symbol} [key] - The property key for which the descriptor
* is to be created. This parameter is ignored if `object` is a Descriptor
* instance. If `key` is an object and `object` is a valid descriptor, `key`
* is treated as the associated object.
* @throws {Error} Throws an error if the constructed descriptor is not
* valid.
*/
constructor(object: object, key: symbol | string);
constructor(object: object | Descriptor, key?: string | symbol | undefined);
/**

@@ -383,4 +390,18 @@ * Detects whether or not this instance is an accessor object descriptor

*/
applyTo(object: object, forKey: string | symbol): object;
applyTo(object: object, forKey: string | symbol, bindAccessors?: boolean): object;
/**
* Converts this Descriptor class instance into a basic object descriptor
* that is accepted by all the standard JavaScript runtime methods that
* deal with object descriptors.
*
* @param {boolean|object} bindAccessors if `true`, a non-fatal attempt to
* bind accessor getter and setter methods is made before returning the
* object. If `bindAccessors` is truthy and is also an object, this is the
* object the accessors will be bound to. If the value is falsy or if the
* descriptor instance represents a data descriptor, nothing happens.
* @returns {object} the object instance's basic object representation as
* a descriptor.
*/
toObject(bindAccessors?: boolean | object): object;
/**
* Converts this descriptor object into a base representation

@@ -387,0 +408,0 @@ *

@@ -23,9 +23,16 @@ "use strict";

/**
* Creates a new instance of Descriptor either from another object or
* around the supplied object descriptor value.
* Constructs a Descriptor instance which wraps and manages an object
* property descriptor. The constructor can handle an existing descriptor
* object or create a new one based on an object and a property key.
*
* @param {object} object either an object descriptor or the object
* from which to get the descriptor
* @param {symbol|string} key a valid key for accessing the descriptor
* on the aforesupplied object.
* @param {object|Descriptor} object - The target object or an existing
* Descriptor instance. If it's an object, it is used in conjunction with
* `key` to create a descriptor. If it's a Descriptor instance, it is used
* directly as the descriptor.
* @param {string|symbol} [key] - The property key for which the descriptor
* is to be created. This parameter is ignored if `object` is a Descriptor
* instance. If `key` is an object and `object` is a valid descriptor, `key`
* is treated as the associated object.
* @throws {Error} Throws an error if the constructed descriptor is not
* valid.
*/

@@ -57,9 +64,16 @@ constructor(object, key) {

/**
* Creates a new instance of Descriptor either from another object or
* around the supplied object descriptor value.
* Constructs a Descriptor instance which wraps and manages an object
* property descriptor. The constructor can handle an existing descriptor
* object or create a new one based on an object and a property key.
*
* @param {object} object either an object descriptor or the object
* from which to get the descriptor
* @param {symbol|string} key a valid key for accessing the descriptor
* on the aforesupplied object.
* @param {object|Descriptor} object - The target object or an existing
* Descriptor instance. If it's an object, it is used in conjunction with
* `key` to create a descriptor. If it's a Descriptor instance, it is used
* directly as the descriptor.
* @param {string|symbol} [key] - The property key for which the descriptor
* is to be created. This parameter is ignored if `object` is a Descriptor
* instance. If `key` is an object and `object` is a valid descriptor, `key`
* is treated as the associated object.
* @throws {Error} Throws an error if the constructed descriptor is not
* valid.
*/

@@ -70,5 +84,5 @@ );

}
if (Descriptor.isDescriptor(object)) {
else if (Descriptor.isDescriptor(object)) {
__classPrivateFieldSet(this, _Descriptor_desc, object, "f");
__classPrivateFieldSet(this, _Descriptor_object, undefined, "f");
__classPrivateFieldSet(this, _Descriptor_object, isObject(key) ? key : undefined, "f");
}

@@ -80,3 +94,7 @@ else if (isObject(object) && isValidKey(key)) {

if (!this.isDescriptor) {
console.error('Current descriptor:', __classPrivateFieldGet(this, _Descriptor_desc, "f"));
console.error(`
Descriptor(object,key) FAILED:
object: ${object === globalThis ? '[GLOBAL]' : (typeof key === 'object' ? JSON.stringify(object) : String(object))}
key: ${key === globalThis ? '[GLOBAL]' : (typeof key === 'object' ? JSON.stringify(key) : String(key))}
descriptor: `, __classPrivateFieldGet(this, _Descriptor_desc, "f"));
throw new Error(`Not a valid descriptor:`, __classPrivateFieldGet(this, _Descriptor_desc, "f"));

@@ -323,9 +341,42 @@ }

*/
applyTo(object, forKey) {
applyTo(object, forKey, bindAccessors = false) {
if (!isObject(object) || !isValidKey(forKey)) {
throw new Error(`Cannot apply descriptor to non-object or invalid key`);
}
return Object.defineProperty(object, forKey, __classPrivateFieldGet(this, _Descriptor_desc, "f"));
return Object.defineProperty(object, forKey, this.toObject(bindAccessors));
}
/**
* Converts this Descriptor class instance into a basic object descriptor
* that is accepted by all the standard JavaScript runtime methods that
* deal with object descriptors.
*
* @param {boolean|object} bindAccessors if `true`, a non-fatal attempt to
* bind accessor getter and setter methods is made before returning the
* object. If `bindAccessors` is truthy and is also an object, this is the
* object the accessors will be bound to. If the value is falsy or if the
* descriptor instance represents a data descriptor, nothing happens.
* @returns {object} the object instance's basic object representation as
* a descriptor.
*/
toObject(bindAccessors = false) {
let descriptor = { ...__classPrivateFieldGet(this, _Descriptor_desc, "f") };
if (bindAccessors && this.isAccessor) {
if (this.hasObject) {
descriptor = {
...descriptor,
get: this.boundGet,
set: this.boundSet
};
}
else if (isObject(bindAccessors)) {
descriptor = {
...descriptor,
get: this.get?.bind(bindAccessors),
set: this.set?.bind(bindAccessors)
};
}
}
return descriptor;
}
/**
* Converts this descriptor object into a base representation

@@ -356,3 +407,3 @@ *

default:
return __classPrivateFieldGet(this, _Descriptor_desc, "f");
return this.toObject();
}

@@ -359,0 +410,0 @@ }

@@ -1,2 +0,6 @@

export const all: any;
export namespace all {
let patches: {};
let classes: {};
let global: {};
}
export default results;

@@ -6,2 +10,3 @@ declare namespace results {

export { Patches };
export { GlobalFunctionsAndProps };
export { StaticPatches };

@@ -14,9 +19,8 @@ export { InstancePatches };

}
export namespace Extensions {
export { GlobalFunctionsAndProps as global };
}
export const Extensions: {};
export const Patches: Map<any, any>;
export const StaticPatches: ((import("@nejs/extension").Patch | ObjectConstructor)[] | (import("@nejs/extension").Patch | FunctionConstructor)[] | (import("@nejs/extension").Patch | typeof Reflect)[] | (import("@nejs/extension").Patch | StringConstructor)[] | (import("@nejs/extension").Patch | SymbolConstructor)[])[];
export const InstancePatches: Object[][];
export const StaticPatches: ((string | import("@nejs/extension").Patch | ObjectConstructor)[] | (string | import("@nejs/extension").Patch | FunctionConstructor)[] | (string | import("@nejs/extension").Patch | typeof Reflect)[] | (string | import("@nejs/extension").Patch | StringConstructor)[] | (string | import("@nejs/extension").Patch | SymbolConstructor)[])[];
export const InstancePatches: (string | Object)[][];
export const Controls: {};
import { GlobalFunctionsAndProps } from './globals.js';
export { GlobalFunctionsAndProps };

@@ -17,14 +17,14 @@ import { FunctionExtensions, FunctionPrototypeExtensions } from './functionextensions.js';

const StaticPatches = [
[Object, ObjectExtensions],
[Function, FunctionExtensions],
[Reflect, ReflectExtensions],
[String, StringExtensions],
[Symbol, SymbolExtensions],
[Object, ObjectExtensions, Object.name],
[Function, FunctionExtensions, Function.name],
[Reflect, ReflectExtensions, 'Reflect'], // Missing a .name property
[String, StringExtensions, String.name],
[Symbol, SymbolExtensions, 'Symbol'], // Missing a .name property
];
const InstancePatches = [
[Object.prototype, ObjectPrototypeExtensions],
[Function.prototype, FunctionPrototypeExtensions],
[Array.prototype, ArrayPrototypeExtensions],
[Map.prototype, MapPrototypeExtensions],
[Set.prototype, SetPrototypeExtensions],
[Object.prototype, ObjectPrototypeExtensions, Object.name],
[Function.prototype, FunctionPrototypeExtensions, Function.name],
[Array.prototype, ArrayPrototypeExtensions, Array.name],
[Map.prototype, MapPrototypeExtensions, Map.name],
[Set.prototype, SetPrototypeExtensions, Set.name],
];

@@ -36,3 +36,2 @@ const Patches = new Map([

const Extensions = {
global: GlobalFunctionsAndProps,
[AsyncIterableExtensions.key]: AsyncIterableExtensions,

@@ -68,2 +67,3 @@ [AsyncIteratorExtensions.key]: AsyncIteratorExtensions,

Object.values(Extensions).forEach((extension) => { extension.apply(); });
GlobalFunctionsAndProps.apply();
},

@@ -89,20 +89,40 @@ disableAll() {

Object.values(Extensions).forEach((extension) => { extension.revert(); });
GlobalFunctionsAndProps.revert();
},
});
export const all = (() => {
const extensions = [
...Array.from(Patches.values()),
...Array.from(Object.values(Extensions)),
];
const dest = extensions.reduce((accumulator, extension) => {
Reflect.ownKeys(extension.patchEntries).reduce((_, key) => {
const entry = extension.patchEntries[key];
if (entry.isAccessor)
accumulator[key] = new Descriptor(entry.descriptor);
else
accumulator[key] = entry.computed;
return accumulator;
}, accumulator);
const dest = {
patches: {},
classes: {},
global: {},
};
const entriesReducer = (accumulator, [key, entry]) => {
const descriptor = new Descriptor(entry.descriptor, entry.owner);
descriptor.applyTo(accumulator, key, true);
return accumulator;
}, {});
};
const staticPatchReducer = (accumulator, [_, patch, ownerName]) => {
if (!accumulator?.[ownerName]) {
accumulator[ownerName] = {};
}
[...patch].reduce(entriesReducer, accumulator[ownerName]);
return accumulator;
};
const instancePatchReducer = (accumulator, [_, patch, ownerName]) => {
if (!accumulator?.[ownerName])
accumulator[ownerName] = {};
if (!accumulator[ownerName]?.prototype)
accumulator[ownerName].prototype = {};
[...patch].reduce(entriesReducer, accumulator[ownerName].prototype);
return accumulator;
};
StaticPatches.reduce(staticPatchReducer, dest.patches);
InstancePatches.reduce(instancePatchReducer, dest.patches);
(Object.entries(Extensions)
.map(([k, v]) => [k, v, k])
.reduce(staticPatchReducer, dest.classes));
for (const [key, entry] of GlobalFunctionsAndProps) {
const descriptor = new Descriptor(entry.descriptor, entry.owner);
Object.defineProperty(dest.global, key, descriptor.toObject(true));
}
return dest;

@@ -114,2 +134,3 @@ })();

Patches,
GlobalFunctionsAndProps,
StaticPatches,

@@ -123,3 +144,3 @@ InstancePatches,

export default results;
export { Extensions, Patches, StaticPatches, InstancePatches, Controls, };
export { Extensions, Patches, StaticPatches, InstancePatches, Controls, GlobalFunctionsAndProps, };
function toFilterFn(filter = ([owner, extension]) => true) {

@@ -126,0 +147,0 @@ let filterFn = filter;

@@ -27,15 +27,17 @@ /**

* Constructs an instance of AsyncIterable. Similar to Iterable, it can be
* initialized with either an iterable object or individual elements. The
* elements can be promises, direct values, or a mix of both. If the first
* argument is an iterable, the instance is initialized with the elements
* from the iterable, followed by any additional arguments. If the first
* argument is not an iterable, all arguments are treated as individual
* elements.
* initialized with either an iterable object, an async generator function,
* or individual elements. The elements can be promises, direct values, or a
* mix of both. If the first argument is an iterable or an async generator
* function, the instance is initialized with the elements from the iterable
* or the generated elements from the async generator function, followed by
* any additional arguments. If the first argument is not an iterable or an
* async generator function, all arguments are treated as individual elements.
*
* @param {Iterable|Promise|*} elementsOrFirstElement - An iterable object,
* a Promise, or the first element.
* @param {Iterable|AsyncGeneratorFunction|Promise|*} elementsOrFirstElement -
* An iterable object, an async generator function, a Promise, or the first
* element.
* @param {...Promise|*} moreElements - Additional elements if the first
* argument is not an iterable.
* argument is not an iterable or an async generator function.
*/
constructor(elementsOrFirstElement: Iterable<any> | Promise<any> | any, ...moreElements: (Promise<any> | any)[]);
constructor(elementsOrFirstElement: Iterable<any> | AsyncGeneratorFunction | Promise<any> | any, ...moreElements: (Promise<any> | any)[]);
/**

@@ -71,6 +73,7 @@ * Implements the async iterable protocol. When an instance of AsyncIterable

*
* @param {object} asyncIterable any object that has a
* `[Symbol.asyncIterable]` property assigned to a generator function.
* @param {object|AsyncGeneratorFunction} asyncIterable any object that has a
* `[Symbol.asyncIterable]` property assigned to a generator function or an
* async generator function itself.
*/
constructor(asyncIterable: object);
constructor(asyncIterable: object | AsyncGeneratorFunction);
/**

@@ -77,0 +80,0 @@ * Returns a new `Array` derived from the iterable this object

@@ -18,19 +18,26 @@ import { Extension } from '@nejs/extension';

* Constructs an instance of AsyncIterable. Similar to Iterable, it can be
* initialized with either an iterable object or individual elements. The
* elements can be promises, direct values, or a mix of both. If the first
* argument is an iterable, the instance is initialized with the elements
* from the iterable, followed by any additional arguments. If the first
* argument is not an iterable, all arguments are treated as individual
* elements.
* initialized with either an iterable object, an async generator function,
* or individual elements. The elements can be promises, direct values, or a
* mix of both. If the first argument is an iterable or an async generator
* function, the instance is initialized with the elements from the iterable
* or the generated elements from the async generator function, followed by
* any additional arguments. If the first argument is not an iterable or an
* async generator function, all arguments are treated as individual elements.
*
* @param {Iterable|Promise|*} elementsOrFirstElement - An iterable object,
* a Promise, or the first element.
* @param {Iterable|AsyncGeneratorFunction|Promise|*} elementsOrFirstElement -
* An iterable object, an async generator function, a Promise, or the first
* element.
* @param {...Promise|*} moreElements - Additional elements if the first
* argument is not an iterable.
* argument is not an iterable or an async generator function.
*/
constructor(elementsOrFirstElement, ...moreElements) {
if (elementsOrFirstElement != null &&
typeof elementsOrFirstElement[Symbol.iterator] === 'function') {
(typeof elementsOrFirstElement[Symbol.iterator] === 'function' ||
typeof elementsOrFirstElement[Symbol.asyncIterator] === 'function')) {
this.#elements = [...elementsOrFirstElement, ...moreElements];
}
else if (typeof elementsOrFirstElement === 'function' &&
elementsOrFirstElement.constructor.name === 'AsyncGeneratorFunction') {
this.#elements = elementsOrFirstElement();
}
else {

@@ -51,6 +58,6 @@ this.#elements = [elementsOrFirstElement, ...moreElements];

async *[Symbol.asyncIterator]() {
for (const element of this.#elements) {
// Treat each element as a promise. If it's not, it's automatically
// wrapped as a resolved promise.
yield Promise.resolve(element);
for await (const element of this.#elements) {
// No need to wrap as a promise here since `for await...of` can handle
// both Promises and non-Promise values.
yield element;
}

@@ -96,11 +103,19 @@ }

*
* @param {object} asyncIterable any object that has a
* `[Symbol.asyncIterable]` property assigned to a generator function.
* @param {object|AsyncGeneratorFunction} asyncIterable any object that has a
* `[Symbol.asyncIterable]` property assigned to a generator function or an
* async generator function itself.
*/
constructor(asyncIterable) {
if (!asyncIterable || !Reflect.has(asyncIterable, Symbol.asyncIterator)) {
if (typeof asyncIterable === 'function' &&
asyncIterable.constructor.name === 'AsyncGeneratorFunction') {
this.#asyncIterable = asyncIterable();
}
else if (!asyncIterable ||
!Reflect.has(asyncIterable, Symbol.asyncIterator)) {
throw new TypeError('Value used to instantiate AsyncIterator is not an async iterable');
}
this.#asyncIterable = asyncIterable;
this.#asyncIterator = asyncIterable[Symbol.asyncIterator]();
else {
this.#asyncIterable = asyncIterable;
}
this.#asyncIterator = this.#asyncIterable[Symbol.asyncIterator]();
}

@@ -107,0 +122,0 @@ /**

@@ -207,11 +207,18 @@ export class Descriptor {

/**
* Creates a new instance of Descriptor either from another object or
* around the supplied object descriptor value.
* Constructs a Descriptor instance which wraps and manages an object
* property descriptor. The constructor can handle an existing descriptor
* object or create a new one based on an object and a property key.
*
* @param {object} object either an object descriptor or the object
* from which to get the descriptor
* @param {symbol|string} key a valid key for accessing the descriptor
* on the aforesupplied object.
* @param {object|Descriptor} object - The target object or an existing
* Descriptor instance. If it's an object, it is used in conjunction with
* `key` to create a descriptor. If it's a Descriptor instance, it is used
* directly as the descriptor.
* @param {string|symbol} [key] - The property key for which the descriptor
* is to be created. This parameter is ignored if `object` is a Descriptor
* instance. If `key` is an object and `object` is a valid descriptor, `key`
* is treated as the associated object.
* @throws {Error} Throws an error if the constructed descriptor is not
* valid.
*/
constructor(object: object, key: symbol | string);
constructor(object: object | Descriptor, key?: string | symbol | undefined);
/**

@@ -383,4 +390,18 @@ * Detects whether or not this instance is an accessor object descriptor

*/
applyTo(object: object, forKey: string | symbol): object;
applyTo(object: object, forKey: string | symbol, bindAccessors?: boolean): object;
/**
* Converts this Descriptor class instance into a basic object descriptor
* that is accepted by all the standard JavaScript runtime methods that
* deal with object descriptors.
*
* @param {boolean|object} bindAccessors if `true`, a non-fatal attempt to
* bind accessor getter and setter methods is made before returning the
* object. If `bindAccessors` is truthy and is also an object, this is the
* object the accessors will be bound to. If the value is falsy or if the
* descriptor instance represents a data descriptor, nothing happens.
* @returns {object} the object instance's basic object representation as
* a descriptor.
*/
toObject(bindAccessors?: boolean | object): object;
/**
* Converts this descriptor object into a base representation

@@ -387,0 +408,0 @@ *

@@ -23,9 +23,16 @@ import { Extension } from '@nejs/extension';

/**
* Creates a new instance of Descriptor either from another object or
* around the supplied object descriptor value.
* Constructs a Descriptor instance which wraps and manages an object
* property descriptor. The constructor can handle an existing descriptor
* object or create a new one based on an object and a property key.
*
* @param {object} object either an object descriptor or the object
* from which to get the descriptor
* @param {symbol|string} key a valid key for accessing the descriptor
* on the aforesupplied object.
* @param {object|Descriptor} object - The target object or an existing
* Descriptor instance. If it's an object, it is used in conjunction with
* `key` to create a descriptor. If it's a Descriptor instance, it is used
* directly as the descriptor.
* @param {string|symbol} [key] - The property key for which the descriptor
* is to be created. This parameter is ignored if `object` is a Descriptor
* instance. If `key` is an object and `object` is a valid descriptor, `key`
* is treated as the associated object.
* @throws {Error} Throws an error if the constructed descriptor is not
* valid.
*/

@@ -36,5 +43,5 @@ constructor(object, key) {

}
if (Descriptor.isDescriptor(object)) {
else if (Descriptor.isDescriptor(object)) {
this.#desc = object;
this.#object = undefined;
this.#object = isObject(key) ? key : undefined;
}

@@ -46,3 +53,7 @@ else if (isObject(object) && isValidKey(key)) {

if (!this.isDescriptor) {
console.error('Current descriptor:', this.#desc);
console.error(`
Descriptor(object,key) FAILED:
object: ${object === globalThis ? '[GLOBAL]' : (typeof key === 'object' ? JSON.stringify(object) : String(object))}
key: ${key === globalThis ? '[GLOBAL]' : (typeof key === 'object' ? JSON.stringify(key) : String(key))}
descriptor: `, this.#desc);
throw new Error(`Not a valid descriptor:`, this.#desc);

@@ -289,9 +300,42 @@ }

*/
applyTo(object, forKey) {
applyTo(object, forKey, bindAccessors = false) {
if (!isObject(object) || !isValidKey(forKey)) {
throw new Error(`Cannot apply descriptor to non-object or invalid key`);
}
return Object.defineProperty(object, forKey, this.#desc);
return Object.defineProperty(object, forKey, this.toObject(bindAccessors));
}
/**
* Converts this Descriptor class instance into a basic object descriptor
* that is accepted by all the standard JavaScript runtime methods that
* deal with object descriptors.
*
* @param {boolean|object} bindAccessors if `true`, a non-fatal attempt to
* bind accessor getter and setter methods is made before returning the
* object. If `bindAccessors` is truthy and is also an object, this is the
* object the accessors will be bound to. If the value is falsy or if the
* descriptor instance represents a data descriptor, nothing happens.
* @returns {object} the object instance's basic object representation as
* a descriptor.
*/
toObject(bindAccessors = false) {
let descriptor = { ...this.#desc };
if (bindAccessors && this.isAccessor) {
if (this.hasObject) {
descriptor = {
...descriptor,
get: this.boundGet,
set: this.boundSet
};
}
else if (isObject(bindAccessors)) {
descriptor = {
...descriptor,
get: this.get?.bind(bindAccessors),
set: this.set?.bind(bindAccessors)
};
}
}
return descriptor;
}
/**
* Converts this descriptor object into a base representation

@@ -322,3 +366,3 @@ *

default:
return this.#desc;
return this.toObject();
}

@@ -325,0 +369,0 @@ }

@@ -61,7 +61,7 @@ {

"type": "module",
"version": "1.10.0",
"version": "2.0.0",
"dependencies": {
"@nejs/extension": "^2.2.0"
"@nejs/extension": "^2.5.0"
},
"browser": "dist/@nejs/basic-extensions.bundle.1.9.0.js"
"browser": "dist/@nejs/basic-extensions.bundle.1.10.0.js"
}

@@ -26,15 +26,15 @@ import { FunctionExtensions, FunctionPrototypeExtensions } from './functionextensions.js'

const StaticPatches = [
[Object, ObjectExtensions],
[Function, FunctionExtensions],
[Reflect, ReflectExtensions],
[String, StringExtensions],
[Symbol, SymbolExtensions],
[Object, ObjectExtensions, Object.name],
[Function, FunctionExtensions, Function.name],
[Reflect, ReflectExtensions, 'Reflect'], // Missing a .name property
[String, StringExtensions, String.name],
[Symbol, SymbolExtensions, 'Symbol'], // Missing a .name property
]
const InstancePatches = [
[Object.prototype, ObjectPrototypeExtensions],
[Function.prototype, FunctionPrototypeExtensions],
[Array.prototype, ArrayPrototypeExtensions],
[Map.prototype, MapPrototypeExtensions],
[Set.prototype, SetPrototypeExtensions],
[Object.prototype, ObjectPrototypeExtensions, Object.name],
[Function.prototype, FunctionPrototypeExtensions, Function.name],
[Array.prototype, ArrayPrototypeExtensions, Array.name],
[Map.prototype, MapPrototypeExtensions, Map.name],
[Set.prototype, SetPrototypeExtensions, Set.name],
]

@@ -48,4 +48,2 @@

const Extensions = {
global: GlobalFunctionsAndProps,
[AsyncIterableExtensions.key]: AsyncIterableExtensions,

@@ -87,2 +85,3 @@ [AsyncIteratorExtensions.key]: AsyncIteratorExtensions,

Object.values(Extensions).forEach((extension) => { extension.apply() })
GlobalFunctionsAndProps.apply()
},

@@ -113,2 +112,3 @@

Object.values(Extensions).forEach((extension) => { extension.revert() })
GlobalFunctionsAndProps.revert()
},

@@ -118,23 +118,49 @@ })

export const all = (() => {
const extensions = [
...Array.from(Patches.values()),
...Array.from(Object.values(Extensions)),
]
const dest = {
patches: {},
classes: {},
global: {},
};
const dest = extensions.reduce((accumulator, extension) => {
Reflect.ownKeys(extension.patchEntries).reduce((_, key) => {
const entry = extension.patchEntries[key]
const entriesReducer = (accumulator, [key, entry]) => {
const descriptor = new Descriptor(entry.descriptor, entry.owner)
if (entry.isAccessor)
accumulator[key] = new Descriptor(entry.descriptor)
else
accumulator[key] = entry.computed
descriptor.applyTo(accumulator, key, true)
return accumulator
}, accumulator)
return accumulator
}
const staticPatchReducer = (accumulator, [_, patch, ownerName]) => {
if (!accumulator?.[ownerName]) {
accumulator[ownerName] = {}
}
[...patch].reduce(entriesReducer, accumulator[ownerName])
return accumulator
}, {})
};
return dest
const instancePatchReducer = (accumulator, [_, patch, ownerName]) => {
if (!accumulator?.[ownerName])
accumulator[ownerName] = {};
if (!accumulator[ownerName]?.prototype)
accumulator[ownerName].prototype = {};
[...patch].reduce(entriesReducer, accumulator[ownerName].prototype)
return accumulator
}
StaticPatches.reduce(staticPatchReducer, dest.patches);
InstancePatches.reduce(instancePatchReducer, dest.patches);
(Object.entries(Extensions)
.map(([k,v]) => [k, v, k])
.reduce(staticPatchReducer, dest.classes)
)
for (const [key, entry] of GlobalFunctionsAndProps) {
const descriptor = new Descriptor(entry.descriptor, entry.owner)
Object.defineProperty(dest.global, key, descriptor.toObject(true))
}
return dest
})()

@@ -146,2 +172,3 @@

Patches,
GlobalFunctionsAndProps,
StaticPatches,

@@ -163,2 +190,3 @@ InstancePatches,

Controls,
GlobalFunctionsAndProps,
}

@@ -165,0 +193,0 @@

@@ -20,13 +20,15 @@ import { Extension } from '@nejs/extension'

* Constructs an instance of AsyncIterable. Similar to Iterable, it can be
* initialized with either an iterable object or individual elements. The
* elements can be promises, direct values, or a mix of both. If the first
* argument is an iterable, the instance is initialized with the elements
* from the iterable, followed by any additional arguments. If the first
* argument is not an iterable, all arguments are treated as individual
* elements.
* initialized with either an iterable object, an async generator function,
* or individual elements. The elements can be promises, direct values, or a
* mix of both. If the first argument is an iterable or an async generator
* function, the instance is initialized with the elements from the iterable
* or the generated elements from the async generator function, followed by
* any additional arguments. If the first argument is not an iterable or an
* async generator function, all arguments are treated as individual elements.
*
* @param {Iterable|Promise|*} elementsOrFirstElement - An iterable object,
* a Promise, or the first element.
* @param {Iterable|AsyncGeneratorFunction|Promise|*} elementsOrFirstElement -
* An iterable object, an async generator function, a Promise, or the first
* element.
* @param {...Promise|*} moreElements - Additional elements if the first
* argument is not an iterable.
* argument is not an iterable or an async generator function.
*/

@@ -36,5 +38,11 @@ constructor(elementsOrFirstElement, ...moreElements) {

elementsOrFirstElement != null &&
typeof elementsOrFirstElement[Symbol.iterator] === 'function'
(typeof elementsOrFirstElement[Symbol.iterator] === 'function' ||
typeof elementsOrFirstElement[Symbol.asyncIterator] === 'function')
) {
this.#elements = [...elementsOrFirstElement, ...moreElements];
} else if (
typeof elementsOrFirstElement === 'function' &&
elementsOrFirstElement.constructor.name === 'AsyncGeneratorFunction'
) {
this.#elements = elementsOrFirstElement();
} else {

@@ -56,6 +64,6 @@ this.#elements = [elementsOrFirstElement, ...moreElements];

async *[Symbol.asyncIterator]() {
for (const element of this.#elements) {
// Treat each element as a promise. If it's not, it's automatically
// wrapped as a resolved promise.
yield Promise.resolve(element);
for await (const element of this.#elements) {
// No need to wrap as a promise here since `for await...of` can handle
// both Promises and non-Promise values.
yield element;
}

@@ -104,14 +112,21 @@ }

*
* @param {object} asyncIterable any object that has a
* `[Symbol.asyncIterable]` property assigned to a generator function.
* @param {object|AsyncGeneratorFunction} asyncIterable any object that has a
* `[Symbol.asyncIterable]` property assigned to a generator function or an
* async generator function itself.
*/
constructor(asyncIterable) {
if (!asyncIterable || !Reflect.has(asyncIterable, Symbol.asyncIterator)) {
if (typeof asyncIterable === 'function' &&
asyncIterable.constructor.name === 'AsyncGeneratorFunction') {
this.#asyncIterable = asyncIterable();
} else if (
!asyncIterable ||
!Reflect.has(asyncIterable, Symbol.asyncIterator)
) {
throw new TypeError(
'Value used to instantiate AsyncIterator is not an async iterable'
);
} else {
this.#asyncIterable = asyncIterable;
}
this.#asyncIterable = asyncIterable;
this.#asyncIterator = asyncIterable[Symbol.asyncIterator]();
this.#asyncIterator = this.#asyncIterable[Symbol.asyncIterator]();
}

@@ -118,0 +133,0 @@

@@ -27,9 +27,16 @@ import { Extension } from '@nejs/extension'

/**
* Creates a new instance of Descriptor either from another object or
* around the supplied object descriptor value.
* Constructs a Descriptor instance which wraps and manages an object
* property descriptor. The constructor can handle an existing descriptor
* object or create a new one based on an object and a property key.
*
* @param {object} object either an object descriptor or the object
* from which to get the descriptor
* @param {symbol|string} key a valid key for accessing the descriptor
* on the aforesupplied object.
* @param {object|Descriptor} object - The target object or an existing
* Descriptor instance. If it's an object, it is used in conjunction with
* `key` to create a descriptor. If it's a Descriptor instance, it is used
* directly as the descriptor.
* @param {string|symbol} [key] - The property key for which the descriptor
* is to be created. This parameter is ignored if `object` is a Descriptor
* instance. If `key` is an object and `object` is a valid descriptor, `key`
* is treated as the associated object.
* @throws {Error} Throws an error if the constructed descriptor is not
* valid.
*/

@@ -40,7 +47,6 @@ constructor(object, key) {

}
if (Descriptor.isDescriptor(object)) {
else if (Descriptor.isDescriptor(object)) {
this.#desc = object
this.#object = undefined
}
this.#object = isObject(key) ? key : undefined
}
else if (isObject(object) && isValidKey(key)) {

@@ -52,3 +58,8 @@ this.#desc = Object.getOwnPropertyDescriptor(object, key)

if (!this.isDescriptor) {
console.error('Current descriptor:', this.#desc)
console.error(`
Descriptor(object,key) FAILED:
object: ${object === globalThis ? '[GLOBAL]' : (typeof key === 'object' ? JSON.stringify(object) : String(object))}
key: ${key === globalThis ? '[GLOBAL]' : (typeof key === 'object' ? JSON.stringify(key) : String(key))}
descriptor: `, this.#desc
)
throw new Error(`Not a valid descriptor:`, this.#desc)

@@ -320,3 +331,3 @@ }

*/
applyTo(object, forKey) {
applyTo(object, forKey, bindAccessors = false) {
if (!isObject(object) || !isValidKey(forKey)) {

@@ -326,6 +337,42 @@ throw new Error(`Cannot apply descriptor to non-object or invalid key`)

return Object.defineProperty(object, forKey, this.#desc)
return Object.defineProperty(object, forKey, this.toObject(bindAccessors))
}
/**
* Converts this Descriptor class instance into a basic object descriptor
* that is accepted by all the standard JavaScript runtime methods that
* deal with object descriptors.
*
* @param {boolean|object} bindAccessors if `true`, a non-fatal attempt to
* bind accessor getter and setter methods is made before returning the
* object. If `bindAccessors` is truthy and is also an object, this is the
* object the accessors will be bound to. If the value is falsy or if the
* descriptor instance represents a data descriptor, nothing happens.
* @returns {object} the object instance's basic object representation as
* a descriptor.
*/
toObject(bindAccessors = false) {
let descriptor = { ...this.#desc }
if (bindAccessors && this.isAccessor) {
if (this.hasObject) {
descriptor = {
...descriptor,
get: this.boundGet,
set: this.boundSet
}
}
else if (isObject(bindAccessors)) {
descriptor = {
...descriptor,
get: this.get?.bind(bindAccessors),
set: this.set?.bind(bindAccessors)
}
}
}
return descriptor
}
/**
* Converts this descriptor object into a base representation

@@ -360,3 +407,3 @@ *

default:
return this.#desc
return this.toObject()
}

@@ -363,0 +410,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc