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 2.5.0 to 2.6.0

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

110

dist/cjs/arrayextensions.js

@@ -14,59 +14,61 @@ "use strict";

exports.ArrayPrototypeExtensions = new extension_1.Patch(Array.prototype, {
/**
* Sometimes defining even a short function for the invocation of `find`
* can be troublesome. This helper function performs that job for you. If
* the specified element is in the array, `true` will be returned.
*
* @param {*} value the value to search for. This value must triple equals
* the array element in order to return true.
* @returns true if the exact element exists in the array, false otherwise
*/
contains(value) {
return !!this.find(entry => entry === value);
},
/**
* The `findEntry` function searches the entries of the object and returns
* the `[index, value]` entry array for the first matching value found.
*
* @param {function} findFn a function that takes the element to be checked
* and returns a boolean value
* @returns if `findFn` returns `true`, an array with two elements, the first
* being the index, the second being the value, is returned.
*/
findEntry(findFn) {
const entries = this.entries();
const VALUE = 1;
for (let entry of entries) {
if (findFn(entry[VALUE])) {
return entry;
[extension_1.Patch.kMutablyHidden]: {
/**
* Sometimes defining even a short function for the invocation of `find`
* can be troublesome. This helper function performs that job for you. If
* the specified element is in the array, `true` will be returned.
*
* @param {*} value the value to search for. This value must triple equals
* the array element in order to return true.
* @returns true if the exact element exists in the array, false otherwise
*/
contains(value) {
return !!this.find(entry => entry === value);
},
/**
* The `findEntry` function searches the entries of the object and returns
* the `[index, value]` entry array for the first matching value found.
*
* @param {function} findFn a function that takes the element to be checked
* and returns a boolean value
* @returns if `findFn` returns `true`, an array with two elements, the first
* being the index, the second being the value, is returned.
*/
findEntry(findFn) {
const entries = this.entries();
const VALUE = 1;
for (let entry of entries) {
if (findFn(entry[VALUE])) {
return entry;
}
}
}
return undefined;
return undefined;
},
/**
* A getter property that returns the first element of the array. If the
* array is empty, it returns `undefined`. This property is useful for
* scenarios where you need to quickly access the first item of an array
* without the need for additional checks or method calls.
*
* @returns {*} The first element of the array or `undefined` if the array
* is empty.
*/
get first() {
return this[0];
},
/**
* A getter property that returns the last element of the array. It
* calculates the last index based on the array's length. If the array is
* empty, it returns `undefined`. This property is beneficial when you need
* to access the last item in an array, improving code readability and
* avoiding manual index calculation.
*
* @returns {*} The last element of the array or `undefined` if the
* array is empty.
*/
get last() {
return this[this.length - 1];
},
},
/**
* A getter property that returns the first element of the array. If the
* array is empty, it returns `undefined`. This property is useful for
* scenarios where you need to quickly access the first item of an array
* without the need for additional checks or method calls.
*
* @returns {*} The first element of the array or `undefined` if the array
* is empty.
*/
get first() {
return this[0];
},
/**
* A getter property that returns the last element of the array. It
* calculates the last index based on the array's length. If the array is
* empty, it returns `undefined`. This property is beneficial when you need
* to access the last item in an array, improving code readability and
* avoiding manual index calculation.
*
* @returns {*} The last element of the array or `undefined` if the
* array is empty.
*/
get last() {
return this[this.length - 1];
},
});
//# sourceMappingURL=arrayextensions.js.map

@@ -119,83 +119,85 @@ "use strict";

exports.FunctionPrototypeExtensions = new extension_1.Patch(Function.prototype, {
/**
* Determines if a given value is an asynchronous function. It checks if the
* value is an instance of `Function` and if its string representation
* includes the keyword 'Async'. This method is particularly useful for
* identifying async functions.
*
* @returns {boolean} Returns `true` if the value is an async function,
* otherwise `false`.
*/
get isAsync() {
return Function.isAsync(this);
[extension_1.Patch.kMutablyHidden]: {
/**
* Determines if a given value is an asynchronous function. It checks if the
* value is an instance of `Function` and if its string representation
* includes the keyword 'Async'. This method is particularly useful for
* identifying async functions.
*
* @returns {boolean} Returns `true` if the value is an async function,
* otherwise `false`.
*/
get isAsync() {
return Function.isAsync(this);
},
/**
* The function checks if a given value is an async generator function
*
* @returns {boolean} `true` if the value is an instance of a function and
* its string tag is 'AsyncGeneratorFunction', otherwise it returns `false`.
*/
get isAsyncGenerator() {
return Function.isAsyncGenerator(this);
},
/**
* Checks if a given value is an arrow function. It verifies if the value is
* an instance of `Function`, if its string representation includes the '=>'
* symbol, and if it lacks a prototype, which is a characteristic of arrow
* functions in JavaScript.
*
* @returns {boolean} Returns `true` if the value is an arrow function,
* otherwise `false`.
*/
get isBigArrow() {
return Function.isBigArrow(this);
},
/**
* Determines if a given value is a bound function. Bound functions are
* created using the `Function.prototype.bind` method, which allows setting
* the `this` value at the time of binding. This method checks if the value
* is an instance of `Function`, if its string representation starts with
* 'bound', and if it lacks a `prototype` property. These characteristics
* are indicative of bound functions in JavaScript.
*
* @returns {boolean} Returns `true` if the value is a bound function,
* otherwise `false`. Bound functions have a specific format in their
* string representation and do not have their own `prototype` property.
*/
get isBound() {
return Function.isBound(this);
},
/**
* Determines if a given value is a class. It checks if the value is an
* instance of `Function` and if its string representation includes the
* keyword 'class'. This method is useful for distinguishing classes from
* other function types in JavaScript.
*
* @returns {boolean} Returns `true` if the value is a class, otherwise
* `false`.
*/
get isClass() {
return Function.isClass(this);
},
/**
* Checks if a given value is a regular function. This method verifies if
* the value is an instance of `Function`, which includes regular functions,
* classes, and async functions but excludes arrow functions.
*
* @returns {boolean} Returns `true` if the value is a regular function,
* otherwise `false`.
*/
get isFunction() {
return Function.isFunction(this);
},
/**
* The function checks if a given value is a generator function
*
* @returns {boolean} `true` if the value is an instance of a function and
* its string tag is 'GeneratorFunction', otherwise it returns `false`.
*/
get isGenerator() {
return Function.isGenerator(this);
},
},
/**
* The function checks if a given value is an async generator function
*
* @returns {boolean} `true` if the value is an instance of a function and
* its string tag is 'AsyncGeneratorFunction', otherwise it returns `false`.
*/
get isAsyncGenerator() {
return Function.isAsyncGenerator(this);
},
/**
* Checks if a given value is an arrow function. It verifies if the value is
* an instance of `Function`, if its string representation includes the '=>'
* symbol, and if it lacks a prototype, which is a characteristic of arrow
* functions in JavaScript.
*
* @returns {boolean} Returns `true` if the value is an arrow function,
* otherwise `false`.
*/
get isBigArrow() {
return Function.isBigArrow(this);
},
/**
* Determines if a given value is a bound function. Bound functions are
* created using the `Function.prototype.bind` method, which allows setting
* the `this` value at the time of binding. This method checks if the value
* is an instance of `Function`, if its string representation starts with
* 'bound', and if it lacks a `prototype` property. These characteristics
* are indicative of bound functions in JavaScript.
*
* @returns {boolean} Returns `true` if the value is a bound function,
* otherwise `false`. Bound functions have a specific format in their
* string representation and do not have their own `prototype` property.
*/
get isBound() {
return Function.isBound(this);
},
/**
* Determines if a given value is a class. It checks if the value is an
* instance of `Function` and if its string representation includes the
* keyword 'class'. This method is useful for distinguishing classes from
* other function types in JavaScript.
*
* @returns {boolean} Returns `true` if the value is a class, otherwise
* `false`.
*/
get isClass() {
return Function.isClass(this);
},
/**
* Checks if a given value is a regular function. This method verifies if
* the value is an instance of `Function`, which includes regular functions,
* classes, and async functions but excludes arrow functions.
*
* @returns {boolean} Returns `true` if the value is a regular function,
* otherwise `false`.
*/
get isFunction() {
return Function.isFunction(this);
},
/**
* The function checks if a given value is a generator function
*
* @returns {boolean} `true` if the value is an instance of a function and
* its string tag is 'GeneratorFunction', otherwise it returns `false`.
*/
get isGenerator() {
return Function.isGenerator(this);
},
});
//# sourceMappingURL=functionextensions.js.map

@@ -6,26 +6,28 @@ "use strict";

exports.MapPrototypeExtensions = new extension_1.Patch(Map.prototype, {
/**
* The function `getKey` returns the key associated with a given value
* in a map.
*
* @param {any} value - The value parameter is the value that you want to
* find the corresponding key for in the map.
* @param [strict=true] - The "strict" parameter is a boolean value that
* determines whether strict equality (===) or loose equality (==) should
* be used when comparing the "value" parameter with the values in the
* entries of the object. If "strict" is set to true, strict equality will
* be used.
* @returns the key associated with the given value. If a matching key is
* found, it is returned. If no matching key is found, null is returned.
*/
getKey(value, strict = true) {
for (const [key, entryValue] of this) {
if ((strict && value === entryValue) &&
(!strict && value == entryValue)) {
return key;
[extension_1.Patch.kMutablyHidden]: {
/**
* The function `getKey` returns the key associated with a given value
* in a map.
*
* @param {any} value - The value parameter is the value that you want to
* find the corresponding key for in the map.
* @param [strict=true] - The "strict" parameter is a boolean value that
* determines whether strict equality (===) or loose equality (==) should
* be used when comparing the "value" parameter with the values in the
* entries of the object. If "strict" is set to true, strict equality will
* be used.
* @returns the key associated with the given value. If a matching key is
* found, it is returned. If no matching key is found, null is returned.
*/
getKey(value, strict = true) {
for (const [key, entryValue] of this) {
if ((strict && value === entryValue) &&
(!strict && value == entryValue)) {
return key;
}
return null;
}
return null;
}
},
},
});
//# sourceMappingURL=mapextensions.js.map

@@ -181,21 +181,53 @@ "use strict";

});
const staticPatches = exports.ObjectExtensions.patches;
exports.ObjectPrototypeExtensions = new extension_1.Patch(Object.prototype, {
/**
* Strips an object down to only the keys specified. Optionally, any
* accessors can be made to retain their context on the source object.
* This is a passthrough to the static {@link Object.stripTo} function
*
* @param {Array<string|symbol>} keys the keys that should appear in the
* final reduced object
* @param {boolean} [bindAccessors = true] if this value is true then any
* accessors from the source object will continue to have their `this`
* value bound to the source. If the getter or setter on that object is
* defined using an arrow function, this will not work as intended.
* @returns {object} an object containing only the keys and symbols
* specified in the `keys` parameter.
*/
stripTo(keys, bindAccessors = true) {
return Object.stripTo(this, keys, bindAccessors);
}
[extension_1.Patch.kMutablyHidden](store) {
return {
/**
* Checks to see if the supplied `value` is both an object, and has the
* appropriate symbol defined.
*
* @param {any} value the value to determine if it contains a defined
* `Symbol.toStringTag` defined.
* @returns true if the symbol is defined, false otherwise
*/
get hasStringTag() {
return staticPatches.hasStringTag(this);
},
/**
* Retrieves the string tag of an object. The string tag is a representation
* of the object's type, as defined by its `Object.prototype.toString`
* method. This utility method is helpful for getting a more descriptive
* type of an object than what is returned by the `typeof` operator,
* especially for custom objects.
*
* @param {*} value - The object whose string tag is to be retrieved.
* @param {boolean} strict - if this is set to true, undefined will be
* returned whenever a supplied object does not have a
* `Symbol.toStringTag` defined, period. if false, the default,
* @returns {string} - The string tag of the object, indicating its type.
*/
getStringTag(strict = false) {
return staticPatches.getStringTag(this, strict);
},
/**
* Strips an object down to only the keys specified. Optionally, any
* accessors can be made to retain their context on the source object.
* This is a passthrough to the static {@link Object.stripTo} function
*
* @param {Array<string|symbol>} keys the keys that should appear in the
* final reduced object
* @param {boolean} [bindAccessors = true] if this value is true then any
* accessors from the source object will continue to have their `this`
* value bound to the source. If the getter or setter on that object is
* defined using an arrow function, this will not work as intended.
* @returns {object} an object containing only the keys and symbols
* specified in the `keys` parameter.
*/
stripTo(keys, bindAccessors = true) {
return Object.stripTo(this, keys, bindAccessors);
}
};
},
});
//# sourceMappingURL=objectextensions.js.map

@@ -6,200 +6,202 @@ "use strict";

exports.SetPrototypeExtensions = new extension_1.Patch(Set.prototype, {
/**
* Merges multiple iterables into the set. Each element from the iterables
* is added to the set, ensuring uniqueness of all elements. This method
* mutates the original set.
*
* @param {...Iterable} iterables - One or more iterable objects (like Set
* or Array) whose elements will be added to the set.
*/
concat(...iterables) {
for (const iterable of iterables) {
if (typeof iterable === 'string' ||
!Reflect.has(iterable, Symbol.iterator)) {
this.add(iterable);
continue;
[extension_1.Patch.kMutablyHidden]: {
/**
* Merges multiple iterables into the set. Each element from the iterables
* is added to the set, ensuring uniqueness of all elements. This method
* mutates the original set.
*
* @param {...Iterable} iterables - One or more iterable objects (like Set
* or Array) whose elements will be added to the set.
*/
concat(...iterables) {
for (const iterable of iterables) {
if (typeof iterable === 'string' ||
!Reflect.has(iterable, Symbol.iterator)) {
this.add(iterable);
continue;
}
for (const element of iterable) {
this.add(element);
}
}
for (const element of iterable) {
this.add(element);
},
/**
* Checks to see if any value within the `Set` loosely equals the supplied
* value.
*
* @param {*} value any value that might be loosely equal to an item in the
* set, as opposed to {@link Set.has} which is the equivalent of a strict or
* triple equals (`===`) check
* @returns {boolean} `true` if any value within the set is loosely equal to
* the supplied value, `false` otherwise
*/
contains(value) {
for (const element of this) {
if (value == element) {
return true;
}
}
}
},
/**
* Checks to see if any value within the `Set` loosely equals the supplied
* value.
*
* @param {*} value any value that might be loosely equal to an item in the
* set, as opposed to {@link Set.has} which is the equivalent of a strict or
* triple equals (`===`) check
* @returns {boolean} `true` if any value within the set is loosely equal to
* the supplied value, `false` otherwise
*/
contains(value) {
for (const element of this) {
if (value == element) {
return true;
return false;
},
/**
* Checks if every element in the set passes the test implemented by the
* provided function. The function is called with each element of the set.
* Note: Since sets do not have indices, the index parameter is always NaN.
*
* @param {Function} everyFn - The function to test each element. Receives
* the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `everyFn`.
* @throws {TypeError} If `everyFn` is not a function.
* @returns {boolean} True if every element passes the test, false otherwise.
*/
every(everyFn, thisArg) {
if (typeof everyFn !== 'function') {
throw new TypeError(`everyFn must be a function! Received ${String(everyFn)}`);
}
}
return false;
},
/**
* Checks if every element in the set passes the test implemented by the
* provided function. The function is called with each element of the set.
* Note: Since sets do not have indices, the index parameter is always NaN.
*
* @param {Function} everyFn - The function to test each element. Receives
* the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `everyFn`.
* @throws {TypeError} If `everyFn` is not a function.
* @returns {boolean} True if every element passes the test, false otherwise.
*/
every(everyFn, thisArg) {
if (typeof everyFn !== 'function') {
throw new TypeError(`everyFn must be a function! Received ${String(everyFn)}`);
}
let found = 0;
for (const element of this) {
if (everyFn.call(thisArg, element, NaN, this)) {
found++;
let found = 0;
for (const element of this) {
if (everyFn.call(thisArg, element, NaN, this)) {
found++;
}
}
}
return (found === this.size);
},
/**
* Finds the first element in the set satisfying the provided testing
* function. If no elements satisfy the testing function, undefined is
* returned. The function is called with each element of the set.
* Note: Since sets do not have indices, the index parameter is always NaN.
*
* @param {Function} findFn - The function to execute on each element. It
* receives the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `findFn`.
* @throws {TypeError} If `findFn` is not a function.
* @returns {*} The first element that satisfies `findFn`, or undefined.
*/
find(findFn, thisArg) {
if (typeof findFn !== 'function') {
throw new TypeError(`findFn must be a function! Received ${String(findFn)}`);
}
for (const element of this) {
const match = findFn.call(thisArg, element, NaN, this);
if (match) {
return element;
return (found === this.size);
},
/**
* Finds the first element in the set satisfying the provided testing
* function. If no elements satisfy the testing function, undefined is
* returned. The function is called with each element of the set.
* Note: Since sets do not have indices, the index parameter is always NaN.
*
* @param {Function} findFn - The function to execute on each element. It
* receives the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `findFn`.
* @throws {TypeError} If `findFn` is not a function.
* @returns {*} The first element that satisfies `findFn`, or undefined.
*/
find(findFn, thisArg) {
if (typeof findFn !== 'function') {
throw new TypeError(`findFn must be a function! Received ${String(findFn)}`);
}
}
return undefined;
},
/**
* Finds the last element in the set satisfying the provided testing function.
* If no elements satisfy the testing function, undefined is returned. The
* function is called with each element of the set in reverse order.
* Note: Since sets do not have indices, the index parameter is always NaN.
*
* @param {Function} findFn - The function to execute on each element. It
* receives the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `findFn`.
* @throws {TypeError} If `findFn` is not a function.
* @returns {*} The last element that satisfies `findFn`, or undefined.
*/
findLast(findFn, thisArg) {
if (typeof findFn !== 'function') {
throw new TypeError(`findFn must be a function! Received ${String(findFn)}`);
}
const found = [];
for (const element of this) {
const match = findFn.call(thisArg, element, NaN, this);
if (match) {
found.push(element);
for (const element of this) {
const match = findFn.call(thisArg, element, NaN, this);
if (match) {
return element;
}
}
}
if (found.length) {
return found[found.length - 1];
}
return undefined;
},
/**
* A getter property that returns the number of elements in the set.
* This is an alias for the `size` property of the set.
*
* @returns {number} The number of elements in the set.
*/
get length() {
return this.size;
},
/**
* Creates a new array populated with the results of calling the provided
* function on every element in the set. The function is called with each
* element of the set. Note: Since sets do not have indices, the index
* parameter is always NaN.
*
* @param {Function} mapFn - The function to execute on each element. It
* receives the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `mapFn`.
* @throws {TypeError} If `mapFn` is not a function.
* @returns {Array} A new array with each element being the result of the
* `mapFn`.
*/
map(mapFn, thisArg) {
if (typeof mapFn !== 'function') {
throw new TypeError(`mapFn must be a function! Received ${String(mapFn)}`);
}
const transformed = [];
for (const element of this) {
transformed.push(mapFn.call(thisArg, element, NaN, this));
}
return transformed;
},
/**
* Applies a function against an accumulator and each element in the set to
* reduce it to a single value. The function is called with each element of
* the set. Note: Since sets do not have indices, the index parameter is
* always NaN.
*
* @param {Function} reduceFn - The function to execute on each element. It
* receives the accumulator, element, index (always NaN), and the set itself.
* @param {*} initialValue - The initial value to start reducing from.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `reduceFn`.
* @throws {TypeError} If `reduceFn` is not a function.
* @returns {*} The reduced value.
*/
reduce(reduceFn, initialValue, thisArg) {
if (typeof reduceFn !== 'function') {
throw new TypeError(`reduceFn must be a Function! Received ${String(reduceFn)}`);
}
let accumulator = initialValue;
for (const element of this) {
accumulator = reduceFn.call(thisArg, accumulator, element, NaN, this);
}
return accumulator;
},
/**
* Tests whether at least one element in the set passes the test implemented
* by the provided function. The function is called with each element of the
* set. Note: Since sets do not have indices, the index parameter is always NaN.
*
* @param {Function} someFn - The function to test each element. It receives
* the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `someFn`.
* @throws {TypeError} If `someFn` is not a function.
* @returns {boolean} True if at least one element passes the test, false
* otherwise.
*/
some(someFn, thisArg) {
if (typeof someFn !== 'function') {
throw new TypeError(`someFn must be a function! Received ${String(someFn)}`);
}
for (const element of this) {
if (someFn.call(thisArg, element, NaN, this)) {
return true;
return undefined;
},
/**
* Finds the last element in the set satisfying the provided testing function.
* If no elements satisfy the testing function, undefined is returned. The
* function is called with each element of the set in reverse order.
* Note: Since sets do not have indices, the index parameter is always NaN.
*
* @param {Function} findFn - The function to execute on each element. It
* receives the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `findFn`.
* @throws {TypeError} If `findFn` is not a function.
* @returns {*} The last element that satisfies `findFn`, or undefined.
*/
findLast(findFn, thisArg) {
if (typeof findFn !== 'function') {
throw new TypeError(`findFn must be a function! Received ${String(findFn)}`);
}
}
return false;
const found = [];
for (const element of this) {
const match = findFn.call(thisArg, element, NaN, this);
if (match) {
found.push(element);
}
}
if (found.length) {
return found[found.length - 1];
}
return undefined;
},
/**
* A getter property that returns the number of elements in the set.
* This is an alias for the `size` property of the set.
*
* @returns {number} The number of elements in the set.
*/
get length() {
return this.size;
},
/**
* Creates a new array populated with the results of calling the provided
* function on every element in the set. The function is called with each
* element of the set. Note: Since sets do not have indices, the index
* parameter is always NaN.
*
* @param {Function} mapFn - The function to execute on each element. It
* receives the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `mapFn`.
* @throws {TypeError} If `mapFn` is not a function.
* @returns {Array} A new array with each element being the result of the
* `mapFn`.
*/
map(mapFn, thisArg) {
if (typeof mapFn !== 'function') {
throw new TypeError(`mapFn must be a function! Received ${String(mapFn)}`);
}
const transformed = [];
for (const element of this) {
transformed.push(mapFn.call(thisArg, element, NaN, this));
}
return transformed;
},
/**
* Applies a function against an accumulator and each element in the set to
* reduce it to a single value. The function is called with each element of
* the set. Note: Since sets do not have indices, the index parameter is
* always NaN.
*
* @param {Function} reduceFn - The function to execute on each element. It
* receives the accumulator, element, index (always NaN), and the set itself.
* @param {*} initialValue - The initial value to start reducing from.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `reduceFn`.
* @throws {TypeError} If `reduceFn` is not a function.
* @returns {*} The reduced value.
*/
reduce(reduceFn, initialValue, thisArg) {
if (typeof reduceFn !== 'function') {
throw new TypeError(`reduceFn must be a Function! Received ${String(reduceFn)}`);
}
let accumulator = initialValue;
for (const element of this) {
accumulator = reduceFn.call(thisArg, accumulator, element, NaN, this);
}
return accumulator;
},
/**
* Tests whether at least one element in the set passes the test implemented
* by the provided function. The function is called with each element of the
* set. Note: Since sets do not have indices, the index parameter is always NaN.
*
* @param {Function} someFn - The function to test each element. It receives
* the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `someFn`.
* @throws {TypeError} If `someFn` is not a function.
* @returns {boolean} True if at least one element passes the test, false
* otherwise.
*/
some(someFn, thisArg) {
if (typeof someFn !== 'function') {
throw new TypeError(`someFn must be a function! Received ${String(someFn)}`);
}
for (const element of this) {
if (someFn.call(thisArg, element, NaN, this)) {
return true;
}
}
return false;
},
},
});
//# sourceMappingURL=setextensions.js.map

@@ -85,73 +85,75 @@ "use strict";

exports.StringPrototypeExtensions = new extension_1.Patch(String.prototype, {
/**
* Extracts a substring from the current string, starting at a given offset
* and bounded by specified opening and closing tokens. This method is
* particularly useful for parsing nested structures or quoted strings,
* where the level of nesting or the presence of escape characters must
* be considered.
*
* @param {number} offset The position in the string from which to start the
* search for the substring.
* @param {[string, string]} tokens An array containing two strings: the
* opening and closing tokens that define the boundaries of the substring
* to be extracted.
* @returns {Object} An object with two properties: `extracted`, the
* extracted substring, and `newOffset`, the position in the original
* string immediately after the end of the extracted substring. If no
* substring is found, `extracted` is `null` and `newOffset` is the same
* as the input offset.
*/
extractSubstring(offset = 0, tokens = parenthesisPair) {
let [openToken, closeToken] = tokens;
let depth = 0;
let start = -1;
let end = -1;
let leadingToken = '';
let firstToken = 0;
for (let i = offset; i < this.length; i++) {
const char = this[i];
if (char === openToken) {
depth++;
if (start === -1)
start = i;
}
else if (char === closeToken) {
depth--;
if (depth === 0) {
end = i;
break;
[extension_1.Patch.kMutablyHidden]: {
/**
* Extracts a substring from the current string, starting at a given offset
* and bounded by specified opening and closing tokens. This method is
* particularly useful for parsing nested structures or quoted strings,
* where the level of nesting or the presence of escape characters must
* be considered.
*
* @param {number} offset The position in the string from which to start the
* search for the substring.
* @param {[string, string]} tokens An array containing two strings: the
* opening and closing tokens that define the boundaries of the substring
* to be extracted.
* @returns {Object} An object with two properties: `extracted`, the
* extracted substring, and `newOffset`, the position in the original
* string immediately after the end of the extracted substring. If no
* substring is found, `extracted` is `null` and `newOffset` is the same
* as the input offset.
*/
extractSubstring(offset = 0, tokens = parenthesisPair) {
let [openToken, closeToken] = tokens;
let depth = 0;
let start = -1;
let end = -1;
let leadingToken = '';
let firstToken = 0;
for (let i = offset; i < this.length; i++) {
const char = this[i];
if (char === openToken) {
depth++;
if (start === -1)
start = i;
}
else if (char === closeToken) {
depth--;
if (depth === 0) {
end = i;
break;
}
}
}
}
let lRange = [
Math.max(0, start - 100),
start
];
let leading = [...this.substring(lRange[0], lRange[1])].reverse().join('');
let reversedLeadingToken;
try {
reversedLeadingToken = /([^ \,\"\'\`]+)/.exec(leading)[1] ?? '';
leadingToken = [...reversedLeadingToken].reverse().join('');
}
catch (ignored) { }
if (start !== -1 && end !== -1) {
const sliceRange = [start, end + 1];
const extracted = this.slice(sliceRange[0], sliceRange[1]);
return {
extracted,
range: [start, end],
newOffset: end + 1,
leadingToken,
};
}
else {
return {
extracted: null,
range: [start, end],
newOffset: offset,
leadingToken,
};
}
let lRange = [
Math.max(0, start - 100),
start
];
let leading = [...this.substring(lRange[0], lRange[1])].reverse().join('');
let reversedLeadingToken;
try {
reversedLeadingToken = /([^ \,\"\'\`]+)/.exec(leading)[1] ?? '';
leadingToken = [...reversedLeadingToken].reverse().join('');
}
catch (ignored) { }
if (start !== -1 && end !== -1) {
const sliceRange = [start, end + 1];
const extracted = this.slice(sliceRange[0], sliceRange[1]);
return {
extracted,
range: [start, end],
newOffset: end + 1,
leadingToken,
};
}
else {
return {
extracted: null,
range: [start, end],
newOffset: offset,
leadingToken,
};
}
},
},
});
//# sourceMappingURL=stringextensions.js.map

@@ -11,59 +11,61 @@ import { Patch } from '@nejs/extension';

export const ArrayPrototypeExtensions = new Patch(Array.prototype, {
/**
* Sometimes defining even a short function for the invocation of `find`
* can be troublesome. This helper function performs that job for you. If
* the specified element is in the array, `true` will be returned.
*
* @param {*} value the value to search for. This value must triple equals
* the array element in order to return true.
* @returns true if the exact element exists in the array, false otherwise
*/
contains(value) {
return !!this.find(entry => entry === value);
},
/**
* The `findEntry` function searches the entries of the object and returns
* the `[index, value]` entry array for the first matching value found.
*
* @param {function} findFn a function that takes the element to be checked
* and returns a boolean value
* @returns if `findFn` returns `true`, an array with two elements, the first
* being the index, the second being the value, is returned.
*/
findEntry(findFn) {
const entries = this.entries();
const VALUE = 1;
for (let entry of entries) {
if (findFn(entry[VALUE])) {
return entry;
[Patch.kMutablyHidden]: {
/**
* Sometimes defining even a short function for the invocation of `find`
* can be troublesome. This helper function performs that job for you. If
* the specified element is in the array, `true` will be returned.
*
* @param {*} value the value to search for. This value must triple equals
* the array element in order to return true.
* @returns true if the exact element exists in the array, false otherwise
*/
contains(value) {
return !!this.find(entry => entry === value);
},
/**
* The `findEntry` function searches the entries of the object and returns
* the `[index, value]` entry array for the first matching value found.
*
* @param {function} findFn a function that takes the element to be checked
* and returns a boolean value
* @returns if `findFn` returns `true`, an array with two elements, the first
* being the index, the second being the value, is returned.
*/
findEntry(findFn) {
const entries = this.entries();
const VALUE = 1;
for (let entry of entries) {
if (findFn(entry[VALUE])) {
return entry;
}
}
}
return undefined;
return undefined;
},
/**
* A getter property that returns the first element of the array. If the
* array is empty, it returns `undefined`. This property is useful for
* scenarios where you need to quickly access the first item of an array
* without the need for additional checks or method calls.
*
* @returns {*} The first element of the array or `undefined` if the array
* is empty.
*/
get first() {
return this[0];
},
/**
* A getter property that returns the last element of the array. It
* calculates the last index based on the array's length. If the array is
* empty, it returns `undefined`. This property is beneficial when you need
* to access the last item in an array, improving code readability and
* avoiding manual index calculation.
*
* @returns {*} The last element of the array or `undefined` if the
* array is empty.
*/
get last() {
return this[this.length - 1];
},
},
/**
* A getter property that returns the first element of the array. If the
* array is empty, it returns `undefined`. This property is useful for
* scenarios where you need to quickly access the first item of an array
* without the need for additional checks or method calls.
*
* @returns {*} The first element of the array or `undefined` if the array
* is empty.
*/
get first() {
return this[0];
},
/**
* A getter property that returns the last element of the array. It
* calculates the last index based on the array's length. If the array is
* empty, it returns `undefined`. This property is beneficial when you need
* to access the last item in an array, improving code readability and
* avoiding manual index calculation.
*
* @returns {*} The last element of the array or `undefined` if the
* array is empty.
*/
get last() {
return this[this.length - 1];
},
});
//# sourceMappingURL=arrayextensions.js.map

@@ -116,83 +116,85 @@ import { Patch } from '@nejs/extension';

export const FunctionPrototypeExtensions = new Patch(Function.prototype, {
/**
* Determines if a given value is an asynchronous function. It checks if the
* value is an instance of `Function` and if its string representation
* includes the keyword 'Async'. This method is particularly useful for
* identifying async functions.
*
* @returns {boolean} Returns `true` if the value is an async function,
* otherwise `false`.
*/
get isAsync() {
return Function.isAsync(this);
[Patch.kMutablyHidden]: {
/**
* Determines if a given value is an asynchronous function. It checks if the
* value is an instance of `Function` and if its string representation
* includes the keyword 'Async'. This method is particularly useful for
* identifying async functions.
*
* @returns {boolean} Returns `true` if the value is an async function,
* otherwise `false`.
*/
get isAsync() {
return Function.isAsync(this);
},
/**
* The function checks if a given value is an async generator function
*
* @returns {boolean} `true` if the value is an instance of a function and
* its string tag is 'AsyncGeneratorFunction', otherwise it returns `false`.
*/
get isAsyncGenerator() {
return Function.isAsyncGenerator(this);
},
/**
* Checks if a given value is an arrow function. It verifies if the value is
* an instance of `Function`, if its string representation includes the '=>'
* symbol, and if it lacks a prototype, which is a characteristic of arrow
* functions in JavaScript.
*
* @returns {boolean} Returns `true` if the value is an arrow function,
* otherwise `false`.
*/
get isBigArrow() {
return Function.isBigArrow(this);
},
/**
* Determines if a given value is a bound function. Bound functions are
* created using the `Function.prototype.bind` method, which allows setting
* the `this` value at the time of binding. This method checks if the value
* is an instance of `Function`, if its string representation starts with
* 'bound', and if it lacks a `prototype` property. These characteristics
* are indicative of bound functions in JavaScript.
*
* @returns {boolean} Returns `true` if the value is a bound function,
* otherwise `false`. Bound functions have a specific format in their
* string representation and do not have their own `prototype` property.
*/
get isBound() {
return Function.isBound(this);
},
/**
* Determines if a given value is a class. It checks if the value is an
* instance of `Function` and if its string representation includes the
* keyword 'class'. This method is useful for distinguishing classes from
* other function types in JavaScript.
*
* @returns {boolean} Returns `true` if the value is a class, otherwise
* `false`.
*/
get isClass() {
return Function.isClass(this);
},
/**
* Checks if a given value is a regular function. This method verifies if
* the value is an instance of `Function`, which includes regular functions,
* classes, and async functions but excludes arrow functions.
*
* @returns {boolean} Returns `true` if the value is a regular function,
* otherwise `false`.
*/
get isFunction() {
return Function.isFunction(this);
},
/**
* The function checks if a given value is a generator function
*
* @returns {boolean} `true` if the value is an instance of a function and
* its string tag is 'GeneratorFunction', otherwise it returns `false`.
*/
get isGenerator() {
return Function.isGenerator(this);
},
},
/**
* The function checks if a given value is an async generator function
*
* @returns {boolean} `true` if the value is an instance of a function and
* its string tag is 'AsyncGeneratorFunction', otherwise it returns `false`.
*/
get isAsyncGenerator() {
return Function.isAsyncGenerator(this);
},
/**
* Checks if a given value is an arrow function. It verifies if the value is
* an instance of `Function`, if its string representation includes the '=>'
* symbol, and if it lacks a prototype, which is a characteristic of arrow
* functions in JavaScript.
*
* @returns {boolean} Returns `true` if the value is an arrow function,
* otherwise `false`.
*/
get isBigArrow() {
return Function.isBigArrow(this);
},
/**
* Determines if a given value is a bound function. Bound functions are
* created using the `Function.prototype.bind` method, which allows setting
* the `this` value at the time of binding. This method checks if the value
* is an instance of `Function`, if its string representation starts with
* 'bound', and if it lacks a `prototype` property. These characteristics
* are indicative of bound functions in JavaScript.
*
* @returns {boolean} Returns `true` if the value is a bound function,
* otherwise `false`. Bound functions have a specific format in their
* string representation and do not have their own `prototype` property.
*/
get isBound() {
return Function.isBound(this);
},
/**
* Determines if a given value is a class. It checks if the value is an
* instance of `Function` and if its string representation includes the
* keyword 'class'. This method is useful for distinguishing classes from
* other function types in JavaScript.
*
* @returns {boolean} Returns `true` if the value is a class, otherwise
* `false`.
*/
get isClass() {
return Function.isClass(this);
},
/**
* Checks if a given value is a regular function. This method verifies if
* the value is an instance of `Function`, which includes regular functions,
* classes, and async functions but excludes arrow functions.
*
* @returns {boolean} Returns `true` if the value is a regular function,
* otherwise `false`.
*/
get isFunction() {
return Function.isFunction(this);
},
/**
* The function checks if a given value is a generator function
*
* @returns {boolean} `true` if the value is an instance of a function and
* its string tag is 'GeneratorFunction', otherwise it returns `false`.
*/
get isGenerator() {
return Function.isGenerator(this);
},
});
//# sourceMappingURL=functionextensions.js.map
import { Patch } from '@nejs/extension';
export const MapPrototypeExtensions = new Patch(Map.prototype, {
/**
* The function `getKey` returns the key associated with a given value
* in a map.
*
* @param {any} value - The value parameter is the value that you want to
* find the corresponding key for in the map.
* @param [strict=true] - The "strict" parameter is a boolean value that
* determines whether strict equality (===) or loose equality (==) should
* be used when comparing the "value" parameter with the values in the
* entries of the object. If "strict" is set to true, strict equality will
* be used.
* @returns the key associated with the given value. If a matching key is
* found, it is returned. If no matching key is found, null is returned.
*/
getKey(value, strict = true) {
for (const [key, entryValue] of this) {
if ((strict && value === entryValue) &&
(!strict && value == entryValue)) {
return key;
[Patch.kMutablyHidden]: {
/**
* The function `getKey` returns the key associated with a given value
* in a map.
*
* @param {any} value - The value parameter is the value that you want to
* find the corresponding key for in the map.
* @param [strict=true] - The "strict" parameter is a boolean value that
* determines whether strict equality (===) or loose equality (==) should
* be used when comparing the "value" parameter with the values in the
* entries of the object. If "strict" is set to true, strict equality will
* be used.
* @returns the key associated with the given value. If a matching key is
* found, it is returned. If no matching key is found, null is returned.
*/
getKey(value, strict = true) {
for (const [key, entryValue] of this) {
if ((strict && value === entryValue) &&
(!strict && value == entryValue)) {
return key;
}
return null;
}
return null;
}
},
},
});
//# sourceMappingURL=mapextensions.js.map

@@ -178,21 +178,53 @@ import { Patch } from '@nejs/extension';

});
const staticPatches = ObjectExtensions.patches;
export const ObjectPrototypeExtensions = new Patch(Object.prototype, {
/**
* Strips an object down to only the keys specified. Optionally, any
* accessors can be made to retain their context on the source object.
* This is a passthrough to the static {@link Object.stripTo} function
*
* @param {Array<string|symbol>} keys the keys that should appear in the
* final reduced object
* @param {boolean} [bindAccessors = true] if this value is true then any
* accessors from the source object will continue to have their `this`
* value bound to the source. If the getter or setter on that object is
* defined using an arrow function, this will not work as intended.
* @returns {object} an object containing only the keys and symbols
* specified in the `keys` parameter.
*/
stripTo(keys, bindAccessors = true) {
return Object.stripTo(this, keys, bindAccessors);
}
[Patch.kMutablyHidden](store) {
return {
/**
* Checks to see if the supplied `value` is both an object, and has the
* appropriate symbol defined.
*
* @param {any} value the value to determine if it contains a defined
* `Symbol.toStringTag` defined.
* @returns true if the symbol is defined, false otherwise
*/
get hasStringTag() {
return staticPatches.hasStringTag(this);
},
/**
* Retrieves the string tag of an object. The string tag is a representation
* of the object's type, as defined by its `Object.prototype.toString`
* method. This utility method is helpful for getting a more descriptive
* type of an object than what is returned by the `typeof` operator,
* especially for custom objects.
*
* @param {*} value - The object whose string tag is to be retrieved.
* @param {boolean} strict - if this is set to true, undefined will be
* returned whenever a supplied object does not have a
* `Symbol.toStringTag` defined, period. if false, the default,
* @returns {string} - The string tag of the object, indicating its type.
*/
getStringTag(strict = false) {
return staticPatches.getStringTag(this, strict);
},
/**
* Strips an object down to only the keys specified. Optionally, any
* accessors can be made to retain their context on the source object.
* This is a passthrough to the static {@link Object.stripTo} function
*
* @param {Array<string|symbol>} keys the keys that should appear in the
* final reduced object
* @param {boolean} [bindAccessors = true] if this value is true then any
* accessors from the source object will continue to have their `this`
* value bound to the source. If the getter or setter on that object is
* defined using an arrow function, this will not work as intended.
* @returns {object} an object containing only the keys and symbols
* specified in the `keys` parameter.
*/
stripTo(keys, bindAccessors = true) {
return Object.stripTo(this, keys, bindAccessors);
}
};
},
});
//# sourceMappingURL=objectextensions.js.map
import { Patch } from '@nejs/extension';
export const SetPrototypeExtensions = new Patch(Set.prototype, {
/**
* Merges multiple iterables into the set. Each element from the iterables
* is added to the set, ensuring uniqueness of all elements. This method
* mutates the original set.
*
* @param {...Iterable} iterables - One or more iterable objects (like Set
* or Array) whose elements will be added to the set.
*/
concat(...iterables) {
for (const iterable of iterables) {
if (typeof iterable === 'string' ||
!Reflect.has(iterable, Symbol.iterator)) {
this.add(iterable);
continue;
[Patch.kMutablyHidden]: {
/**
* Merges multiple iterables into the set. Each element from the iterables
* is added to the set, ensuring uniqueness of all elements. This method
* mutates the original set.
*
* @param {...Iterable} iterables - One or more iterable objects (like Set
* or Array) whose elements will be added to the set.
*/
concat(...iterables) {
for (const iterable of iterables) {
if (typeof iterable === 'string' ||
!Reflect.has(iterable, Symbol.iterator)) {
this.add(iterable);
continue;
}
for (const element of iterable) {
this.add(element);
}
}
for (const element of iterable) {
this.add(element);
},
/**
* Checks to see if any value within the `Set` loosely equals the supplied
* value.
*
* @param {*} value any value that might be loosely equal to an item in the
* set, as opposed to {@link Set.has} which is the equivalent of a strict or
* triple equals (`===`) check
* @returns {boolean} `true` if any value within the set is loosely equal to
* the supplied value, `false` otherwise
*/
contains(value) {
for (const element of this) {
if (value == element) {
return true;
}
}
}
},
/**
* Checks to see if any value within the `Set` loosely equals the supplied
* value.
*
* @param {*} value any value that might be loosely equal to an item in the
* set, as opposed to {@link Set.has} which is the equivalent of a strict or
* triple equals (`===`) check
* @returns {boolean} `true` if any value within the set is loosely equal to
* the supplied value, `false` otherwise
*/
contains(value) {
for (const element of this) {
if (value == element) {
return true;
return false;
},
/**
* Checks if every element in the set passes the test implemented by the
* provided function. The function is called with each element of the set.
* Note: Since sets do not have indices, the index parameter is always NaN.
*
* @param {Function} everyFn - The function to test each element. Receives
* the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `everyFn`.
* @throws {TypeError} If `everyFn` is not a function.
* @returns {boolean} True if every element passes the test, false otherwise.
*/
every(everyFn, thisArg) {
if (typeof everyFn !== 'function') {
throw new TypeError(`everyFn must be a function! Received ${String(everyFn)}`);
}
}
return false;
},
/**
* Checks if every element in the set passes the test implemented by the
* provided function. The function is called with each element of the set.
* Note: Since sets do not have indices, the index parameter is always NaN.
*
* @param {Function} everyFn - The function to test each element. Receives
* the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `everyFn`.
* @throws {TypeError} If `everyFn` is not a function.
* @returns {boolean} True if every element passes the test, false otherwise.
*/
every(everyFn, thisArg) {
if (typeof everyFn !== 'function') {
throw new TypeError(`everyFn must be a function! Received ${String(everyFn)}`);
}
let found = 0;
for (const element of this) {
if (everyFn.call(thisArg, element, NaN, this)) {
found++;
let found = 0;
for (const element of this) {
if (everyFn.call(thisArg, element, NaN, this)) {
found++;
}
}
}
return (found === this.size);
},
/**
* Finds the first element in the set satisfying the provided testing
* function. If no elements satisfy the testing function, undefined is
* returned. The function is called with each element of the set.
* Note: Since sets do not have indices, the index parameter is always NaN.
*
* @param {Function} findFn - The function to execute on each element. It
* receives the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `findFn`.
* @throws {TypeError} If `findFn` is not a function.
* @returns {*} The first element that satisfies `findFn`, or undefined.
*/
find(findFn, thisArg) {
if (typeof findFn !== 'function') {
throw new TypeError(`findFn must be a function! Received ${String(findFn)}`);
}
for (const element of this) {
const match = findFn.call(thisArg, element, NaN, this);
if (match) {
return element;
return (found === this.size);
},
/**
* Finds the first element in the set satisfying the provided testing
* function. If no elements satisfy the testing function, undefined is
* returned. The function is called with each element of the set.
* Note: Since sets do not have indices, the index parameter is always NaN.
*
* @param {Function} findFn - The function to execute on each element. It
* receives the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `findFn`.
* @throws {TypeError} If `findFn` is not a function.
* @returns {*} The first element that satisfies `findFn`, or undefined.
*/
find(findFn, thisArg) {
if (typeof findFn !== 'function') {
throw new TypeError(`findFn must be a function! Received ${String(findFn)}`);
}
}
return undefined;
},
/**
* Finds the last element in the set satisfying the provided testing function.
* If no elements satisfy the testing function, undefined is returned. The
* function is called with each element of the set in reverse order.
* Note: Since sets do not have indices, the index parameter is always NaN.
*
* @param {Function} findFn - The function to execute on each element. It
* receives the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `findFn`.
* @throws {TypeError} If `findFn` is not a function.
* @returns {*} The last element that satisfies `findFn`, or undefined.
*/
findLast(findFn, thisArg) {
if (typeof findFn !== 'function') {
throw new TypeError(`findFn must be a function! Received ${String(findFn)}`);
}
const found = [];
for (const element of this) {
const match = findFn.call(thisArg, element, NaN, this);
if (match) {
found.push(element);
for (const element of this) {
const match = findFn.call(thisArg, element, NaN, this);
if (match) {
return element;
}
}
}
if (found.length) {
return found[found.length - 1];
}
return undefined;
},
/**
* A getter property that returns the number of elements in the set.
* This is an alias for the `size` property of the set.
*
* @returns {number} The number of elements in the set.
*/
get length() {
return this.size;
},
/**
* Creates a new array populated with the results of calling the provided
* function on every element in the set. The function is called with each
* element of the set. Note: Since sets do not have indices, the index
* parameter is always NaN.
*
* @param {Function} mapFn - The function to execute on each element. It
* receives the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `mapFn`.
* @throws {TypeError} If `mapFn` is not a function.
* @returns {Array} A new array with each element being the result of the
* `mapFn`.
*/
map(mapFn, thisArg) {
if (typeof mapFn !== 'function') {
throw new TypeError(`mapFn must be a function! Received ${String(mapFn)}`);
}
const transformed = [];
for (const element of this) {
transformed.push(mapFn.call(thisArg, element, NaN, this));
}
return transformed;
},
/**
* Applies a function against an accumulator and each element in the set to
* reduce it to a single value. The function is called with each element of
* the set. Note: Since sets do not have indices, the index parameter is
* always NaN.
*
* @param {Function} reduceFn - The function to execute on each element. It
* receives the accumulator, element, index (always NaN), and the set itself.
* @param {*} initialValue - The initial value to start reducing from.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `reduceFn`.
* @throws {TypeError} If `reduceFn` is not a function.
* @returns {*} The reduced value.
*/
reduce(reduceFn, initialValue, thisArg) {
if (typeof reduceFn !== 'function') {
throw new TypeError(`reduceFn must be a Function! Received ${String(reduceFn)}`);
}
let accumulator = initialValue;
for (const element of this) {
accumulator = reduceFn.call(thisArg, accumulator, element, NaN, this);
}
return accumulator;
},
/**
* Tests whether at least one element in the set passes the test implemented
* by the provided function. The function is called with each element of the
* set. Note: Since sets do not have indices, the index parameter is always NaN.
*
* @param {Function} someFn - The function to test each element. It receives
* the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `someFn`.
* @throws {TypeError} If `someFn` is not a function.
* @returns {boolean} True if at least one element passes the test, false
* otherwise.
*/
some(someFn, thisArg) {
if (typeof someFn !== 'function') {
throw new TypeError(`someFn must be a function! Received ${String(someFn)}`);
}
for (const element of this) {
if (someFn.call(thisArg, element, NaN, this)) {
return true;
return undefined;
},
/**
* Finds the last element in the set satisfying the provided testing function.
* If no elements satisfy the testing function, undefined is returned. The
* function is called with each element of the set in reverse order.
* Note: Since sets do not have indices, the index parameter is always NaN.
*
* @param {Function} findFn - The function to execute on each element. It
* receives the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `findFn`.
* @throws {TypeError} If `findFn` is not a function.
* @returns {*} The last element that satisfies `findFn`, or undefined.
*/
findLast(findFn, thisArg) {
if (typeof findFn !== 'function') {
throw new TypeError(`findFn must be a function! Received ${String(findFn)}`);
}
}
return false;
const found = [];
for (const element of this) {
const match = findFn.call(thisArg, element, NaN, this);
if (match) {
found.push(element);
}
}
if (found.length) {
return found[found.length - 1];
}
return undefined;
},
/**
* A getter property that returns the number of elements in the set.
* This is an alias for the `size` property of the set.
*
* @returns {number} The number of elements in the set.
*/
get length() {
return this.size;
},
/**
* Creates a new array populated with the results of calling the provided
* function on every element in the set. The function is called with each
* element of the set. Note: Since sets do not have indices, the index
* parameter is always NaN.
*
* @param {Function} mapFn - The function to execute on each element. It
* receives the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `mapFn`.
* @throws {TypeError} If `mapFn` is not a function.
* @returns {Array} A new array with each element being the result of the
* `mapFn`.
*/
map(mapFn, thisArg) {
if (typeof mapFn !== 'function') {
throw new TypeError(`mapFn must be a function! Received ${String(mapFn)}`);
}
const transformed = [];
for (const element of this) {
transformed.push(mapFn.call(thisArg, element, NaN, this));
}
return transformed;
},
/**
* Applies a function against an accumulator and each element in the set to
* reduce it to a single value. The function is called with each element of
* the set. Note: Since sets do not have indices, the index parameter is
* always NaN.
*
* @param {Function} reduceFn - The function to execute on each element. It
* receives the accumulator, element, index (always NaN), and the set itself.
* @param {*} initialValue - The initial value to start reducing from.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `reduceFn`.
* @throws {TypeError} If `reduceFn` is not a function.
* @returns {*} The reduced value.
*/
reduce(reduceFn, initialValue, thisArg) {
if (typeof reduceFn !== 'function') {
throw new TypeError(`reduceFn must be a Function! Received ${String(reduceFn)}`);
}
let accumulator = initialValue;
for (const element of this) {
accumulator = reduceFn.call(thisArg, accumulator, element, NaN, this);
}
return accumulator;
},
/**
* Tests whether at least one element in the set passes the test implemented
* by the provided function. The function is called with each element of the
* set. Note: Since sets do not have indices, the index parameter is always NaN.
*
* @param {Function} someFn - The function to test each element. It receives
* the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `someFn`.
* @throws {TypeError} If `someFn` is not a function.
* @returns {boolean} True if at least one element passes the test, false
* otherwise.
*/
some(someFn, thisArg) {
if (typeof someFn !== 'function') {
throw new TypeError(`someFn must be a function! Received ${String(someFn)}`);
}
for (const element of this) {
if (someFn.call(thisArg, element, NaN, this)) {
return true;
}
}
return false;
},
},
});
//# sourceMappingURL=setextensions.js.map

@@ -82,73 +82,75 @@ import { Patch } from '@nejs/extension';

export const StringPrototypeExtensions = new Patch(String.prototype, {
/**
* Extracts a substring from the current string, starting at a given offset
* and bounded by specified opening and closing tokens. This method is
* particularly useful for parsing nested structures or quoted strings,
* where the level of nesting or the presence of escape characters must
* be considered.
*
* @param {number} offset The position in the string from which to start the
* search for the substring.
* @param {[string, string]} tokens An array containing two strings: the
* opening and closing tokens that define the boundaries of the substring
* to be extracted.
* @returns {Object} An object with two properties: `extracted`, the
* extracted substring, and `newOffset`, the position in the original
* string immediately after the end of the extracted substring. If no
* substring is found, `extracted` is `null` and `newOffset` is the same
* as the input offset.
*/
extractSubstring(offset = 0, tokens = parenthesisPair) {
let [openToken, closeToken] = tokens;
let depth = 0;
let start = -1;
let end = -1;
let leadingToken = '';
let firstToken = 0;
for (let i = offset; i < this.length; i++) {
const char = this[i];
if (char === openToken) {
depth++;
if (start === -1)
start = i;
}
else if (char === closeToken) {
depth--;
if (depth === 0) {
end = i;
break;
[Patch.kMutablyHidden]: {
/**
* Extracts a substring from the current string, starting at a given offset
* and bounded by specified opening and closing tokens. This method is
* particularly useful for parsing nested structures or quoted strings,
* where the level of nesting or the presence of escape characters must
* be considered.
*
* @param {number} offset The position in the string from which to start the
* search for the substring.
* @param {[string, string]} tokens An array containing two strings: the
* opening and closing tokens that define the boundaries of the substring
* to be extracted.
* @returns {Object} An object with two properties: `extracted`, the
* extracted substring, and `newOffset`, the position in the original
* string immediately after the end of the extracted substring. If no
* substring is found, `extracted` is `null` and `newOffset` is the same
* as the input offset.
*/
extractSubstring(offset = 0, tokens = parenthesisPair) {
let [openToken, closeToken] = tokens;
let depth = 0;
let start = -1;
let end = -1;
let leadingToken = '';
let firstToken = 0;
for (let i = offset; i < this.length; i++) {
const char = this[i];
if (char === openToken) {
depth++;
if (start === -1)
start = i;
}
else if (char === closeToken) {
depth--;
if (depth === 0) {
end = i;
break;
}
}
}
}
let lRange = [
Math.max(0, start - 100),
start
];
let leading = [...this.substring(lRange[0], lRange[1])].reverse().join('');
let reversedLeadingToken;
try {
reversedLeadingToken = /([^ \,\"\'\`]+)/.exec(leading)[1] ?? '';
leadingToken = [...reversedLeadingToken].reverse().join('');
}
catch (ignored) { }
if (start !== -1 && end !== -1) {
const sliceRange = [start, end + 1];
const extracted = this.slice(sliceRange[0], sliceRange[1]);
return {
extracted,
range: [start, end],
newOffset: end + 1,
leadingToken,
};
}
else {
return {
extracted: null,
range: [start, end],
newOffset: offset,
leadingToken,
};
}
let lRange = [
Math.max(0, start - 100),
start
];
let leading = [...this.substring(lRange[0], lRange[1])].reverse().join('');
let reversedLeadingToken;
try {
reversedLeadingToken = /([^ \,\"\'\`]+)/.exec(leading)[1] ?? '';
leadingToken = [...reversedLeadingToken].reverse().join('');
}
catch (ignored) { }
if (start !== -1 && end !== -1) {
const sliceRange = [start, end + 1];
const extracted = this.slice(sliceRange[0], sliceRange[1]);
return {
extracted,
range: [start, end],
newOffset: end + 1,
leadingToken,
};
}
else {
return {
extracted: null,
range: [start, end],
newOffset: offset,
leadingToken,
};
}
},
},
});
//# sourceMappingURL=stringextensions.js.map

@@ -58,10 +58,11 @@ {

"module": "bin/build",
"test": "jest"
"test": "jest",
"repl": "npm run build && node --no-warnings repl.bootstrap.js"
},
"type": "module",
"version": "2.5.0",
"version": "2.6.0",
"dependencies": {
"@nejs/extension": "^2.8.0"
},
"browser": "dist/@nejs/basic-extensions.bundle.2.3.0.js"
"browser": "dist/@nejs/basic-extensions.bundle.2.5.0.js"
}

@@ -12,64 +12,65 @@ import { Patch } from '@nejs/extension'

export const ArrayPrototypeExtensions = new Patch(Array.prototype, {
/**
* Sometimes defining even a short function for the invocation of `find`
* can be troublesome. This helper function performs that job for you. If
* the specified element is in the array, `true` will be returned.
*
* @param {*} value the value to search for. This value must triple equals
* the array element in order to return true.
* @returns true if the exact element exists in the array, false otherwise
*/
contains(value) {
return !!this.find(entry => entry === value)
},
[Patch.kMutablyHidden]: {
/**
* Sometimes defining even a short function for the invocation of `find`
* can be troublesome. This helper function performs that job for you. If
* the specified element is in the array, `true` will be returned.
*
* @param {*} value the value to search for. This value must triple equals
* the array element in order to return true.
* @returns true if the exact element exists in the array, false otherwise
*/
contains(value) {
return !!this.find(entry => entry === value)
},
/**
* The `findEntry` function searches the entries of the object and returns
* the `[index, value]` entry array for the first matching value found.
*
* @param {function} findFn a function that takes the element to be checked
* and returns a boolean value
* @returns if `findFn` returns `true`, an array with two elements, the first
* being the index, the second being the value, is returned.
*/
findEntry(findFn) {
const entries = this.entries()
const VALUE = 1
/**
* The `findEntry` function searches the entries of the object and returns
* the `[index, value]` entry array for the first matching value found.
*
* @param {function} findFn a function that takes the element to be checked
* and returns a boolean value
* @returns if `findFn` returns `true`, an array with two elements, the first
* being the index, the second being the value, is returned.
*/
findEntry(findFn) {
const entries = this.entries()
const VALUE = 1
for (let entry of entries) {
if (findFn(entry[VALUE])) {
return entry
for (let entry of entries) {
if (findFn(entry[VALUE])) {
return entry
}
}
}
return undefined
},
return undefined
},
/**
* A getter property that returns the first element of the array. If the
* array is empty, it returns `undefined`. This property is useful for
* scenarios where you need to quickly access the first item of an array
* without the need for additional checks or method calls.
*
* @returns {*} The first element of the array or `undefined` if the array
* is empty.
*/
get first() {
return this[0];
},
/**
* A getter property that returns the first element of the array. If the
* array is empty, it returns `undefined`. This property is useful for
* scenarios where you need to quickly access the first item of an array
* without the need for additional checks or method calls.
*
* @returns {*} The first element of the array or `undefined` if the array
* is empty.
*/
get first() {
return this[0];
},
/**
* A getter property that returns the last element of the array. It
* calculates the last index based on the array's length. If the array is
* empty, it returns `undefined`. This property is beneficial when you need
* to access the last item in an array, improving code readability and
* avoiding manual index calculation.
*
* @returns {*} The last element of the array or `undefined` if the
* array is empty.
*/
get last() {
return this[this.length - 1];
/**
* A getter property that returns the last element of the array. It
* calculates the last index based on the array's length. If the array is
* empty, it returns `undefined`. This property is beneficial when you need
* to access the last item in an array, improving code readability and
* avoiding manual index calculation.
*
* @returns {*} The last element of the array or `undefined` if the
* array is empty.
*/
get last() {
return this[this.length - 1];
},
},
})

@@ -137,88 +137,90 @@ import { Patch } from '@nejs/extension'

export const FunctionPrototypeExtensions = new Patch(Function.prototype, {
/**
* Determines if a given value is an asynchronous function. It checks if the
* value is an instance of `Function` and if its string representation
* includes the keyword 'Async'. This method is particularly useful for
* identifying async functions.
*
* @returns {boolean} Returns `true` if the value is an async function,
* otherwise `false`.
*/
get isAsync() {
return Function.isAsync(this)
},
[Patch.kMutablyHidden]: {
/**
* Determines if a given value is an asynchronous function. It checks if the
* value is an instance of `Function` and if its string representation
* includes the keyword 'Async'. This method is particularly useful for
* identifying async functions.
*
* @returns {boolean} Returns `true` if the value is an async function,
* otherwise `false`.
*/
get isAsync() {
return Function.isAsync(this)
},
/**
* The function checks if a given value is an async generator function
*
* @returns {boolean} `true` if the value is an instance of a function and
* its string tag is 'AsyncGeneratorFunction', otherwise it returns `false`.
*/
get isAsyncGenerator() {
return Function.isAsyncGenerator(this)
},
/**
* The function checks if a given value is an async generator function
*
* @returns {boolean} `true` if the value is an instance of a function and
* its string tag is 'AsyncGeneratorFunction', otherwise it returns `false`.
*/
get isAsyncGenerator() {
return Function.isAsyncGenerator(this)
},
/**
* Checks if a given value is an arrow function. It verifies if the value is
* an instance of `Function`, if its string representation includes the '=>'
* symbol, and if it lacks a prototype, which is a characteristic of arrow
* functions in JavaScript.
*
* @returns {boolean} Returns `true` if the value is an arrow function,
* otherwise `false`.
*/
get isBigArrow() {
return Function.isBigArrow(this)
},
/**
* Checks if a given value is an arrow function. It verifies if the value is
* an instance of `Function`, if its string representation includes the '=>'
* symbol, and if it lacks a prototype, which is a characteristic of arrow
* functions in JavaScript.
*
* @returns {boolean} Returns `true` if the value is an arrow function,
* otherwise `false`.
*/
get isBigArrow() {
return Function.isBigArrow(this)
},
/**
* Determines if a given value is a bound function. Bound functions are
* created using the `Function.prototype.bind` method, which allows setting
* the `this` value at the time of binding. This method checks if the value
* is an instance of `Function`, if its string representation starts with
* 'bound', and if it lacks a `prototype` property. These characteristics
* are indicative of bound functions in JavaScript.
*
* @returns {boolean} Returns `true` if the value is a bound function,
* otherwise `false`. Bound functions have a specific format in their
* string representation and do not have their own `prototype` property.
*/
get isBound() {
return Function.isBound(this)
},
/**
* Determines if a given value is a bound function. Bound functions are
* created using the `Function.prototype.bind` method, which allows setting
* the `this` value at the time of binding. This method checks if the value
* is an instance of `Function`, if its string representation starts with
* 'bound', and if it lacks a `prototype` property. These characteristics
* are indicative of bound functions in JavaScript.
*
* @returns {boolean} Returns `true` if the value is a bound function,
* otherwise `false`. Bound functions have a specific format in their
* string representation and do not have their own `prototype` property.
*/
get isBound() {
return Function.isBound(this)
},
/**
* Determines if a given value is a class. It checks if the value is an
* instance of `Function` and if its string representation includes the
* keyword 'class'. This method is useful for distinguishing classes from
* other function types in JavaScript.
*
* @returns {boolean} Returns `true` if the value is a class, otherwise
* `false`.
*/
get isClass() {
return Function.isClass(this)
},
/**
* Determines if a given value is a class. It checks if the value is an
* instance of `Function` and if its string representation includes the
* keyword 'class'. This method is useful for distinguishing classes from
* other function types in JavaScript.
*
* @returns {boolean} Returns `true` if the value is a class, otherwise
* `false`.
*/
get isClass() {
return Function.isClass(this)
},
/**
* Checks if a given value is a regular function. This method verifies if
* the value is an instance of `Function`, which includes regular functions,
* classes, and async functions but excludes arrow functions.
*
* @returns {boolean} Returns `true` if the value is a regular function,
* otherwise `false`.
*/
get isFunction() {
return Function.isFunction(this)
},
/**
* Checks if a given value is a regular function. This method verifies if
* the value is an instance of `Function`, which includes regular functions,
* classes, and async functions but excludes arrow functions.
*
* @returns {boolean} Returns `true` if the value is a regular function,
* otherwise `false`.
*/
get isFunction() {
return Function.isFunction(this)
},
/**
* The function checks if a given value is a generator function
*
* @returns {boolean} `true` if the value is an instance of a function and
* its string tag is 'GeneratorFunction', otherwise it returns `false`.
*/
get isGenerator() {
return Function.isGenerator(this)
/**
* The function checks if a given value is a generator function
*
* @returns {boolean} `true` if the value is an instance of a function and
* its string tag is 'GeneratorFunction', otherwise it returns `false`.
*/
get isGenerator() {
return Function.isGenerator(this)
},
},
})
import { Patch } from '@nejs/extension';
export const MapPrototypeExtensions = new Patch(Map.prototype, {
/**
* The function `getKey` returns the key associated with a given value
* in a map.
*
* @param {any} value - The value parameter is the value that you want to
* find the corresponding key for in the map.
* @param [strict=true] - The "strict" parameter is a boolean value that
* determines whether strict equality (===) or loose equality (==) should
* be used when comparing the "value" parameter with the values in the
* entries of the object. If "strict" is set to true, strict equality will
* be used.
* @returns the key associated with the given value. If a matching key is
* found, it is returned. If no matching key is found, null is returned.
*/
getKey(value, strict = true) {
for (const [key, entryValue] of this) {
if (
(strict && value === entryValue) &&
(!strict && value == entryValue)
) {
return key
[Patch.kMutablyHidden]: {
/**
* The function `getKey` returns the key associated with a given value
* in a map.
*
* @param {any} value - The value parameter is the value that you want to
* find the corresponding key for in the map.
* @param [strict=true] - The "strict" parameter is a boolean value that
* determines whether strict equality (===) or loose equality (==) should
* be used when comparing the "value" parameter with the values in the
* entries of the object. If "strict" is set to true, strict equality will
* be used.
* @returns the key associated with the given value. If a matching key is
* found, it is returned. If no matching key is found, null is returned.
*/
getKey(value, strict = true) {
for (const [key, entryValue] of this) {
if (
(strict && value === entryValue) &&
(!strict && value == entryValue)
) {
return key
}
return null
}
return null
}
},
},
})

@@ -203,20 +203,55 @@ import { Patch } from '@nejs/extension';

const staticPatches = ObjectExtensions.patches;
export const ObjectPrototypeExtensions = new Patch(Object.prototype, {
/**
* Strips an object down to only the keys specified. Optionally, any
* accessors can be made to retain their context on the source object.
* This is a passthrough to the static {@link Object.stripTo} function
*
* @param {Array<string|symbol>} keys the keys that should appear in the
* final reduced object
* @param {boolean} [bindAccessors = true] if this value is true then any
* accessors from the source object will continue to have their `this`
* value bound to the source. If the getter or setter on that object is
* defined using an arrow function, this will not work as intended.
* @returns {object} an object containing only the keys and symbols
* specified in the `keys` parameter.
*/
stripTo(keys, bindAccessors = true) {
return Object.stripTo(this, keys, bindAccessors)
}
[Patch.kMutablyHidden](store) {
return {
/**
* Checks to see if the supplied `value` is both an object, and has the
* appropriate symbol defined.
*
* @param {any} value the value to determine if it contains a defined
* `Symbol.toStringTag` defined.
* @returns true if the symbol is defined, false otherwise
*/
get hasStringTag() {
return staticPatches.hasStringTag(this)
},
/**
* Retrieves the string tag of an object. The string tag is a representation
* of the object's type, as defined by its `Object.prototype.toString`
* method. This utility method is helpful for getting a more descriptive
* type of an object than what is returned by the `typeof` operator,
* especially for custom objects.
*
* @param {*} value - The object whose string tag is to be retrieved.
* @param {boolean} strict - if this is set to true, undefined will be
* returned whenever a supplied object does not have a
* `Symbol.toStringTag` defined, period. if false, the default,
* @returns {string} - The string tag of the object, indicating its type.
*/
getStringTag(strict = false) {
return staticPatches.getStringTag(this, strict)
},
/**
* Strips an object down to only the keys specified. Optionally, any
* accessors can be made to retain their context on the source object.
* This is a passthrough to the static {@link Object.stripTo} function
*
* @param {Array<string|symbol>} keys the keys that should appear in the
* final reduced object
* @param {boolean} [bindAccessors = true] if this value is true then any
* accessors from the source object will continue to have their `this`
* value bound to the source. If the getter or setter on that object is
* defined using an arrow function, this will not work as intended.
* @returns {object} an object containing only the keys and symbols
* specified in the `keys` parameter.
*/
stripTo(keys, bindAccessors = true) {
return Object.stripTo(this, keys, bindAccessors)
}
}
},
})
import { Patch } from '@nejs/extension';
export const SetPrototypeExtensions = new Patch(Set.prototype, {
/**
* Merges multiple iterables into the set. Each element from the iterables
* is added to the set, ensuring uniqueness of all elements. This method
* mutates the original set.
*
* @param {...Iterable} iterables - One or more iterable objects (like Set
* or Array) whose elements will be added to the set.
*/
concat(...iterables) {
for (const iterable of iterables) {
if (
typeof iterable === 'string' ||
!Reflect.has(iterable, Symbol.iterator)
) {
this.add(iterable)
continue
}
[Patch.kMutablyHidden]: {
/**
* Merges multiple iterables into the set. Each element from the iterables
* is added to the set, ensuring uniqueness of all elements. This method
* mutates the original set.
*
* @param {...Iterable} iterables - One or more iterable objects (like Set
* or Array) whose elements will be added to the set.
*/
concat(...iterables) {
for (const iterable of iterables) {
if (
typeof iterable === 'string' ||
!Reflect.has(iterable, Symbol.iterator)
) {
this.add(iterable)
continue
}
for (const element of iterable) {
this.add(element)
for (const element of iterable) {
this.add(element)
}
}
}
},
},
/**
* Checks to see if any value within the `Set` loosely equals the supplied
* value.
*
* @param {*} value any value that might be loosely equal to an item in the
* set, as opposed to {@link Set.has} which is the equivalent of a strict or
* triple equals (`===`) check
* @returns {boolean} `true` if any value within the set is loosely equal to
* the supplied value, `false` otherwise
*/
contains(value) {
for (const element of this) {
if (value == element) {
return true
/**
* Checks to see if any value within the `Set` loosely equals the supplied
* value.
*
* @param {*} value any value that might be loosely equal to an item in the
* set, as opposed to {@link Set.has} which is the equivalent of a strict or
* triple equals (`===`) check
* @returns {boolean} `true` if any value within the set is loosely equal to
* the supplied value, `false` otherwise
*/
contains(value) {
for (const element of this) {
if (value == element) {
return true
}
}
}
return false
},
return false
},
/**
* Checks if every element in the set passes the test implemented by the
* provided function. The function is called with each element of the set.
* Note: Since sets do not have indices, the index parameter is always NaN.
*
* @param {Function} everyFn - The function to test each element. Receives
* the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `everyFn`.
* @throws {TypeError} If `everyFn` is not a function.
* @returns {boolean} True if every element passes the test, false otherwise.
*/
every(everyFn, thisArg) {
if (typeof everyFn !== 'function') {
throw new TypeError(
`everyFn must be a function! Received ${String(everyFn)}`
)
}
/**
* Checks if every element in the set passes the test implemented by the
* provided function. The function is called with each element of the set.
* Note: Since sets do not have indices, the index parameter is always NaN.
*
* @param {Function} everyFn - The function to test each element. Receives
* the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `everyFn`.
* @throws {TypeError} If `everyFn` is not a function.
* @returns {boolean} True if every element passes the test, false otherwise.
*/
every(everyFn, thisArg) {
if (typeof everyFn !== 'function') {
throw new TypeError(
`everyFn must be a function! Received ${String(everyFn)}`
)
}
let found = 0
let found = 0
for (const element of this) {
if (everyFn.call(thisArg, element, NaN, this)) {
found++
for (const element of this) {
if (everyFn.call(thisArg, element, NaN, this)) {
found++
}
}
}
return (found === this.size)
},
return (found === this.size)
},
/**
* Finds the first element in the set satisfying the provided testing
* function. If no elements satisfy the testing function, undefined is
* returned. The function is called with each element of the set.
* Note: Since sets do not have indices, the index parameter is always NaN.
*
* @param {Function} findFn - The function to execute on each element. It
* receives the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `findFn`.
* @throws {TypeError} If `findFn` is not a function.
* @returns {*} The first element that satisfies `findFn`, or undefined.
*/
find(findFn, thisArg) {
if (typeof findFn !== 'function') {
throw new TypeError(
`findFn must be a function! Received ${String(findFn)}`
)
}
/**
* Finds the first element in the set satisfying the provided testing
* function. If no elements satisfy the testing function, undefined is
* returned. The function is called with each element of the set.
* Note: Since sets do not have indices, the index parameter is always NaN.
*
* @param {Function} findFn - The function to execute on each element. It
* receives the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `findFn`.
* @throws {TypeError} If `findFn` is not a function.
* @returns {*} The first element that satisfies `findFn`, or undefined.
*/
find(findFn, thisArg) {
if (typeof findFn !== 'function') {
throw new TypeError(
`findFn must be a function! Received ${String(findFn)}`
)
}
for (const element of this) {
const match = findFn.call(thisArg, element, NaN, this)
if (match) {
return element
for (const element of this) {
const match = findFn.call(thisArg, element, NaN, this)
if (match) {
return element
}
}
}
return undefined
},
return undefined
},
/**
* Finds the last element in the set satisfying the provided testing function.
* If no elements satisfy the testing function, undefined is returned. The
* function is called with each element of the set in reverse order.
* Note: Since sets do not have indices, the index parameter is always NaN.
*
* @param {Function} findFn - The function to execute on each element. It
* receives the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `findFn`.
* @throws {TypeError} If `findFn` is not a function.
* @returns {*} The last element that satisfies `findFn`, or undefined.
*/
findLast(findFn, thisArg) {
if (typeof findFn !== 'function') {
throw new TypeError(
`findFn must be a function! Received ${String(findFn)}`
)
}
/**
* Finds the last element in the set satisfying the provided testing function.
* If no elements satisfy the testing function, undefined is returned. The
* function is called with each element of the set in reverse order.
* Note: Since sets do not have indices, the index parameter is always NaN.
*
* @param {Function} findFn - The function to execute on each element. It
* receives the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `findFn`.
* @throws {TypeError} If `findFn` is not a function.
* @returns {*} The last element that satisfies `findFn`, or undefined.
*/
findLast(findFn, thisArg) {
if (typeof findFn !== 'function') {
throw new TypeError(
`findFn must be a function! Received ${String(findFn)}`
)
}
const found = []
const found = []
for (const element of this) {
const match = findFn.call(thisArg, element, NaN, this)
if (match) {
found.push(element)
for (const element of this) {
const match = findFn.call(thisArg, element, NaN, this)
if (match) {
found.push(element)
}
}
}
if (found.length) {
return found[found.length - 1]
}
if (found.length) {
return found[found.length - 1]
}
return undefined
},
return undefined
},
/**
* A getter property that returns the number of elements in the set.
* This is an alias for the `size` property of the set.
*
* @returns {number} The number of elements in the set.
*/
get length() {
return this.size
},
/**
* A getter property that returns the number of elements in the set.
* This is an alias for the `size` property of the set.
*
* @returns {number} The number of elements in the set.
*/
get length() {
return this.size
},
/**
* Creates a new array populated with the results of calling the provided
* function on every element in the set. The function is called with each
* element of the set. Note: Since sets do not have indices, the index
* parameter is always NaN.
*
* @param {Function} mapFn - The function to execute on each element. It
* receives the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `mapFn`.
* @throws {TypeError} If `mapFn` is not a function.
* @returns {Array} A new array with each element being the result of the
* `mapFn`.
*/
map(mapFn, thisArg) {
if (typeof mapFn !== 'function') {
throw new TypeError(
`mapFn must be a function! Received ${String(mapFn)}`
)
}
/**
* Creates a new array populated with the results of calling the provided
* function on every element in the set. The function is called with each
* element of the set. Note: Since sets do not have indices, the index
* parameter is always NaN.
*
* @param {Function} mapFn - The function to execute on each element. It
* receives the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `mapFn`.
* @throws {TypeError} If `mapFn` is not a function.
* @returns {Array} A new array with each element being the result of the
* `mapFn`.
*/
map(mapFn, thisArg) {
if (typeof mapFn !== 'function') {
throw new TypeError(
`mapFn must be a function! Received ${String(mapFn)}`
)
}
const transformed = []
const transformed = []
for (const element of this) {
transformed.push(mapFn.call(thisArg, element, NaN, this))
}
for (const element of this) {
transformed.push(mapFn.call(thisArg, element, NaN, this))
}
return transformed
},
return transformed
},
/**
* Applies a function against an accumulator and each element in the set to
* reduce it to a single value. The function is called with each element of
* the set. Note: Since sets do not have indices, the index parameter is
* always NaN.
*
* @param {Function} reduceFn - The function to execute on each element. It
* receives the accumulator, element, index (always NaN), and the set itself.
* @param {*} initialValue - The initial value to start reducing from.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `reduceFn`.
* @throws {TypeError} If `reduceFn` is not a function.
* @returns {*} The reduced value.
*/
reduce(reduceFn, initialValue, thisArg) {
if (typeof reduceFn !== 'function') {
throw new TypeError(
`reduceFn must be a Function! Received ${String(reduceFn)}`
)
}
/**
* Applies a function against an accumulator and each element in the set to
* reduce it to a single value. The function is called with each element of
* the set. Note: Since sets do not have indices, the index parameter is
* always NaN.
*
* @param {Function} reduceFn - The function to execute on each element. It
* receives the accumulator, element, index (always NaN), and the set itself.
* @param {*} initialValue - The initial value to start reducing from.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `reduceFn`.
* @throws {TypeError} If `reduceFn` is not a function.
* @returns {*} The reduced value.
*/
reduce(reduceFn, initialValue, thisArg) {
if (typeof reduceFn !== 'function') {
throw new TypeError(
`reduceFn must be a Function! Received ${String(reduceFn)}`
)
}
let accumulator = initialValue
for (const element of this) {
accumulator = reduceFn.call(thisArg, accumulator, element, NaN, this)
}
let accumulator = initialValue
for (const element of this) {
accumulator = reduceFn.call(thisArg, accumulator, element, NaN, this)
}
return accumulator
},
return accumulator
},
/**
* Tests whether at least one element in the set passes the test implemented
* by the provided function. The function is called with each element of the
* set. Note: Since sets do not have indices, the index parameter is always NaN.
*
* @param {Function} someFn - The function to test each element. It receives
* the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `someFn`.
* @throws {TypeError} If `someFn` is not a function.
* @returns {boolean} True if at least one element passes the test, false
* otherwise.
*/
some(someFn, thisArg) {
if (typeof someFn !== 'function') {
throw new TypeError(
`someFn must be a function! Received ${String(someFn)}`
)
}
/**
* Tests whether at least one element in the set passes the test implemented
* by the provided function. The function is called with each element of the
* set. Note: Since sets do not have indices, the index parameter is always NaN.
*
* @param {Function} someFn - The function to test each element. It receives
* the element, index (always NaN), and the set itself.
* @param {Object} [thisArg] - Optional. Value to use as `this` when executing
* `someFn`.
* @throws {TypeError} If `someFn` is not a function.
* @returns {boolean} True if at least one element passes the test, false
* otherwise.
*/
some(someFn, thisArg) {
if (typeof someFn !== 'function') {
throw new TypeError(
`someFn must be a function! Received ${String(someFn)}`
)
}
for (const element of this) {
if (someFn.call(thisArg, element, NaN, this)) {
return true
for (const element of this) {
if (someFn.call(thisArg, element, NaN, this)) {
return true
}
}
}
return false
return false
},
},
})

@@ -88,78 +88,80 @@ import { Patch } from '@nejs/extension';

export const StringPrototypeExtensions = new Patch(String.prototype, {
/**
* Extracts a substring from the current string, starting at a given offset
* and bounded by specified opening and closing tokens. This method is
* particularly useful for parsing nested structures or quoted strings,
* where the level of nesting or the presence of escape characters must
* be considered.
*
* @param {number} offset The position in the string from which to start the
* search for the substring.
* @param {[string, string]} tokens An array containing two strings: the
* opening and closing tokens that define the boundaries of the substring
* to be extracted.
* @returns {Object} An object with two properties: `extracted`, the
* extracted substring, and `newOffset`, the position in the original
* string immediately after the end of the extracted substring. If no
* substring is found, `extracted` is `null` and `newOffset` is the same
* as the input offset.
*/
extractSubstring(offset = 0, tokens = parenthesisPair) {
let [openToken, closeToken] = tokens;
let depth = 0;
let start = -1;
let end = -1;
let leadingToken = '';
let firstToken = 0;
[Patch.kMutablyHidden]: {
/**
* Extracts a substring from the current string, starting at a given offset
* and bounded by specified opening and closing tokens. This method is
* particularly useful for parsing nested structures or quoted strings,
* where the level of nesting or the presence of escape characters must
* be considered.
*
* @param {number} offset The position in the string from which to start the
* search for the substring.
* @param {[string, string]} tokens An array containing two strings: the
* opening and closing tokens that define the boundaries of the substring
* to be extracted.
* @returns {Object} An object with two properties: `extracted`, the
* extracted substring, and `newOffset`, the position in the original
* string immediately after the end of the extracted substring. If no
* substring is found, `extracted` is `null` and `newOffset` is the same
* as the input offset.
*/
extractSubstring(offset = 0, tokens = parenthesisPair) {
let [openToken, closeToken] = tokens;
let depth = 0;
let start = -1;
let end = -1;
let leadingToken = '';
let firstToken = 0;
for (let i = offset; i < this.length; i++) {
const char = this[i];
for (let i = offset; i < this.length; i++) {
const char = this[i];
if (char === openToken) {
depth++;
if (start === -1)
start = i;
}
else if (char === closeToken) {
depth--;
if (depth === 0) {
end = i;
break;
if (char === openToken) {
depth++;
if (start === -1)
start = i;
}
else if (char === closeToken) {
depth--;
if (depth === 0) {
end = i;
break;
}
}
}
}
let lRange = [
Math.max(0, start - 100),
start
];
let leading = [...this.substring(lRange[0], lRange[1])].reverse().join('')
let reversedLeadingToken;
let lRange = [
Math.max(0, start - 100),
start
];
let leading = [...this.substring(lRange[0], lRange[1])].reverse().join('')
let reversedLeadingToken;
try {
reversedLeadingToken = /([^ \,\"\'\`]+)/.exec(leading)[1] ?? '';
leadingToken = [...reversedLeadingToken].reverse().join('');
}
catch(ignored) { }
try {
reversedLeadingToken = /([^ \,\"\'\`]+)/.exec(leading)[1] ?? '';
leadingToken = [...reversedLeadingToken].reverse().join('');
}
catch(ignored) { }
if (start !== -1 && end !== -1) {
const sliceRange = [start, end + 1];
const extracted = this.slice(sliceRange[0], sliceRange[1]);
if (start !== -1 && end !== -1) {
const sliceRange = [start, end + 1];
const extracted = this.slice(sliceRange[0], sliceRange[1]);
return {
extracted,
range: [start, end],
newOffset: end + 1,
leadingToken,
};
}
else {
return {
extracted: null,
range: [start, end],
newOffset: offset,
leadingToken,
};
}
return {
extracted,
range: [start, end],
newOffset: end + 1,
leadingToken,
};
}
else {
return {
extracted: null,
range: [start, end],
newOffset: offset,
leadingToken,
};
}
},
},
})

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 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