@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.
- package/dist/@nejs/{basic-extensions.bundle.1.4.1.js → basic-extensions.bundle.1.5.0.js} +1 -1
- package/dist/@nejs/basic-extensions.bundle.1.5.0.js.map +7 -0
- package/dist/cjs/descriptor.js +56 -49
- package/dist/cjs/functionextensions.d.ts +7 -6
- package/dist/cjs/functionextensions.js +39 -30
- package/dist/cjs/objectextensions.js +8 -0
- package/dist/mjs/descriptor.js +56 -49
- package/dist/mjs/functionextensions.d.ts +7 -6
- package/dist/mjs/functionextensions.js +39 -30
- package/dist/mjs/objectextensions.js +8 -0
- package/package.json +2 -2
- package/src/descriptor.js +56 -49
- package/src/functionextensions.js +39 -30
- package/src/objectextensions.js +8 -0
- package/dist/@nejs/basic-extensions.bundle.1.4.1.js.map +0 -7
|
@@ -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
|
|
7
|
-
* constructor. It extends `Function` with additional utility methods
|
|
8
|
-
* specific type or nature of function-like objects. These
|
|
9
|
-
* distinguish between classes, regular functions,
|
|
10
|
-
* in a more intuitive and straightforward
|
|
11
|
-
*
|
|
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
|
|
16
|
-
* `Function` and if its string representation includes the
|
|
17
|
-
* is useful for distinguishing classes from
|
|
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
|
|
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
|
|
27
|
-
* an instance of `Function`, which includes regular functions,
|
|
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,
|
|
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
|
|
38
|
-
* instance of `Function` and if its string representation
|
|
39
|
-
* This method is particularly useful for
|
|
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,
|
|
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
|
|
51
|
-
* of `Function`, if its string representation includes the '=>'
|
|
52
|
-
* a prototype, which is a characteristic of arrow
|
|
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,
|
|
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
|
|
65
|
-
* the `Function.prototype.bind` method, which allows setting
|
|
66
|
-
* time of binding. This method checks if the value
|
|
67
|
-
*
|
|
68
|
-
*
|
|
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,
|
|
72
|
-
* `false`. Bound functions have a specific format in their
|
|
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
|
},
|
package/dist/mjs/descriptor.js
CHANGED
|
@@ -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
|
|
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
|
|
253
|
-
* property, or undefined if the property does not exist or is not
|
|
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
|
|
280
|
-
* have additional properties such as "accessor" and "descriptor". If
|
|
281
|
-
* property is not found or is not an accessor property, the function
|
|
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
|
|
322
|
-
* the property can be deleted or its attributes can be modified.
|
|
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
|
|
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
|
|
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
|
|
344
|
-
* setter for the property. It will be called whenever the property is
|
|
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
|
|
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
|
|
363
|
-
* to the property.
|
|
364
|
-
* @param [writable=true] - The `writable` parameter determines whether the
|
|
365
|
-
* of the property can be changed. If `writable` is set to `true`, the
|
|
366
|
-
* be changed. If `writable` is set to `false`, the value cannot be
|
|
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
|
|
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
|
|
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
|
|
398
|
-
* descriptor or a property name.
|
|
399
|
-
* @param object - The `object` parameter is the object that you want to
|
|
400
|
-
* for data properties.
|
|
401
|
-
* @returns a boolean value. It returns `true` if the `descriptor` object
|
|
402
|
-
* keys that match the `DATA_KEYS` array, otherwise it returns
|
|
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
|
|
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
|
|
427
|
-
* for accessor properties.
|
|
428
|
-
* @returns a boolean value. It returns true if the descriptor or property
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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`
|
|
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
|
|
3
|
-
* constructor. It extends `Function` with additional utility methods
|
|
4
|
-
* specific type or nature of function-like objects. These
|
|
5
|
-
* distinguish between classes, regular functions,
|
|
6
|
-
* in a more intuitive and straightforward
|
|
7
|
-
*
|
|
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
|
|
4
|
-
* constructor. It extends `Function` with additional utility methods
|
|
5
|
-
* specific type or nature of function-like objects. These
|
|
6
|
-
* distinguish between classes, regular functions,
|
|
7
|
-
* in a more intuitive and straightforward
|
|
8
|
-
*
|
|
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
|
|
13
|
-
* `Function` and if its string representation includes the
|
|
14
|
-
* is useful for distinguishing classes from
|
|
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
|
|
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
|
|
24
|
-
* an instance of `Function`, which includes regular functions,
|
|
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,
|
|
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
|
|
35
|
-
* instance of `Function` and if its string representation
|
|
36
|
-
* This method is particularly useful for
|
|
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,
|
|
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
|
|
48
|
-
* of `Function`, if its string representation includes the '=>'
|
|
49
|
-
* a prototype, which is a characteristic of arrow
|
|
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,
|
|
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
|
|
62
|
-
* the `Function.prototype.bind` method, which allows setting
|
|
63
|
-
* time of binding. This method checks if the value
|
|
64
|
-
*
|
|
65
|
-
*
|
|
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,
|
|
69
|
-
* `false`. Bound functions have a specific format in their
|
|
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.
|
|
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.
|
|
53
|
+
"browser": "dist/@nejs/basic-extensions.bundle.1.5.0.js"
|
|
54
54
|
}
|