@nejs/basic-extensions 2.4.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +151 -118
  2. package/dist/@nejs/basic-extensions.bundle.2.5.0.js +8 -0
  3. package/dist/@nejs/basic-extensions.bundle.2.5.0.js.map +7 -0
  4. package/dist/cjs/arrayextensions.js +56 -54
  5. package/dist/cjs/arrayextensions.js.map +1 -1
  6. package/dist/cjs/functionextensions.js +81 -79
  7. package/dist/cjs/functionextensions.js.map +1 -1
  8. package/dist/cjs/mapextensions.js +23 -21
  9. package/dist/cjs/mapextensions.js.map +1 -1
  10. package/dist/cjs/objectextensions.js +49 -17
  11. package/dist/cjs/objectextensions.js.map +1 -1
  12. package/dist/cjs/setextensions.js +191 -189
  13. package/dist/cjs/setextensions.js.map +1 -1
  14. package/dist/cjs/stringextensions.js +69 -67
  15. package/dist/cjs/stringextensions.js.map +1 -1
  16. package/dist/mjs/arrayextensions.js +56 -54
  17. package/dist/mjs/arrayextensions.js.map +1 -1
  18. package/dist/mjs/functionextensions.js +81 -79
  19. package/dist/mjs/functionextensions.js.map +1 -1
  20. package/dist/mjs/mapextensions.js +23 -21
  21. package/dist/mjs/mapextensions.js.map +1 -1
  22. package/dist/mjs/objectextensions.js +49 -17
  23. package/dist/mjs/objectextensions.js.map +1 -1
  24. package/dist/mjs/setextensions.js +191 -189
  25. package/dist/mjs/setextensions.js.map +1 -1
  26. package/dist/mjs/stringextensions.js +69 -67
  27. package/dist/mjs/stringextensions.js.map +1 -1
  28. package/docs/index.html +636 -478
  29. package/package.json +5 -4
  30. package/src/arrayextensions.js +56 -55
  31. package/src/functionextensions.js +87 -85
  32. package/src/mapextensions.js +26 -24
  33. package/src/objectextensions.js +52 -17
  34. package/src/setextensions.js +216 -214
  35. package/src/stringextensions.js +69 -67
  36. package/dist/@nejs/basic-extensions.bundle.2.3.0.js +0 -8
  37. package/dist/@nejs/basic-extensions.bundle.2.3.0.js.map +0 -7
package/package.json CHANGED
@@ -55,12 +55,13 @@
55
55
  "jsdoc": "jsdoc -c jsdoc-config.json -p -a all -R README.md",
56
56
  "documentation": "documentation build src/** -f html --github -o docs && documentation readme src/index.js --section=API",
57
57
  "module": "bin/build",
58
- "test": "jest"
58
+ "test": "jest",
59
+ "repl": "npm run build && node --no-warnings repl.bootstrap.js"
59
60
  },
60
61
  "type": "module",
61
- "version": "2.4.0",
62
+ "version": "2.6.0",
62
63
  "dependencies": {
63
- "@nejs/extension": "^2.7.2"
64
+ "@nejs/extension": "^2.8.0"
64
65
  },
65
- "browser": "dist/@nejs/basic-extensions.bundle.2.3.0.js"
66
+ "browser": "dist/@nejs/basic-extensions.bundle.2.5.0.js"
66
67
  }
@@ -9,66 +9,67 @@ import { Patch } from '@nejs/extension'
9
9
  * operations on arrays and makes code more expressive and concise.
10
10
  */
11
11
  export const ArrayPrototypeExtensions = new Patch(Array.prototype, {
12
- /**
13
- * Sometimes defining even a short function for the invocation of `find`
14
- * can be troublesome. This helper function performs that job for you. If
15
- * the specified element is in the array, `true` will be returned.
16
- *
17
- * @param {*} value the value to search for. This value must triple equals
18
- * the array element in order to return true.
19
- * @returns true if the exact element exists in the array, false otherwise
20
- */
21
- contains(value) {
22
- return !!this.find(entry => entry === value)
23
- },
12
+ [Patch.kMutablyHidden]: {
13
+ /**
14
+ * Sometimes defining even a short function for the invocation of `find`
15
+ * can be troublesome. This helper function performs that job for you. If
16
+ * the specified element is in the array, `true` will be returned.
17
+ *
18
+ * @param {*} value the value to search for. This value must triple equals
19
+ * the array element in order to return true.
20
+ * @returns true if the exact element exists in the array, false otherwise
21
+ */
22
+ contains(value) {
23
+ return !!this.find(entry => entry === value)
24
+ },
24
25
 
25
- /**
26
- * The `findEntry` function searches the entries of the object and returns
27
- * the `[index, value]` entry array for the first matching value found.
28
- *
29
- * @param {function} findFn a function that takes the element to be checked
30
- * and returns a boolean value
31
- * @returns if `findFn` returns `true`, an array with two elements, the first
32
- * being the index, the second being the value, is returned.
33
- */
34
- findEntry(findFn) {
35
- const entries = this.entries()
36
- const VALUE = 1
26
+ /**
27
+ * The `findEntry` function searches the entries of the object and returns
28
+ * the `[index, value]` entry array for the first matching value found.
29
+ *
30
+ * @param {function} findFn a function that takes the element to be checked
31
+ * and returns a boolean value
32
+ * @returns if `findFn` returns `true`, an array with two elements, the first
33
+ * being the index, the second being the value, is returned.
34
+ */
35
+ findEntry(findFn) {
36
+ const entries = this.entries()
37
+ const VALUE = 1
37
38
 
38
- for (let entry of entries) {
39
- if (findFn(entry[VALUE])) {
40
- return entry
39
+ for (let entry of entries) {
40
+ if (findFn(entry[VALUE])) {
41
+ return entry
42
+ }
41
43
  }
42
- }
43
44
 
44
- return undefined
45
- },
45
+ return undefined
46
+ },
46
47
 
47
- /**
48
- * A getter property that returns the first element of the array. If the
49
- * array is empty, it returns `undefined`. This property is useful for
50
- * scenarios where you need to quickly access the first item of an array
51
- * without the need for additional checks or method calls.
52
- *
53
- * @returns {*} The first element of the array or `undefined` if the array
54
- * is empty.
55
- */
56
- get first() {
57
- return this[0];
58
- },
48
+ /**
49
+ * A getter property that returns the first element of the array. If the
50
+ * array is empty, it returns `undefined`. This property is useful for
51
+ * scenarios where you need to quickly access the first item of an array
52
+ * without the need for additional checks or method calls.
53
+ *
54
+ * @returns {*} The first element of the array or `undefined` if the array
55
+ * is empty.
56
+ */
57
+ get first() {
58
+ return this[0];
59
+ },
59
60
 
60
- /**
61
- * A getter property that returns the last element of the array. It
62
- * calculates the last index based on the array's length. If the array is
63
- * empty, it returns `undefined`. This property is beneficial when you need
64
- * to access the last item in an array, improving code readability and
65
- * avoiding manual index calculation.
66
- *
67
- * @returns {*} The last element of the array or `undefined` if the
68
- * array is empty.
69
- */
70
- get last() {
71
- return this[this.length - 1];
61
+ /**
62
+ * A getter property that returns the last element of the array. It
63
+ * calculates the last index based on the array's length. If the array is
64
+ * empty, it returns `undefined`. This property is beneficial when you need
65
+ * to access the last item in an array, improving code readability and
66
+ * avoiding manual index calculation.
67
+ *
68
+ * @returns {*} The last element of the array or `undefined` if the
69
+ * array is empty.
70
+ */
71
+ get last() {
72
+ return this[this.length - 1];
73
+ },
72
74
  },
73
-
74
75
  })
@@ -134,90 +134,92 @@ export const FunctionExtensions = new Patch(Function, {
134
134
  })
135
135
 
136
136
  export const FunctionPrototypeExtensions = new Patch(Function.prototype, {
137
- /**
138
- * Determines if a given value is an asynchronous function. It checks if the
139
- * value is an instance of `Function` and if its string representation
140
- * includes the keyword 'Async'. This method is particularly useful for
141
- * identifying async functions.
142
- *
143
- * @returns {boolean} Returns `true` if the value is an async function,
144
- * otherwise `false`.
145
- */
146
- get isAsync() {
147
- return Function.isAsync(this)
148
- },
149
-
150
- /**
151
- * The function checks if a given value is an async generator function
152
- *
153
- * @returns {boolean} `true` if the value is an instance of a function and
154
- * its string tag is 'AsyncGeneratorFunction', otherwise it returns `false`.
155
- */
156
- get isAsyncGenerator() {
157
- return Function.isAsyncGenerator(this)
158
- },
159
-
160
- /**
161
- * Checks if a given value is an arrow function. It verifies if the value is
162
- * an instance of `Function`, if its string representation includes the '=>'
163
- * symbol, and if it lacks a prototype, which is a characteristic of arrow
164
- * functions in JavaScript.
165
- *
166
- * @returns {boolean} Returns `true` if the value is an arrow function,
167
- * otherwise `false`.
168
- */
169
- get isBigArrow() {
170
- return Function.isBigArrow(this)
171
- },
172
-
173
- /**
174
- * Determines if a given value is a bound function. Bound functions are
175
- * created using the `Function.prototype.bind` method, which allows setting
176
- * the `this` value at the time of binding. This method checks if the value
177
- * is an instance of `Function`, if its string representation starts with
178
- * 'bound', and if it lacks a `prototype` property. These characteristics
179
- * are indicative of bound functions in JavaScript.
180
- *
181
- * @returns {boolean} Returns `true` if the value is a bound function,
182
- * otherwise `false`. Bound functions have a specific format in their
183
- * string representation and do not have their own `prototype` property.
184
- */
185
- get isBound() {
186
- return Function.isBound(this)
187
- },
188
-
189
- /**
190
- * Determines if a given value is a class. It checks if the value is an
191
- * instance of `Function` and if its string representation includes the
192
- * keyword 'class'. This method is useful for distinguishing classes from
193
- * other function types in JavaScript.
194
- *
195
- * @returns {boolean} Returns `true` if the value is a class, otherwise
196
- * `false`.
197
- */
198
- get isClass() {
199
- return Function.isClass(this)
200
- },
201
-
202
- /**
203
- * Checks if a given value is a regular function. This method verifies if
204
- * the value is an instance of `Function`, which includes regular functions,
205
- * classes, and async functions but excludes arrow functions.
206
- *
207
- * @returns {boolean} Returns `true` if the value is a regular function,
208
- * otherwise `false`.
209
- */
210
- get isFunction() {
211
- return Function.isFunction(this)
212
- },
213
-
214
- /**
215
- * The function checks if a given value is a generator function
216
- *
217
- * @returns {boolean} `true` if the value is an instance of a function and
218
- * its string tag is 'GeneratorFunction', otherwise it returns `false`.
219
- */
220
- get isGenerator() {
221
- return Function.isGenerator(this)
137
+ [Patch.kMutablyHidden]: {
138
+ /**
139
+ * Determines if a given value is an asynchronous function. It checks if the
140
+ * value is an instance of `Function` and if its string representation
141
+ * includes the keyword 'Async'. This method is particularly useful for
142
+ * identifying async functions.
143
+ *
144
+ * @returns {boolean} Returns `true` if the value is an async function,
145
+ * otherwise `false`.
146
+ */
147
+ get isAsync() {
148
+ return Function.isAsync(this)
149
+ },
150
+
151
+ /**
152
+ * The function checks if a given value is an async generator function
153
+ *
154
+ * @returns {boolean} `true` if the value is an instance of a function and
155
+ * its string tag is 'AsyncGeneratorFunction', otherwise it returns `false`.
156
+ */
157
+ get isAsyncGenerator() {
158
+ return Function.isAsyncGenerator(this)
159
+ },
160
+
161
+ /**
162
+ * Checks if a given value is an arrow function. It verifies if the value is
163
+ * an instance of `Function`, if its string representation includes the '=>'
164
+ * symbol, and if it lacks a prototype, which is a characteristic of arrow
165
+ * functions in JavaScript.
166
+ *
167
+ * @returns {boolean} Returns `true` if the value is an arrow function,
168
+ * otherwise `false`.
169
+ */
170
+ get isBigArrow() {
171
+ return Function.isBigArrow(this)
172
+ },
173
+
174
+ /**
175
+ * Determines if a given value is a bound function. Bound functions are
176
+ * created using the `Function.prototype.bind` method, which allows setting
177
+ * the `this` value at the time of binding. This method checks if the value
178
+ * is an instance of `Function`, if its string representation starts with
179
+ * 'bound', and if it lacks a `prototype` property. These characteristics
180
+ * are indicative of bound functions in JavaScript.
181
+ *
182
+ * @returns {boolean} Returns `true` if the value is a bound function,
183
+ * otherwise `false`. Bound functions have a specific format in their
184
+ * string representation and do not have their own `prototype` property.
185
+ */
186
+ get isBound() {
187
+ return Function.isBound(this)
188
+ },
189
+
190
+ /**
191
+ * Determines if a given value is a class. It checks if the value is an
192
+ * instance of `Function` and if its string representation includes the
193
+ * keyword 'class'. This method is useful for distinguishing classes from
194
+ * other function types in JavaScript.
195
+ *
196
+ * @returns {boolean} Returns `true` if the value is a class, otherwise
197
+ * `false`.
198
+ */
199
+ get isClass() {
200
+ return Function.isClass(this)
201
+ },
202
+
203
+ /**
204
+ * Checks if a given value is a regular function. This method verifies if
205
+ * the value is an instance of `Function`, which includes regular functions,
206
+ * classes, and async functions but excludes arrow functions.
207
+ *
208
+ * @returns {boolean} Returns `true` if the value is a regular function,
209
+ * otherwise `false`.
210
+ */
211
+ get isFunction() {
212
+ return Function.isFunction(this)
213
+ },
214
+
215
+ /**
216
+ * The function checks if a given value is a generator function
217
+ *
218
+ * @returns {boolean} `true` if the value is an instance of a function and
219
+ * its string tag is 'GeneratorFunction', otherwise it returns `false`.
220
+ */
221
+ get isGenerator() {
222
+ return Function.isGenerator(this)
223
+ },
222
224
  },
223
225
  })
@@ -1,30 +1,32 @@
1
1
  import { Patch } from '@nejs/extension';
2
2
 
3
3
  export const MapPrototypeExtensions = new Patch(Map.prototype, {
4
- /**
5
- * The function `getKey` returns the key associated with a given value
6
- * in a map.
7
- *
8
- * @param {any} value - The value parameter is the value that you want to
9
- * find the corresponding key for in the map.
10
- * @param [strict=true] - The "strict" parameter is a boolean value that
11
- * determines whether strict equality (===) or loose equality (==) should
12
- * be used when comparing the "value" parameter with the values in the
13
- * entries of the object. If "strict" is set to true, strict equality will
14
- * be used.
15
- * @returns the key associated with the given value. If a matching key is
16
- * found, it is returned. If no matching key is found, null is returned.
17
- */
18
- getKey(value, strict = true) {
19
- for (const [key, entryValue] of this) {
20
- if (
21
- (strict && value === entryValue) &&
22
- (!strict && value == entryValue)
23
- ) {
24
- return key
25
- }
4
+ [Patch.kMutablyHidden]: {
5
+ /**
6
+ * The function `getKey` returns the key associated with a given value
7
+ * in a map.
8
+ *
9
+ * @param {any} value - The value parameter is the value that you want to
10
+ * find the corresponding key for in the map.
11
+ * @param [strict=true] - The "strict" parameter is a boolean value that
12
+ * determines whether strict equality (===) or loose equality (==) should
13
+ * be used when comparing the "value" parameter with the values in the
14
+ * entries of the object. If "strict" is set to true, strict equality will
15
+ * be used.
16
+ * @returns the key associated with the given value. If a matching key is
17
+ * found, it is returned. If no matching key is found, null is returned.
18
+ */
19
+ getKey(value, strict = true) {
20
+ for (const [key, entryValue] of this) {
21
+ if (
22
+ (strict && value === entryValue) &&
23
+ (!strict && value == entryValue)
24
+ ) {
25
+ return key
26
+ }
26
27
 
27
- return null
28
- }
28
+ return null
29
+ }
30
+ },
29
31
  },
30
32
  })
@@ -200,22 +200,57 @@ export const ObjectExtensions = new Patch(Object, {
200
200
  },
201
201
  });
202
202
 
203
+ const staticPatches = ObjectExtensions.patches;
204
+
203
205
  export const ObjectPrototypeExtensions = new Patch(Object.prototype, {
204
- /**
205
- * Strips an object down to only the keys specified. Optionally, any
206
- * accessors can be made to retain their context on the source object.
207
- * This is a passthrough to the static {@link Object.stripTo} function
208
- *
209
- * @param {Array<string|symbol>} keys the keys that should appear in the
210
- * final reduced object
211
- * @param {boolean} [bindAccessors = true] if this value is true then any
212
- * accessors from the source object will continue to have their `this`
213
- * value bound to the source. If the getter or setter on that object is
214
- * defined using an arrow function, this will not work as intended.
215
- * @returns {object} an object containing only the keys and symbols
216
- * specified in the `keys` parameter.
217
- */
218
- stripTo(keys, bindAccessors = true) {
219
- return Object.stripTo(this, keys, bindAccessors)
220
- }
206
+ [Patch.kMutablyHidden](store) {
207
+ return {
208
+ /**
209
+ * Checks to see if the supplied `value` is both an object, and has the
210
+ * appropriate symbol defined.
211
+ *
212
+ * @param {any} value the value to determine if it contains a defined
213
+ * `Symbol.toStringTag` defined.
214
+ * @returns true if the symbol is defined, false otherwise
215
+ */
216
+ get hasStringTag() {
217
+ return staticPatches.hasStringTag(this)
218
+ },
219
+
220
+ /**
221
+ * Retrieves the string tag of an object. The string tag is a representation
222
+ * of the object's type, as defined by its `Object.prototype.toString`
223
+ * method. This utility method is helpful for getting a more descriptive
224
+ * type of an object than what is returned by the `typeof` operator,
225
+ * especially for custom objects.
226
+ *
227
+ * @param {*} value - The object whose string tag is to be retrieved.
228
+ * @param {boolean} strict - if this is set to true, undefined will be
229
+ * returned whenever a supplied object does not have a
230
+ * `Symbol.toStringTag` defined, period. if false, the default,
231
+ * @returns {string} - The string tag of the object, indicating its type.
232
+ */
233
+ getStringTag(strict = false) {
234
+ return staticPatches.getStringTag(this, strict)
235
+ },
236
+
237
+ /**
238
+ * Strips an object down to only the keys specified. Optionally, any
239
+ * accessors can be made to retain their context on the source object.
240
+ * This is a passthrough to the static {@link Object.stripTo} function
241
+ *
242
+ * @param {Array<string|symbol>} keys the keys that should appear in the
243
+ * final reduced object
244
+ * @param {boolean} [bindAccessors = true] if this value is true then any
245
+ * accessors from the source object will continue to have their `this`
246
+ * value bound to the source. If the getter or setter on that object is
247
+ * defined using an arrow function, this will not work as intended.
248
+ * @returns {object} an object containing only the keys and symbols
249
+ * specified in the `keys` parameter.
250
+ */
251
+ stripTo(keys, bindAccessors = true) {
252
+ return Object.stripTo(this, keys, bindAccessors)
253
+ }
254
+ }
255
+ },
221
256
  })