@nejs/basic-extensions 1.5.0 → 1.5.1

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.
@@ -3,43 +3,49 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FunctionExtensions = void 0;
4
4
  const extension_1 = require("@nejs/extension");
5
5
  /**
6
- * The `FunctionExtensions` class is a patch applied to the built-in JavaScript `Function`
7
- * constructor. It extends `Function` with additional utility methods for determining the
8
- * specific type or nature of function-like objects. These methods allow developers to
9
- * distinguish between classes, regular functions, async functions, and arrow functions
10
- * in a more intuitive and straightforward manner. This class is part of the `@nejs/extension`
11
- * library and enhances the capabilities of function handling and introspection in JavaScript.
6
+ * The `FunctionExtensions` class is a patch applied to the built-in JavaScript
7
+ * `Function` constructor. It extends `Function` with additional utility methods
8
+ * for determining the specific type or nature of function-like objects. These
9
+ * methods allow developers to distinguish between classes, regular functions,
10
+ * async functions, and arrow functions in a more intuitive and straightforward
11
+ * manner. This class is part of the `@nejs/extension` library and enhances the
12
+ * capabilities of function handling and introspection in JavaScript.
12
13
  */
13
14
  exports.FunctionExtensions = new extension_1.Patch(Function, {
14
15
  /**
15
- * Determines if a given value is a class. It checks if the value is an instance of
16
- * `Function` and if its string representation includes the keyword 'class'. This method
17
- * is useful for distinguishing classes from other function types in JavaScript.
16
+ * Determines if a given value is a class. It checks if the value is an
17
+ * instance of `Function` and if its string representation includes the
18
+ * keyword 'class'. This method is useful for distinguishing classes from
19
+ * other function types in JavaScript.
18
20
  *
19
21
  * @param {*} value - The value to be checked.
20
- * @returns {boolean} Returns `true` if the value is a class, otherwise `false`.
22
+ * @returns {boolean} Returns `true` if the value is a class, otherwise
23
+ * `false`.
21
24
  */
22
25
  isClass(value) {
23
26
  return value instanceof Function && !!/^class\s/.exec(String(value));
24
27
  },
25
28
  /**
26
- * Checks if a given value is a regular function. This method verifies if the value is
27
- * an instance of `Function`, which includes regular functions, classes, and async
28
- * functions but excludes arrow functions.
29
+ * Checks if a given value is a regular function. This method verifies if
30
+ * the value is an instance of `Function`, which includes regular functions,
31
+ * classes, and async functions but excludes arrow functions.
29
32
  *
30
33
  * @param {*} value - The value to be checked.
31
- * @returns {boolean} Returns `true` if the value is a regular function, otherwise `false`.
34
+ * @returns {boolean} Returns `true` if the value is a regular function,
35
+ * otherwise `false`.
32
36
  */
33
37
  isFunction(value) {
34
38
  return value instanceof Function;
35
39
  },
36
40
  /**
37
- * Determines if a given value is an asynchronous function. It checks if the value is an
38
- * instance of `Function` and if its string representation includes the keyword 'Async'.
39
- * This method is particularly useful for identifying async functions.
41
+ * Determines if a given value is an asynchronous function. It checks if the
42
+ * value is an instance of `Function` and if its string representation
43
+ * includes the keyword 'Async'. This method is particularly useful for
44
+ * identifying async functions.
40
45
  *
41
46
  * @param {*} value - The value to be checked.
42
- * @returns {boolean} Returns `true` if the value is an async function, otherwise `false`.
47
+ * @returns {boolean} Returns `true` if the value is an async function,
48
+ * otherwise `false`.
43
49
  */
44
50
  isAsync(value) {
45
51
  const stringTag = /(\w+)]/g.exec(Object.prototype.toString.call(value))[1];
@@ -47,12 +53,14 @@ exports.FunctionExtensions = new extension_1.Patch(Function, {
47
53
  stringTag.includes('Async'));
48
54
  },
49
55
  /**
50
- * Checks if a given value is an arrow function. It verifies if the value is an instance
51
- * of `Function`, if its string representation includes the '=>' symbol, and if it lacks
52
- * a prototype, which is a characteristic of arrow functions in JavaScript.
56
+ * Checks if a given value is an arrow function. It verifies if the value is
57
+ * an instance of `Function`, if its string representation includes the '=>'
58
+ * symbol, and if it lacks a prototype, which is a characteristic of arrow
59
+ * functions in JavaScript.
53
60
  *
54
61
  * @param {*} value - The value to be checked.
55
- * @returns {boolean} Returns `true` if the value is an arrow function, otherwise `false`.
62
+ * @returns {boolean} Returns `true` if the value is an arrow function,
63
+ * otherwise `false`.
56
64
  */
57
65
  isBigArrow(value) {
58
66
  return (value instanceof Function &&
@@ -61,16 +69,17 @@ exports.FunctionExtensions = new extension_1.Patch(Function, {
61
69
  !Reflect.has(value, 'prototype'));
62
70
  },
63
71
  /**
64
- * Determines if a given value is a bound function. Bound functions are created using
65
- * the `Function.prototype.bind` method, which allows setting the `this` value at the
66
- * time of binding. This method checks if the value is an instance of `Function`, if
67
- * its string representation starts with 'bound', and if it lacks a `prototype`
68
- * property. These characteristics are indicative of bound functions in JavaScript.
72
+ * Determines if a given value is a bound function. Bound functions are
73
+ * created using the `Function.prototype.bind` method, which allows setting
74
+ * the `this` value at the time of binding. This method checks if the value
75
+ * is an instance of `Function`, if its string representation starts with
76
+ * 'bound', and if it lacks a `prototype` property. These characteristics
77
+ * are indicative of bound functions in JavaScript.
69
78
  *
70
79
  * @param {*} value - The value to be checked, typically a function.
71
- * @returns {boolean} Returns `true` if the value is a bound function, otherwise
72
- * `false`. Bound functions have a specific format in their string representation
73
- * and do not have their own `prototype` property.
80
+ * @returns {boolean} Returns `true` if the value is a bound function,
81
+ * otherwise `false`. Bound functions have a specific format in their
82
+ * string representation and do not have their own `prototype` property.
74
83
  */
75
84
  isBound(value) {
76
85
  return (value instanceof Function &&
@@ -11,6 +11,14 @@ const extension_1 = require("@nejs/extension");
11
11
  * utility functions.
12
12
  */
13
13
  exports.ObjectExtensions = new extension_1.Patch(Object, {
14
+ /**
15
+ * Checks to see if the supplied `value` is both an object, and has the
16
+ * appropriate symbol defined.
17
+ *
18
+ * @param {any} value the value to determine if it contains a defined
19
+ * `Symbol.toStringTag` defined.
20
+ * @returns true if the symbol is defined, false otherwise
21
+ */
14
22
  hasStringTag(value) {
15
23
  return Object.isObject(value) && Reflect.has(value, Symbol.toStringTag);
16
24
  },
@@ -242,16 +242,16 @@ class Descriptor {
242
242
  return this.constructor.name;
243
243
  }
244
244
  /**
245
- * The function `getData` retrieves the value of a property from an object if it
246
- * exists and is a data property.
245
+ * The function `getData` retrieves the value of a property from an object
246
+ * if it exists and is a data property.
247
247
  *
248
248
  * @param object - The "object" parameter is the object from which we want to
249
249
  * retrieve data.
250
250
  * @param property - The `property` parameter is the name of the property that
251
251
  * you want to retrieve the data from.
252
- * @returns either the value of the specified property if it exists and is a data
253
- * property, or undefined if the property does not exist or is not a data
254
- * property.
252
+ * @returns either the value of the specified property if it exists and is
253
+ * a data property, or undefined if the property does not exist or is not
254
+ * a data property.
255
255
  */
256
256
  static getData(object, property) {
257
257
  if (!isObject(object) || !isString(property)) {
@@ -276,10 +276,10 @@ class Descriptor {
276
276
  * which we want to get the accessor.
277
277
  * @returns an object that contains the getter and setter functions for the
278
278
  * specified property of the given object. If the property is an accessor
279
- * property (defined with a getter and/or setter), the returned object will also
280
- * have additional properties such as "accessor" and "descriptor". If the
281
- * property is not found or is not an accessor property, the function returns
282
- * undefined.
279
+ * property (defined with a getter and/or setter), the returned object will
280
+ * also have additional properties such as "accessor" and "descriptor". If
281
+ * the property is not found or is not an accessor property, the function
282
+ * returns undefined.
283
283
  */
284
284
  static getAccessor(object, property) {
285
285
  if (!isObject(object))
@@ -318,14 +318,14 @@ class Descriptor {
318
318
  *
319
319
  * @param [enumerable=false] - A boolean value indicating whether the property
320
320
  * can be enumerated (listed) when iterating over the object's properties.
321
- * @param [configurable=false] - The `configurable` parameter determines whether
322
- * the property can be deleted or its attributes can be modified. If
323
- * `configurable` is set to `true`, the property can be deleted and its
324
- * attributes can be changed. If `configurable` is set to `false`, the property
325
- * cannot be deleted and
321
+ * @param [configurable=false] - The `configurable` parameter determines
322
+ * whether the property can be deleted or its attributes can be modified.
323
+ * If `configurable` is set to `true`, the property can be deleted and its
324
+ * attributes can be changed. If `configurable` is set to `false`, the
325
+ * property cannot be deleted and
326
326
  * @returns An object with the properties `enumerable` and `configurable` is
327
- * being returned. The values of these properties are determined by the arguments
328
- * passed to the `base` function.
327
+ * being returned. The values of these properties are determined by the
328
+ * arguments passed to the `base` function.
329
329
  */
330
330
  static base(enumerable = false, configurable = false) {
331
331
  return {
@@ -340,9 +340,9 @@ class Descriptor {
340
340
  *
341
341
  * @param getter - The getter parameter is a function that will be used as the
342
342
  * getter for the property. It will be called when the property is accessed.
343
- * @param setter - The `setter` parameter is a function that will be used as the
344
- * setter for the property. It will be called whenever the property is assigned a
345
- * new value.
343
+ * @param setter - The `setter` parameter is a function that will be used as
344
+ * the setter for the property. It will be called whenever the property is
345
+ * assigned a new value.
346
346
  * @param [] - - `getter`: A function that will be used as the getter for the
347
347
  * property.
348
348
  * @returns an object with properties "get", "set", "enumerable", and
@@ -357,13 +357,15 @@ class Descriptor {
357
357
  };
358
358
  }
359
359
  /**
360
- * The function "newData" creates a new data object with customizable properties.
360
+ * The function "newData" creates a new data object with customizable
361
+ * properties.
361
362
  *
362
- * @param value - The value parameter represents the value that will be assigned
363
- * to the property.
364
- * @param [writable=true] - The `writable` parameter determines whether the value
365
- * of the property can be changed. If `writable` is set to `true`, the value can
366
- * be changed. If `writable` is set to `false`, the value cannot be changed.
363
+ * @param value - The value parameter represents the value that will be
364
+ * assigned to the property.
365
+ * @param [writable=true] - The `writable` parameter determines whether the
366
+ * value of the property can be changed. If `writable` is set to `true`, the
367
+ * value can be changed. If `writable` is set to `false`, the value cannot be
368
+ * changed.
367
369
  * @param [] - - `value`: The value to be assigned to the property.
368
370
  * @returns an object with properties `value`, `enumerable`, `writable`, and
369
371
  * `configurable`.
@@ -377,10 +379,11 @@ class Descriptor {
377
379
  };
378
380
  }
379
381
  /**
380
- * The function checks if an object is a valid object descriptor in JavaScript.
382
+ * The function checks if an object is a valid object descriptor in
383
+ * JavaScript.
381
384
  *
382
- * @param object - The `object` parameter is the object that we want to check if
383
- * it is a descriptor.
385
+ * @param object - The `object` parameter is the object that we want to
386
+ * check if it is a descriptor.
384
387
  * @returns a boolean value.
385
388
  */
386
389
  static isDescriptor(object) {
@@ -394,12 +397,13 @@ class Descriptor {
394
397
  /**
395
398
  * The function checks if a given property or descriptor is a data property.
396
399
  *
397
- * @param descriptor_orProp - The `descriptor_orProp` parameter can be either a
398
- * descriptor or a property name.
399
- * @param object - The `object` parameter is the object that you want to check
400
- * for data properties.
401
- * @returns a boolean value. It returns `true` if the `descriptor` object has any
402
- * keys that match the `DATA_KEYS` array, otherwise it returns `false`.
400
+ * @param descriptor_orProp - The `descriptor_orProp` parameter can be
401
+ * either a descriptor or a property name.
402
+ * @param object - The `object` parameter is the object that you want to
403
+ * check for data properties.
404
+ * @returns a boolean value. It returns `true` if the `descriptor` object
405
+ * has any keys that match the `DATA_KEYS` array, otherwise it returns
406
+ * `false`.
403
407
  */
404
408
  static isData(object_orProp, property) {
405
409
  const needsDescriptor = (((typeof object_orProp === 'object') || object_orProp instanceof Object) &&
@@ -418,15 +422,15 @@ class Descriptor {
418
422
  return validData;
419
423
  }
420
424
  /**
421
- * The function checks if a given property descriptor or property of an object is
422
- * an accessor.
425
+ * The function checks if a given property descriptor or property of an
426
+ * object is an accessor.
423
427
  *
424
428
  * @param object_orProp - The `descriptor_orProp` parameter can be either a
425
429
  * descriptor object or a property name.
426
- * @param property - The `object` parameter is the object that you want to check
427
- * for accessor properties.
428
- * @returns a boolean value. It returns true if the descriptor or property passed
429
- * as an argument is an accessor descriptor, and false otherwise.
430
+ * @param property - The `object` parameter is the object that you want to
431
+ * check for accessor properties.
432
+ * @returns a boolean value. It returns true if the descriptor or property
433
+ * passed as an argument is an accessor descriptor, and false otherwise.
430
434
  */
431
435
  static isAccessor(object_orProp, property) {
432
436
  const needsDescriptor = ((object_orProp && property) &&
@@ -446,25 +450,28 @@ class Descriptor {
446
450
  return validAccessor;
447
451
  }
448
452
  /**
449
- * A base descriptor (new for each read) that is both enumerable and configurable
453
+ * A base descriptor (new for each read) that is both enumerable and
454
+ * configurable
450
455
  *
451
- * @returns The method `flexible` is returning the result of calling the `base`
452
- * method with the arguments `true` and `true`.
456
+ * @returns The method `flexible` is returning the result of calling the
457
+ * `base` method with the arguments `true` and `true`.
453
458
  */
454
459
  static get flexible() {
455
460
  return this.base(true, true);
456
461
  }
457
462
  /**
458
- * A base descriptor (new for each read) that is not enumerable but is configurable
463
+ * A base descriptor (new for each read) that is not enumerable but is
464
+ * configurable
459
465
  *
460
- * @returns The method `enigmatic` is returning the result of calling the `base`
461
- * method with the arguments `false` and `true`.
466
+ * @returns The method `enigmatic` is returning the result of calling
467
+ * the `base` method with the arguments `false` and `true`.
462
468
  */
463
469
  static get enigmatic() {
464
470
  return this.base(false, true);
465
471
  }
466
472
  /**
467
- * A base descriptor (new for each read) that is neither enumerable nor configurable
473
+ * A base descriptor (new for each read) that is neither enumerable
474
+ * nor configurable
468
475
  *
469
476
  * @returns The code is returning the result of calling the `base` method with
470
477
  * the arguments `false` and `false`.
@@ -475,8 +482,8 @@ class Descriptor {
475
482
  /**
476
483
  * A base descriptor (new for each read) that enumerable but not configurable
477
484
  *
478
- * @returns The method is returning the result of calling the `base` method with
479
- * the arguments `true` and `false`.
485
+ * @returns The method is returning the result of calling the `base`
486
+ * method with the arguments `true` and `false`.
480
487
  */
481
488
  static get transparent() {
482
489
  return this.base(true, false);
@@ -1,10 +1,11 @@
1
1
  /**
2
- * The `FunctionExtensions` class is a patch applied to the built-in JavaScript `Function`
3
- * constructor. It extends `Function` with additional utility methods for determining the
4
- * specific type or nature of function-like objects. These methods allow developers to
5
- * distinguish between classes, regular functions, async functions, and arrow functions
6
- * in a more intuitive and straightforward manner. This class is part of the `@nejs/extension`
7
- * library and enhances the capabilities of function handling and introspection in JavaScript.
2
+ * The `FunctionExtensions` class is a patch applied to the built-in JavaScript
3
+ * `Function` constructor. It extends `Function` with additional utility methods
4
+ * for determining the specific type or nature of function-like objects. These
5
+ * methods allow developers to distinguish between classes, regular functions,
6
+ * async functions, and arrow functions in a more intuitive and straightforward
7
+ * manner. This class is part of the `@nejs/extension` library and enhances the
8
+ * capabilities of function handling and introspection in JavaScript.
8
9
  */
9
10
  export const FunctionExtensions: Patch;
10
11
  import { Patch } from '@nejs/extension';
@@ -1,42 +1,48 @@
1
1
  import { Patch } from '@nejs/extension';
2
2
  /**
3
- * The `FunctionExtensions` class is a patch applied to the built-in JavaScript `Function`
4
- * constructor. It extends `Function` with additional utility methods for determining the
5
- * specific type or nature of function-like objects. These methods allow developers to
6
- * distinguish between classes, regular functions, async functions, and arrow functions
7
- * in a more intuitive and straightforward manner. This class is part of the `@nejs/extension`
8
- * library and enhances the capabilities of function handling and introspection in JavaScript.
3
+ * The `FunctionExtensions` class is a patch applied to the built-in JavaScript
4
+ * `Function` constructor. It extends `Function` with additional utility methods
5
+ * for determining the specific type or nature of function-like objects. These
6
+ * methods allow developers to distinguish between classes, regular functions,
7
+ * async functions, and arrow functions in a more intuitive and straightforward
8
+ * manner. This class is part of the `@nejs/extension` library and enhances the
9
+ * capabilities of function handling and introspection in JavaScript.
9
10
  */
10
11
  export const FunctionExtensions = new Patch(Function, {
11
12
  /**
12
- * Determines if a given value is a class. It checks if the value is an instance of
13
- * `Function` and if its string representation includes the keyword 'class'. This method
14
- * is useful for distinguishing classes from other function types in JavaScript.
13
+ * Determines if a given value is a class. It checks if the value is an
14
+ * instance of `Function` and if its string representation includes the
15
+ * keyword 'class'. This method is useful for distinguishing classes from
16
+ * other function types in JavaScript.
15
17
  *
16
18
  * @param {*} value - The value to be checked.
17
- * @returns {boolean} Returns `true` if the value is a class, otherwise `false`.
19
+ * @returns {boolean} Returns `true` if the value is a class, otherwise
20
+ * `false`.
18
21
  */
19
22
  isClass(value) {
20
23
  return value instanceof Function && !!/^class\s/.exec(String(value));
21
24
  },
22
25
  /**
23
- * Checks if a given value is a regular function. This method verifies if the value is
24
- * an instance of `Function`, which includes regular functions, classes, and async
25
- * functions but excludes arrow functions.
26
+ * Checks if a given value is a regular function. This method verifies if
27
+ * the value is an instance of `Function`, which includes regular functions,
28
+ * classes, and async functions but excludes arrow functions.
26
29
  *
27
30
  * @param {*} value - The value to be checked.
28
- * @returns {boolean} Returns `true` if the value is a regular function, otherwise `false`.
31
+ * @returns {boolean} Returns `true` if the value is a regular function,
32
+ * otherwise `false`.
29
33
  */
30
34
  isFunction(value) {
31
35
  return value instanceof Function;
32
36
  },
33
37
  /**
34
- * Determines if a given value is an asynchronous function. It checks if the value is an
35
- * instance of `Function` and if its string representation includes the keyword 'Async'.
36
- * This method is particularly useful for identifying async functions.
38
+ * Determines if a given value is an asynchronous function. It checks if the
39
+ * value is an instance of `Function` and if its string representation
40
+ * includes the keyword 'Async'. This method is particularly useful for
41
+ * identifying async functions.
37
42
  *
38
43
  * @param {*} value - The value to be checked.
39
- * @returns {boolean} Returns `true` if the value is an async function, otherwise `false`.
44
+ * @returns {boolean} Returns `true` if the value is an async function,
45
+ * otherwise `false`.
40
46
  */
41
47
  isAsync(value) {
42
48
  const stringTag = /(\w+)]/g.exec(Object.prototype.toString.call(value))[1];
@@ -44,12 +50,14 @@ export const FunctionExtensions = new Patch(Function, {
44
50
  stringTag.includes('Async'));
45
51
  },
46
52
  /**
47
- * Checks if a given value is an arrow function. It verifies if the value is an instance
48
- * of `Function`, if its string representation includes the '=>' symbol, and if it lacks
49
- * a prototype, which is a characteristic of arrow functions in JavaScript.
53
+ * Checks if a given value is an arrow function. It verifies if the value is
54
+ * an instance of `Function`, if its string representation includes the '=>'
55
+ * symbol, and if it lacks a prototype, which is a characteristic of arrow
56
+ * functions in JavaScript.
50
57
  *
51
58
  * @param {*} value - The value to be checked.
52
- * @returns {boolean} Returns `true` if the value is an arrow function, otherwise `false`.
59
+ * @returns {boolean} Returns `true` if the value is an arrow function,
60
+ * otherwise `false`.
53
61
  */
54
62
  isBigArrow(value) {
55
63
  return (value instanceof Function &&
@@ -58,16 +66,17 @@ export const FunctionExtensions = new Patch(Function, {
58
66
  !Reflect.has(value, 'prototype'));
59
67
  },
60
68
  /**
61
- * Determines if a given value is a bound function. Bound functions are created using
62
- * the `Function.prototype.bind` method, which allows setting the `this` value at the
63
- * time of binding. This method checks if the value is an instance of `Function`, if
64
- * its string representation starts with 'bound', and if it lacks a `prototype`
65
- * property. These characteristics are indicative of bound functions in JavaScript.
69
+ * Determines if a given value is a bound function. Bound functions are
70
+ * created using the `Function.prototype.bind` method, which allows setting
71
+ * the `this` value at the time of binding. This method checks if the value
72
+ * is an instance of `Function`, if its string representation starts with
73
+ * 'bound', and if it lacks a `prototype` property. These characteristics
74
+ * are indicative of bound functions in JavaScript.
66
75
  *
67
76
  * @param {*} value - The value to be checked, typically a function.
68
- * @returns {boolean} Returns `true` if the value is a bound function, otherwise
69
- * `false`. Bound functions have a specific format in their string representation
70
- * and do not have their own `prototype` property.
77
+ * @returns {boolean} Returns `true` if the value is a bound function,
78
+ * otherwise `false`. Bound functions have a specific format in their
79
+ * string representation and do not have their own `prototype` property.
71
80
  */
72
81
  isBound(value) {
73
82
  return (value instanceof Function &&
@@ -8,6 +8,14 @@ import { Patch } from '@nejs/extension';
8
8
  * utility functions.
9
9
  */
10
10
  export const ObjectExtensions = new Patch(Object, {
11
+ /**
12
+ * Checks to see if the supplied `value` is both an object, and has the
13
+ * appropriate symbol defined.
14
+ *
15
+ * @param {any} value the value to determine if it contains a defined
16
+ * `Symbol.toStringTag` defined.
17
+ * @returns true if the symbol is defined, false otherwise
18
+ */
11
19
  hasStringTag(value) {
12
20
  return Object.isObject(value) && Reflect.has(value, Symbol.toStringTag);
13
21
  },
package/package.json CHANGED
@@ -46,9 +46,9 @@
46
46
  "test": "jest"
47
47
  },
48
48
  "type": "module",
49
- "version": "1.5.0",
49
+ "version": "1.5.1",
50
50
  "dependencies": {
51
51
  "@nejs/extension": "^1.2.1"
52
52
  },
53
- "browser": "dist/@nejs/basic-extensions.bundle.1.4.1.js"
53
+ "browser": "dist/@nejs/basic-extensions.bundle.1.5.0.js"
54
54
  }