@naman_deep_singh/utils 2.1.0 → 2.2.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.
- package/README.md +1 -1
- package/dist/cjs/array/array-extensions.js +23 -23
- package/dist/cjs/array/index.js +2 -2
- package/dist/cjs/core/index.js +2 -2
- package/dist/cjs/core/performance.js +2 -2
- package/dist/cjs/extensions/index.js +4 -4
- package/dist/cjs/index.js +29 -75
- package/dist/cjs/init/index.js +2 -2
- package/dist/cjs/init/initializer.js +10 -11
- package/dist/cjs/number/index.js +2 -2
- package/dist/cjs/number/number-extensions.js +23 -23
- package/dist/cjs/object/index.js +2 -2
- package/dist/cjs/object/object-extensions.js +14 -14
- package/dist/cjs/string/index.js +2 -2
- package/dist/cjs/string/string-extensions.js +22 -22
- package/dist/cjs/types/index.js +2 -2
- package/dist/cjs/utils/index.js +3 -3
- package/dist/esm/array/array-extensions.js +1 -1
- package/dist/esm/array/index.js +1 -1
- package/dist/esm/core/index.js +2 -2
- package/dist/esm/core/performance.js +1 -1
- package/dist/esm/extensions/index.js +4 -4
- package/dist/esm/index.js +15 -68
- package/dist/esm/init/index.js +2 -2
- package/dist/esm/init/initializer.js +5 -6
- package/dist/esm/number/index.js +1 -1
- package/dist/esm/number/number-extensions.js +2 -2
- package/dist/esm/object/index.js +1 -1
- package/dist/esm/object/object-extensions.js +1 -1
- package/dist/esm/string/index.js +1 -1
- package/dist/esm/string/string-extensions.js +1 -1
- package/dist/esm/types/index.js +2 -2
- package/dist/esm/utils/index.js +3 -3
- package/dist/types/array/index.d.ts +1 -1
- package/dist/types/core/index.d.ts +2 -2
- package/dist/types/extensions/index.d.ts +4 -4
- package/dist/types/index.d.ts +10 -61
- package/dist/types/init/index.d.ts +2 -2
- package/dist/types/init/initializer.d.ts +1 -1
- package/dist/types/init/options.d.ts +1 -1
- package/dist/types/number/index.d.ts +1 -1
- package/dist/types/object/index.d.ts +1 -1
- package/dist/types/string/index.d.ts +1 -1
- package/dist/types/types/extension-types.d.ts +1 -1
- package/dist/types/types/global-augmentations.d.ts +37 -24
- package/dist/types/types/index.d.ts +2 -2
- package/dist/types/utils/config.d.ts +1 -1
- package/dist/types/utils/index.d.ts +3 -3
- package/package.json +52 -4
- package/dist/cjs/array/array-extensions.d.ts +0 -1
- package/dist/cjs/array/index.d.ts +0 -1
- package/dist/cjs/core/index.d.ts +0 -2
- package/dist/cjs/core/performance.d.ts +0 -17
- package/dist/cjs/core/validation.d.ts +0 -4
- package/dist/cjs/core/version.d.ts +0 -1
- package/dist/cjs/extensions/index.d.ts +0 -4
- package/dist/cjs/index.d.ts +0 -61
- package/dist/cjs/init/index.d.ts +0 -2
- package/dist/cjs/init/initializer.d.ts +0 -3
- package/dist/cjs/init/options.d.ts +0 -3
- package/dist/cjs/number/index.d.ts +0 -1
- package/dist/cjs/number/number-extensions.d.ts +0 -1
- package/dist/cjs/object/index.d.ts +0 -1
- package/dist/cjs/object/object-extensions.d.ts +0 -1
- package/dist/cjs/string/index.d.ts +0 -1
- package/dist/cjs/string/string-extensions.d.ts +0 -1
- package/dist/cjs/types/extension-types.d.ts +0 -9
- package/dist/cjs/types/global-augmentations.d.ts +0 -72
- package/dist/cjs/types/index.d.ts +0 -2
- package/dist/cjs/utils/config.d.ts +0 -4
- package/dist/cjs/utils/defineExtension.d.ts +0 -1
- package/dist/cjs/utils/helpers.d.ts +0 -5
- package/dist/cjs/utils/index.d.ts +0 -3
- package/dist/esm/array/array-extensions.d.ts +0 -1
- package/dist/esm/array/index.d.ts +0 -1
- package/dist/esm/core/index.d.ts +0 -2
- package/dist/esm/core/performance.d.ts +0 -17
- package/dist/esm/core/validation.d.ts +0 -4
- package/dist/esm/core/version.d.ts +0 -1
- package/dist/esm/extensions/index.d.ts +0 -4
- package/dist/esm/index.d.ts +0 -61
- package/dist/esm/init/index.d.ts +0 -2
- package/dist/esm/init/initializer.d.ts +0 -3
- package/dist/esm/init/options.d.ts +0 -3
- package/dist/esm/number/index.d.ts +0 -1
- package/dist/esm/number/number-extensions.d.ts +0 -1
- package/dist/esm/object/index.d.ts +0 -1
- package/dist/esm/object/object-extensions.d.ts +0 -1
- package/dist/esm/string/index.d.ts +0 -1
- package/dist/esm/string/string-extensions.d.ts +0 -1
- package/dist/esm/types/extension-types.d.ts +0 -9
- package/dist/esm/types/global-augmentations.d.ts +0 -72
- package/dist/esm/types/index.d.ts +0 -2
- package/dist/esm/utils/config.d.ts +0 -4
- package/dist/esm/utils/defineExtension.d.ts +0 -1
- package/dist/esm/utils/helpers.d.ts +0 -5
- package/dist/esm/utils/index.d.ts +0 -3
package/README.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.extendArray = extendArray;
|
|
4
|
-
const
|
|
4
|
+
const index_js_1 = require("../utils/index.js");
|
|
5
5
|
let arrayExtended = false;
|
|
6
6
|
function extendArray() {
|
|
7
7
|
if (arrayExtended)
|
|
8
8
|
return;
|
|
9
9
|
arrayExtended = true;
|
|
10
|
-
(0,
|
|
10
|
+
(0, index_js_1.defineExtension)(Array.prototype, 'unique', function () {
|
|
11
11
|
return [...new Set(this)];
|
|
12
12
|
});
|
|
13
|
-
(0,
|
|
13
|
+
(0, index_js_1.defineExtension)(Array.prototype, 'shuffle', function () {
|
|
14
14
|
const arr = [...this];
|
|
15
15
|
for (let i = arr.length - 1; i > 0; i--) {
|
|
16
16
|
const j = Math.floor(Math.random() * (i + 1));
|
|
@@ -18,7 +18,7 @@ function extendArray() {
|
|
|
18
18
|
}
|
|
19
19
|
return arr;
|
|
20
20
|
});
|
|
21
|
-
(0,
|
|
21
|
+
(0, index_js_1.defineExtension)(Array.prototype, 'chunk', function (size) {
|
|
22
22
|
if (!Number.isInteger(size) || size <= 0) {
|
|
23
23
|
throw new TypeError(`chunk: size must be a positive integer, got ${size}`);
|
|
24
24
|
}
|
|
@@ -28,7 +28,7 @@ function extendArray() {
|
|
|
28
28
|
}
|
|
29
29
|
return chunks;
|
|
30
30
|
});
|
|
31
|
-
(0,
|
|
31
|
+
(0, index_js_1.defineExtension)(Array.prototype, 'groupBy', function (keyFn) {
|
|
32
32
|
if (typeof keyFn !== 'function') {
|
|
33
33
|
throw new TypeError(`groupBy: keyFn must be a function, got ${typeof keyFn}`);
|
|
34
34
|
}
|
|
@@ -40,28 +40,28 @@ function extendArray() {
|
|
|
40
40
|
return groups;
|
|
41
41
|
}, {});
|
|
42
42
|
});
|
|
43
|
-
(0,
|
|
43
|
+
(0, index_js_1.defineExtension)(Array.prototype, 'sum', function () {
|
|
44
44
|
if (this.length === 0) {
|
|
45
45
|
throw new TypeError('sum: array must contain at least one number');
|
|
46
46
|
}
|
|
47
47
|
return this.reduce((sum, num) => sum + num, 0);
|
|
48
48
|
});
|
|
49
|
-
(0,
|
|
49
|
+
(0, index_js_1.defineExtension)(Array.prototype, 'average', function () {
|
|
50
50
|
if (this.length === 0) {
|
|
51
51
|
throw new TypeError('average: array must contain at least one number');
|
|
52
52
|
}
|
|
53
53
|
return this.reduce((sum, num) => sum + num, 0) / this.length;
|
|
54
54
|
});
|
|
55
|
-
(0,
|
|
55
|
+
(0, index_js_1.defineExtension)(Array.prototype, 'compact', function () {
|
|
56
56
|
return this.filter((item) => item !== null && item !== undefined && item !== '');
|
|
57
57
|
});
|
|
58
|
-
(0,
|
|
58
|
+
(0, index_js_1.defineExtension)(Array.prototype, 'compactTruthy', function () {
|
|
59
59
|
return this.filter(Boolean);
|
|
60
60
|
});
|
|
61
|
-
(0,
|
|
61
|
+
(0, index_js_1.defineExtension)(Array.prototype, 'pluck', function (key) {
|
|
62
62
|
return this.map((item) => item[key]).filter((val) => val !== undefined);
|
|
63
63
|
});
|
|
64
|
-
(0,
|
|
64
|
+
(0, index_js_1.defineExtension)(Array.prototype, 'findLast', function (predicate) {
|
|
65
65
|
if (typeof predicate !== 'function') {
|
|
66
66
|
throw new TypeError(`findLast: predicate must be a function, got ${typeof predicate}`);
|
|
67
67
|
}
|
|
@@ -71,7 +71,7 @@ function extendArray() {
|
|
|
71
71
|
}
|
|
72
72
|
return undefined;
|
|
73
73
|
});
|
|
74
|
-
(0,
|
|
74
|
+
(0, index_js_1.defineExtension)(Array.prototype, 'partition', function (predicate) {
|
|
75
75
|
if (typeof predicate !== 'function') {
|
|
76
76
|
throw new TypeError(`partition: predicate must be a function, got ${typeof predicate}`);
|
|
77
77
|
}
|
|
@@ -80,44 +80,44 @@ function extendArray() {
|
|
|
80
80
|
this.forEach((item) => predicate(item) ? truthy.push(item) : falsy.push(item));
|
|
81
81
|
return [truthy, falsy];
|
|
82
82
|
});
|
|
83
|
-
(0,
|
|
83
|
+
(0, index_js_1.defineExtension)(Array.prototype, 'flatten', function (depth = 1) {
|
|
84
84
|
return depth > 0
|
|
85
85
|
? this.reduce((acc, val) => acc.concat(Array.isArray(val) ? val.flatten(depth - 1) : val), [])
|
|
86
86
|
: this.slice();
|
|
87
87
|
});
|
|
88
|
-
(0,
|
|
88
|
+
(0, index_js_1.defineExtension)(Array.prototype, 'deepFlatten', function () {
|
|
89
89
|
return this.reduce((acc, val) => acc.concat(Array.isArray(val) ? val.deepFlatten() : val), []);
|
|
90
90
|
});
|
|
91
|
-
(0,
|
|
91
|
+
(0, index_js_1.defineExtension)(Array.prototype, 'difference', function (other) {
|
|
92
92
|
if (!Array.isArray(other)) {
|
|
93
93
|
throw new TypeError(`difference: other must be an array, got ${typeof other}`);
|
|
94
94
|
}
|
|
95
95
|
return this.filter((item) => !other.includes(item));
|
|
96
96
|
});
|
|
97
|
-
(0,
|
|
97
|
+
(0, index_js_1.defineExtension)(Array.prototype, 'intersection', function (other) {
|
|
98
98
|
if (!Array.isArray(other)) {
|
|
99
99
|
throw new TypeError(`intersection: other must be an array, got ${typeof other}`);
|
|
100
100
|
}
|
|
101
101
|
return this.filter((item) => other.includes(item));
|
|
102
102
|
});
|
|
103
|
-
(0,
|
|
103
|
+
(0, index_js_1.defineExtension)(Array.prototype, 'union', function (other) {
|
|
104
104
|
if (!Array.isArray(other)) {
|
|
105
105
|
throw new TypeError(`union: other must be an array, got ${typeof other}`);
|
|
106
106
|
}
|
|
107
107
|
return [...new Set([...this, ...other])];
|
|
108
108
|
});
|
|
109
|
-
(0,
|
|
109
|
+
(0, index_js_1.defineExtension)(Array.prototype, 'sample', function () {
|
|
110
110
|
return this.length > 0
|
|
111
111
|
? this[Math.floor(Math.random() * this.length)]
|
|
112
112
|
: undefined;
|
|
113
113
|
});
|
|
114
|
-
(0,
|
|
114
|
+
(0, index_js_1.defineExtension)(Array.prototype, 'take', function (count) {
|
|
115
115
|
return this.slice(0, Math.max(0, count));
|
|
116
116
|
});
|
|
117
|
-
(0,
|
|
117
|
+
(0, index_js_1.defineExtension)(Array.prototype, 'drop', function (count) {
|
|
118
118
|
return this.slice(Math.max(0, count));
|
|
119
119
|
});
|
|
120
|
-
(0,
|
|
120
|
+
(0, index_js_1.defineExtension)(Array.prototype, 'uniqueBy', function (keyFn) {
|
|
121
121
|
if (typeof keyFn !== 'function') {
|
|
122
122
|
throw new TypeError(`uniqueBy: keyFn must be a function, got ${typeof keyFn}`);
|
|
123
123
|
}
|
|
@@ -132,7 +132,7 @@ function extendArray() {
|
|
|
132
132
|
}
|
|
133
133
|
return result;
|
|
134
134
|
});
|
|
135
|
-
(0,
|
|
135
|
+
(0, index_js_1.defineExtension)(Array.prototype, 'sortBy', function (keyFn) {
|
|
136
136
|
if (typeof keyFn !== 'function') {
|
|
137
137
|
throw new TypeError(`sortBy: keyFn must be a function, got ${typeof keyFn}`);
|
|
138
138
|
}
|
|
@@ -146,7 +146,7 @@ function extendArray() {
|
|
|
146
146
|
return 0;
|
|
147
147
|
});
|
|
148
148
|
});
|
|
149
|
-
(0,
|
|
149
|
+
(0, index_js_1.defineExtension)(Array.prototype, 'last', function () {
|
|
150
150
|
return this.length > 0 ? this[this.length - 1] : undefined;
|
|
151
151
|
});
|
|
152
152
|
}
|
package/dist/cjs/array/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.extendArray = void 0;
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "extendArray", { enumerable: true, get: function () { return
|
|
4
|
+
var array_extensions_js_1 = require("./array-extensions.js");
|
|
5
|
+
Object.defineProperty(exports, "extendArray", { enumerable: true, get: function () { return array_extensions_js_1.extendArray; } });
|
package/dist/cjs/core/index.js
CHANGED
|
@@ -15,5 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
// Re-export core utilities
|
|
18
|
-
__exportStar(require("./validation"), exports);
|
|
19
|
-
__exportStar(require("./performance"), exports);
|
|
18
|
+
__exportStar(require("./validation.js"), exports);
|
|
19
|
+
__exportStar(require("./performance.js"), exports);
|
|
@@ -5,7 +5,7 @@ exports.setPerformanceConfig = setPerformanceConfig;
|
|
|
5
5
|
exports.getPerformanceConfig = getPerformanceConfig;
|
|
6
6
|
exports.makeInternalCacheKey = makeInternalCacheKey;
|
|
7
7
|
exports.withCache = withCache;
|
|
8
|
-
const
|
|
8
|
+
const version_js_1 = require("./version.js");
|
|
9
9
|
const defaultConfig = {
|
|
10
10
|
enableCaching: false,
|
|
11
11
|
maxCacheSize: 100,
|
|
@@ -64,7 +64,7 @@ function getOrCreateCache() {
|
|
|
64
64
|
return cache;
|
|
65
65
|
}
|
|
66
66
|
function makeInternalCacheKey(domain, key) {
|
|
67
|
-
const INTERNAL_CACHE_PREFIX = '@js-ext' + (0,
|
|
67
|
+
const INTERNAL_CACHE_PREFIX = '@js-ext' + (0, version_js_1.getPackageVersion)();
|
|
68
68
|
return `${INTERNAL_CACHE_PREFIX}:${domain}:${key}`;
|
|
69
69
|
}
|
|
70
70
|
function withCache(key, fn) {
|
|
@@ -15,7 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
// Re-export all extensions
|
|
18
|
-
__exportStar(require("../string"), exports);
|
|
19
|
-
__exportStar(require("../array"), exports);
|
|
20
|
-
__exportStar(require("../object"), exports);
|
|
21
|
-
__exportStar(require("../number"), exports);
|
|
18
|
+
__exportStar(require("../string/index.js"), exports);
|
|
19
|
+
__exportStar(require("../array/index.js"), exports);
|
|
20
|
+
__exportStar(require("../object/index.js"), exports);
|
|
21
|
+
__exportStar(require("../number/index.js"), exports);
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,77 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
Object.defineProperty(exports, "getPerformanceConfig", { enumerable: true, get: function () { return performance_1.getPerformanceConfig; } });
|
|
16
|
-
Object.defineProperty(exports, "setPerformanceConfig", { enumerable: true, get: function () { return performance_1.setPerformanceConfig; } });
|
|
17
|
-
Object.defineProperty(exports, "withCache", { enumerable: true, get: function () { return performance_1.withCache; } });
|
|
18
|
-
// Import validation utilities
|
|
19
|
-
const validation_1 = require("./core/validation");
|
|
20
|
-
Object.defineProperty(exports, "validateArrayInput", { enumerable: true, get: function () { return validation_1.validateArrayInput; } });
|
|
21
|
-
Object.defineProperty(exports, "validateExtensionInput", { enumerable: true, get: function () { return validation_1.validateExtensionInput; } });
|
|
22
|
-
Object.defineProperty(exports, "validateNumberRange", { enumerable: true, get: function () { return validation_1.validateNumberRange; } });
|
|
23
|
-
Object.defineProperty(exports, "validatePositiveInteger", { enumerable: true, get: function () { return validation_1.validatePositiveInteger; } });
|
|
24
|
-
// Import utility functions
|
|
25
|
-
const config_1 = require("./utils/config");
|
|
26
|
-
Object.defineProperty(exports, "mergeConfigs", { enumerable: true, get: function () { return config_1.mergeConfigs; } });
|
|
27
|
-
Object.defineProperty(exports, "validateConfig", { enumerable: true, get: function () { return config_1.validateConfig; } });
|
|
28
|
-
Object.defineProperty(exports, "validatePerformanceSettings", { enumerable: true, get: function () { return config_1.validatePerformanceSettings; } });
|
|
29
|
-
const helpers_1 = require("./utils/helpers");
|
|
30
|
-
Object.defineProperty(exports, "ensurePositiveInteger", { enumerable: true, get: function () { return helpers_1.ensurePositiveInteger; } });
|
|
31
|
-
Object.defineProperty(exports, "getPathSegments", { enumerable: true, get: function () { return helpers_1.getPathSegments; } });
|
|
32
|
-
Object.defineProperty(exports, "hasOwnProperty", { enumerable: true, get: function () { return helpers_1.hasOwnProperty; } });
|
|
33
|
-
Object.defineProperty(exports, "isValidArrayIndex", { enumerable: true, get: function () { return helpers_1.isValidArrayIndex; } });
|
|
34
|
-
Object.defineProperty(exports, "safeClone", { enumerable: true, get: function () { return helpers_1.safeClone; } });
|
|
35
|
-
// Import initialization functions
|
|
36
|
-
const initializer_1 = require("./init/initializer");
|
|
37
|
-
Object.defineProperty(exports, "extendAll", { enumerable: true, get: function () { return initializer_1.extendAll; } });
|
|
38
|
-
/**
|
|
39
|
-
* Initialize JavaScript prototype extensions
|
|
40
|
-
* @param options - Configure which extensions to enable (default: all enabled)
|
|
41
|
-
*/
|
|
42
|
-
function initializeExtensions(options = {}) {
|
|
43
|
-
(0, initializer_1.initExtensions)(options);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Selective prototype extension helpers
|
|
47
|
-
* Initialize only specific extensions
|
|
48
|
-
*/
|
|
49
|
-
exports.extend = {
|
|
50
|
-
string: string_1.extendString,
|
|
51
|
-
array: array_1.extendArray,
|
|
52
|
-
object: object_1.extendObject,
|
|
53
|
-
number: number_1.extendNumber,
|
|
54
|
-
};
|
|
55
|
-
// Default export
|
|
56
|
-
exports.default = {
|
|
57
|
-
initializeExtensions,
|
|
58
|
-
extendAll: initializer_1.extendAll,
|
|
59
|
-
extend: exports.extend,
|
|
60
|
-
LRUCache: performance_1.LRUCache,
|
|
61
|
-
setPerformanceConfig: performance_1.setPerformanceConfig,
|
|
62
|
-
getPerformanceConfig: performance_1.getPerformanceConfig,
|
|
63
|
-
// Validation utilities
|
|
64
|
-
validateExtensionInput: validation_1.validateExtensionInput,
|
|
65
|
-
validateArrayInput: validation_1.validateArrayInput,
|
|
66
|
-
validateNumberRange: validation_1.validateNumberRange,
|
|
67
|
-
validatePositiveInteger: validation_1.validatePositiveInteger,
|
|
68
|
-
// Utility functions
|
|
69
|
-
validateConfig: config_1.validateConfig,
|
|
70
|
-
validatePerformanceSettings: config_1.validatePerformanceSettings,
|
|
71
|
-
mergeConfigs: config_1.mergeConfigs,
|
|
72
|
-
isValidArrayIndex: helpers_1.isValidArrayIndex,
|
|
73
|
-
ensurePositiveInteger: helpers_1.ensurePositiveInteger,
|
|
74
|
-
safeClone: helpers_1.safeClone,
|
|
75
|
-
getPathSegments: helpers_1.getPathSegments,
|
|
76
|
-
hasOwnProperty: helpers_1.hasOwnProperty,
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
77
15
|
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
// Global type / prototype augmentations
|
|
18
|
+
require("./types/global-augmentations.js");
|
|
19
|
+
// Core language extensions
|
|
20
|
+
__exportStar(require("./array/index.js"), exports);
|
|
21
|
+
__exportStar(require("./number/index.js"), exports);
|
|
22
|
+
__exportStar(require("./string/index.js"), exports);
|
|
23
|
+
__exportStar(require("./object/index.js"), exports);
|
|
24
|
+
// Core framework & utilities
|
|
25
|
+
__exportStar(require("./core/index.js"), exports);
|
|
26
|
+
__exportStar(require("./utils/index.js"), exports);
|
|
27
|
+
// Initialization & setup
|
|
28
|
+
__exportStar(require("./init/index.js"), exports);
|
|
29
|
+
__exportStar(require("./extensions/index.js"), exports);
|
|
30
|
+
// Types
|
|
31
|
+
__exportStar(require("./types/index.js"), exports);
|
package/dist/cjs/init/index.js
CHANGED
|
@@ -15,5 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
// Re-export initialization logic
|
|
18
|
-
__exportStar(require("./initializer"), exports);
|
|
19
|
-
__exportStar(require("./options"), exports);
|
|
18
|
+
__exportStar(require("./initializer.js"), exports);
|
|
19
|
+
__exportStar(require("./options.js"), exports);
|
|
@@ -2,26 +2,25 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.initExtensions = initExtensions;
|
|
4
4
|
exports.extendAll = extendAll;
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const string_1 = require("../string");
|
|
5
|
+
const index_js_1 = require("../array/index.js");
|
|
6
|
+
const index_js_2 = require("../core/index.js");
|
|
7
|
+
const index_js_3 = require("../number/index.js");
|
|
8
|
+
const index_js_4 = require("../object/index.js");
|
|
9
|
+
const index_js_5 = require("../string/index.js");
|
|
11
10
|
function initExtensions(options = {}) {
|
|
12
11
|
const { string = true, array = true, object = true, number = true, performance, } = options;
|
|
13
12
|
if (performance) {
|
|
14
13
|
// Set performance config if provided
|
|
15
|
-
(0,
|
|
14
|
+
(0, index_js_2.setPerformanceConfig)(performance);
|
|
16
15
|
}
|
|
17
16
|
if (string)
|
|
18
|
-
(0,
|
|
17
|
+
(0, index_js_5.extendString)();
|
|
19
18
|
if (array)
|
|
20
|
-
(0,
|
|
19
|
+
(0, index_js_1.extendArray)();
|
|
21
20
|
if (object)
|
|
22
|
-
(0,
|
|
21
|
+
(0, index_js_4.extendObject)();
|
|
23
22
|
if (number)
|
|
24
|
-
(0,
|
|
23
|
+
(0, index_js_3.extendNumber)();
|
|
25
24
|
}
|
|
26
25
|
function extendAll() {
|
|
27
26
|
initExtensions();
|
package/dist/cjs/number/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.extendNumber = void 0;
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "extendNumber", { enumerable: true, get: function () { return
|
|
4
|
+
var number_extensions_js_1 = require("./number-extensions.js");
|
|
5
|
+
Object.defineProperty(exports, "extendNumber", { enumerable: true, get: function () { return number_extensions_js_1.extendNumber; } });
|
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.extendNumber = extendNumber;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const index_js_1 = require("../core/index.js");
|
|
5
|
+
const index_js_2 = require("../utils/index.js");
|
|
6
6
|
let numberExtended = false;
|
|
7
7
|
function extendNumber() {
|
|
8
8
|
if (numberExtended)
|
|
9
9
|
return;
|
|
10
10
|
numberExtended = true;
|
|
11
|
-
(0,
|
|
11
|
+
(0, index_js_2.defineExtension)(Number.prototype, 'toPercent', function (decimals = 2) {
|
|
12
12
|
return `${(this * 100).toFixed(decimals)}%`;
|
|
13
13
|
});
|
|
14
|
-
(0,
|
|
14
|
+
(0, index_js_2.defineExtension)(Number.prototype, 'toCurrency', function (currency = 'USD', locale = 'en-US') {
|
|
15
15
|
return new Intl.NumberFormat(locale, {
|
|
16
16
|
style: 'currency',
|
|
17
17
|
currency,
|
|
18
18
|
}).format(this);
|
|
19
19
|
});
|
|
20
|
-
(0,
|
|
20
|
+
(0, index_js_2.defineExtension)(Number.prototype, 'clamp', function (min, max) {
|
|
21
21
|
if (min > max)
|
|
22
22
|
throw new RangeError(`clamp: min (${min}) cannot be greater than max (${max})`);
|
|
23
23
|
return Math.min(Math.max(this, min), max);
|
|
24
24
|
});
|
|
25
|
-
(0,
|
|
25
|
+
(0, index_js_2.defineExtension)(Number.prototype, 'isEven', function () {
|
|
26
26
|
return this % 2 === 0;
|
|
27
27
|
});
|
|
28
|
-
(0,
|
|
28
|
+
(0, index_js_2.defineExtension)(Number.prototype, 'isOdd', function () {
|
|
29
29
|
return this % 2 !== 0;
|
|
30
30
|
});
|
|
31
|
-
(0,
|
|
31
|
+
(0, index_js_2.defineExtension)(Number.prototype, 'isPrime', function () {
|
|
32
32
|
const num = this;
|
|
33
|
-
return (0,
|
|
33
|
+
return (0, index_js_1.withCache)((0, index_js_1.makeInternalCacheKey)('prime', num), () => {
|
|
34
34
|
if (num < 2)
|
|
35
35
|
return false;
|
|
36
36
|
for (let i = 2; i <= Math.sqrt(num); i++)
|
|
@@ -39,9 +39,9 @@ function extendNumber() {
|
|
|
39
39
|
return true;
|
|
40
40
|
});
|
|
41
41
|
});
|
|
42
|
-
(0,
|
|
42
|
+
(0, index_js_2.defineExtension)(Number.prototype, 'factorial', function () {
|
|
43
43
|
const num = Math.floor(this);
|
|
44
|
-
return (0,
|
|
44
|
+
return (0, index_js_1.withCache)((0, index_js_1.makeInternalCacheKey)('factorial', num), () => {
|
|
45
45
|
if (num < 0)
|
|
46
46
|
return NaN;
|
|
47
47
|
if (num <= 1)
|
|
@@ -52,19 +52,19 @@ function extendNumber() {
|
|
|
52
52
|
return result;
|
|
53
53
|
});
|
|
54
54
|
});
|
|
55
|
-
(0,
|
|
55
|
+
(0, index_js_2.defineExtension)(Number.prototype, 'toOrdinal', function () {
|
|
56
56
|
const num = Math.floor(this);
|
|
57
57
|
const suffix = ['th', 'st', 'nd', 'rd'];
|
|
58
58
|
const v = num % 100;
|
|
59
59
|
return num + (suffix[(v - 20) % 10] || suffix[v] || suffix[0]);
|
|
60
60
|
});
|
|
61
|
-
(0,
|
|
61
|
+
(0, index_js_2.defineExtension)(Number.prototype, 'toRoman', function () {
|
|
62
62
|
const num = Math.floor(this);
|
|
63
63
|
if (num <= 0)
|
|
64
64
|
throw new RangeError('toRoman: number must be positive');
|
|
65
65
|
if (num >= 4000)
|
|
66
66
|
throw new RangeError('toRoman: number must be less than 4000');
|
|
67
|
-
return (0,
|
|
67
|
+
return (0, index_js_1.withCache)((0, index_js_1.makeInternalCacheKey)('roman', num), () => {
|
|
68
68
|
const values = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
|
|
69
69
|
const symbols = [
|
|
70
70
|
'M',
|
|
@@ -92,47 +92,47 @@ function extendNumber() {
|
|
|
92
92
|
return result;
|
|
93
93
|
});
|
|
94
94
|
});
|
|
95
|
-
(0,
|
|
95
|
+
(0, index_js_2.defineExtension)(Number.prototype, 'inRange', function (min, max) {
|
|
96
96
|
return this >= min && this <= max;
|
|
97
97
|
});
|
|
98
|
-
(0,
|
|
98
|
+
(0, index_js_2.defineExtension)(Number.prototype, 'round', function (decimals = 0) {
|
|
99
99
|
if (!Number.isInteger(decimals) || decimals < 0)
|
|
100
100
|
throw new TypeError('round: decimals must be non-negative integer');
|
|
101
101
|
const factor = Math.pow(10, decimals);
|
|
102
102
|
return Math.round(this * factor) / factor;
|
|
103
103
|
});
|
|
104
|
-
(0,
|
|
104
|
+
(0, index_js_2.defineExtension)(Number.prototype, 'ceil', function (decimals = 0) {
|
|
105
105
|
if (!Number.isInteger(decimals) || decimals < 0)
|
|
106
106
|
throw new TypeError('ceil: decimals must be non-negative integer');
|
|
107
107
|
const factor = Math.pow(10, decimals);
|
|
108
108
|
return Math.ceil(this * factor) / factor;
|
|
109
109
|
});
|
|
110
|
-
(0,
|
|
110
|
+
(0, index_js_2.defineExtension)(Number.prototype, 'floor', function (decimals = 0) {
|
|
111
111
|
if (!Number.isInteger(decimals) || decimals < 0)
|
|
112
112
|
throw new TypeError('floor: decimals must be non-negative integer');
|
|
113
113
|
const factor = Math.pow(10, decimals);
|
|
114
114
|
return Math.floor(this * factor) / factor;
|
|
115
115
|
});
|
|
116
|
-
(0,
|
|
116
|
+
(0, index_js_2.defineExtension)(Number.prototype, 'abs', function () {
|
|
117
117
|
return Math.abs(this);
|
|
118
118
|
});
|
|
119
|
-
(0,
|
|
119
|
+
(0, index_js_2.defineExtension)(Number.prototype, 'sign', function () {
|
|
120
120
|
return Math.sign(this);
|
|
121
121
|
});
|
|
122
|
-
(0,
|
|
122
|
+
(0, index_js_2.defineExtension)(Number.prototype, 'times', function (callback) {
|
|
123
123
|
if (typeof callback !== 'function')
|
|
124
124
|
throw new TypeError('times: callback must be a function');
|
|
125
125
|
for (let i = 0; i < Math.floor(this); i++)
|
|
126
126
|
callback(i);
|
|
127
127
|
});
|
|
128
|
-
(0,
|
|
128
|
+
(0, index_js_2.defineExtension)(Number.prototype, 'toFixedNumber', function (decimals = 0) {
|
|
129
129
|
if (!Number.isInteger(decimals) || decimals < 0) {
|
|
130
130
|
throw new TypeError(`toFixedNumber: decimals must be a non-negative integer, got ${decimals}`);
|
|
131
131
|
}
|
|
132
132
|
const factor = Math.pow(10, decimals);
|
|
133
133
|
return Math.round(this.valueOf() * factor) / factor;
|
|
134
134
|
});
|
|
135
|
-
(0,
|
|
135
|
+
(0, index_js_2.defineExtension)(Number.prototype, 'randomUpTo', function () {
|
|
136
136
|
const max = this.valueOf();
|
|
137
137
|
if (!Number.isFinite(max)) {
|
|
138
138
|
throw new TypeError(`randomUpTo: number must be finite, got ${max}`);
|
package/dist/cjs/object/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.extendObject = void 0;
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "extendObject", { enumerable: true, get: function () { return
|
|
4
|
+
var object_extensions_js_1 = require("./object-extensions.js");
|
|
5
|
+
Object.defineProperty(exports, "extendObject", { enumerable: true, get: function () { return object_extensions_js_1.extendObject; } });
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.extendObject = extendObject;
|
|
4
|
-
const
|
|
4
|
+
const index_js_1 = require("../utils/index.js");
|
|
5
5
|
let objectExtended = false;
|
|
6
6
|
function extendObject() {
|
|
7
7
|
if (objectExtended)
|
|
8
8
|
return;
|
|
9
9
|
objectExtended = true;
|
|
10
|
-
(0,
|
|
10
|
+
(0, index_js_1.defineExtension)(Object.prototype, 'isEmpty', function () {
|
|
11
11
|
return Object.keys(this).length === 0;
|
|
12
12
|
});
|
|
13
|
-
(0,
|
|
13
|
+
(0, index_js_1.defineExtension)(Object.prototype, 'pick', function (keys) {
|
|
14
14
|
if (!Array.isArray(keys))
|
|
15
15
|
throw new TypeError('pick: keys must be an array');
|
|
16
16
|
if (!keys.length)
|
|
@@ -22,7 +22,7 @@ function extendObject() {
|
|
|
22
22
|
});
|
|
23
23
|
return result;
|
|
24
24
|
});
|
|
25
|
-
(0,
|
|
25
|
+
(0, index_js_1.defineExtension)(Object.prototype, 'omit', function (keys) {
|
|
26
26
|
if (!Array.isArray(keys))
|
|
27
27
|
throw new TypeError('omit: keys must be an array');
|
|
28
28
|
if (!keys.length)
|
|
@@ -31,7 +31,7 @@ function extendObject() {
|
|
|
31
31
|
keys.forEach((key) => delete result[key]);
|
|
32
32
|
return result;
|
|
33
33
|
});
|
|
34
|
-
(0,
|
|
34
|
+
(0, index_js_1.defineExtension)(Object.prototype, 'deepClone', function () {
|
|
35
35
|
const visited = new WeakSet();
|
|
36
36
|
function deepCloneSafe(obj) {
|
|
37
37
|
if (obj === null || typeof obj !== 'object')
|
|
@@ -51,10 +51,10 @@ function extendObject() {
|
|
|
51
51
|
}
|
|
52
52
|
return deepCloneSafe(this);
|
|
53
53
|
});
|
|
54
|
-
(0,
|
|
54
|
+
(0, index_js_1.defineExtension)(Object.prototype, 'merge', function (other) {
|
|
55
55
|
return { ...this, ...other };
|
|
56
56
|
});
|
|
57
|
-
(0,
|
|
57
|
+
(0, index_js_1.defineExtension)(Object.prototype, 'deepFreeze', function () {
|
|
58
58
|
Object.getOwnPropertyNames(this).forEach((name) => {
|
|
59
59
|
const value = this[name];
|
|
60
60
|
if (value && typeof value === 'object')
|
|
@@ -62,7 +62,7 @@ function extendObject() {
|
|
|
62
62
|
});
|
|
63
63
|
return Object.freeze(this);
|
|
64
64
|
});
|
|
65
|
-
(0,
|
|
65
|
+
(0, index_js_1.defineExtension)(Object.prototype, 'hasPath', function (path) {
|
|
66
66
|
if (!path.trim())
|
|
67
67
|
throw new TypeError('hasPath: path cannot be empty');
|
|
68
68
|
let current = this;
|
|
@@ -73,14 +73,14 @@ function extendObject() {
|
|
|
73
73
|
return true;
|
|
74
74
|
});
|
|
75
75
|
});
|
|
76
|
-
(0,
|
|
76
|
+
(0, index_js_1.defineExtension)(Object.prototype, 'getPath', function (path, defaultValue) {
|
|
77
77
|
if (!path.trim())
|
|
78
78
|
throw new TypeError('getPath: path cannot be empty');
|
|
79
79
|
return path
|
|
80
80
|
.split('.')
|
|
81
81
|
.reduce((acc, key) => (acc && key in acc ? acc[key] : defaultValue), this);
|
|
82
82
|
});
|
|
83
|
-
(0,
|
|
83
|
+
(0, index_js_1.defineExtension)(Object.prototype, 'setPath', function (path, value) {
|
|
84
84
|
if (!path.trim())
|
|
85
85
|
throw new TypeError('setPath: path cannot be empty');
|
|
86
86
|
const keys = path.split('.');
|
|
@@ -93,7 +93,7 @@ function extendObject() {
|
|
|
93
93
|
current[keys[keys.length - 1]] = value;
|
|
94
94
|
return this;
|
|
95
95
|
});
|
|
96
|
-
(0,
|
|
96
|
+
(0, index_js_1.defineExtension)(Object.prototype, 'mapValues', function (fn) {
|
|
97
97
|
if (typeof fn !== 'function') {
|
|
98
98
|
throw new TypeError(`mapValues: fn must be a function, got ${typeof fn}`);
|
|
99
99
|
}
|
|
@@ -105,7 +105,7 @@ function extendObject() {
|
|
|
105
105
|
}
|
|
106
106
|
return result;
|
|
107
107
|
});
|
|
108
|
-
(0,
|
|
108
|
+
(0, index_js_1.defineExtension)(Object.prototype, 'mapKeys', function (fn) {
|
|
109
109
|
if (typeof fn !== 'function') {
|
|
110
110
|
throw new TypeError(`mapKeys: fn must be a function, got ${typeof fn}`);
|
|
111
111
|
}
|
|
@@ -118,7 +118,7 @@ function extendObject() {
|
|
|
118
118
|
}
|
|
119
119
|
return result;
|
|
120
120
|
});
|
|
121
|
-
(0,
|
|
121
|
+
(0, index_js_1.defineExtension)(Object.prototype, 'filterKeys', function (keys) {
|
|
122
122
|
if (!Array.isArray(keys)) {
|
|
123
123
|
throw new TypeError(`filterKeys: keys must be an array, got ${typeof keys}`);
|
|
124
124
|
}
|
|
@@ -130,7 +130,7 @@ function extendObject() {
|
|
|
130
130
|
}
|
|
131
131
|
return result;
|
|
132
132
|
});
|
|
133
|
-
(0,
|
|
133
|
+
(0, index_js_1.defineExtension)(Object.prototype, 'filterValues', function (fn) {
|
|
134
134
|
if (typeof fn !== 'function') {
|
|
135
135
|
throw new TypeError(`filterValues: fn must be a function, got ${typeof fn}`);
|
|
136
136
|
}
|
package/dist/cjs/string/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.extendString = void 0;
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "extendString", { enumerable: true, get: function () { return
|
|
4
|
+
var string_extensions_js_1 = require("./string-extensions.js");
|
|
5
|
+
Object.defineProperty(exports, "extendString", { enumerable: true, get: function () { return string_extensions_js_1.extendString; } });
|