@naman_deep_singh/js-extensions 1.2.0 → 1.3.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/README.md +48 -8
- package/dist/cjs/{array-extensions.js → array/array-extensions.js} +33 -2
- package/dist/cjs/array/index.d.ts +1 -0
- package/dist/cjs/array/index.js +5 -0
- package/dist/cjs/core/index.d.ts +2 -0
- package/dist/cjs/core/index.js +19 -0
- package/dist/cjs/{performance.d.ts → core/performance.d.ts} +1 -3
- package/dist/cjs/{performance.js → core/performance.js} +17 -4
- package/dist/cjs/extensions/index.d.ts +4 -0
- package/dist/cjs/extensions/index.js +21 -0
- package/dist/cjs/index.d.ts +13 -17
- package/dist/cjs/index.js +24 -35
- package/dist/cjs/init/index.d.ts +2 -0
- package/dist/cjs/init/index.js +19 -0
- package/dist/cjs/init/initializer.d.ts +3 -0
- package/dist/cjs/init/initializer.js +27 -0
- package/dist/cjs/init/options.d.ts +3 -0
- package/dist/cjs/init/options.js +23 -0
- package/dist/cjs/number/index.d.ts +1 -0
- package/dist/cjs/number/index.js +5 -0
- package/dist/cjs/{number-extensions.js → number/number-extensions.js} +23 -3
- package/dist/cjs/object/index.d.ts +1 -0
- package/dist/cjs/object/index.js +5 -0
- package/dist/cjs/object/object-extensions.js +146 -0
- package/dist/cjs/string/index.d.ts +1 -0
- package/dist/cjs/string/index.js +5 -0
- package/dist/cjs/{string-extensions.js → string/string-extensions.js} +27 -0
- package/dist/cjs/types/extension-types.d.ts +9 -0
- package/dist/cjs/types/global-augmentations.js +2 -0
- package/dist/cjs/types/index.d.ts +2 -0
- package/dist/cjs/types/index.js +19 -0
- package/dist/cjs/utils/config.d.ts +4 -0
- package/dist/cjs/utils/config.js +25 -0
- package/dist/cjs/utils/helpers.d.ts +5 -0
- package/dist/cjs/utils/helpers.js +37 -0
- package/dist/cjs/utils/index.d.ts +2 -0
- package/dist/cjs/utils/index.js +19 -0
- package/dist/esm/{array-extensions.js → array/array-extensions.js} +33 -2
- package/dist/esm/array/index.d.ts +1 -0
- package/dist/esm/array/index.js +1 -0
- package/dist/esm/core/index.d.ts +2 -0
- package/dist/esm/core/index.js +3 -0
- package/dist/esm/{performance.d.ts → core/performance.d.ts} +1 -3
- package/dist/esm/{performance.js → core/performance.js} +16 -4
- package/dist/esm/extensions/index.d.ts +4 -0
- package/dist/esm/extensions/index.js +5 -0
- package/dist/esm/index.d.ts +13 -17
- package/dist/esm/index.js +16 -23
- package/dist/esm/init/index.d.ts +2 -0
- package/dist/esm/init/index.js +3 -0
- package/dist/esm/init/initializer.d.ts +3 -0
- package/dist/esm/init/initializer.js +23 -0
- package/dist/esm/init/options.d.ts +3 -0
- package/dist/esm/init/options.js +19 -0
- package/dist/esm/number/index.d.ts +1 -0
- package/dist/esm/number/index.js +1 -0
- package/dist/esm/{number-extensions.js → number/number-extensions.js} +23 -3
- package/dist/esm/object/index.d.ts +1 -0
- package/dist/esm/object/index.js +1 -0
- package/dist/esm/object/object-extensions.js +143 -0
- package/dist/esm/string/index.d.ts +1 -0
- package/dist/esm/string/index.js +1 -0
- package/dist/esm/{string-extensions.js → string/string-extensions.js} +27 -0
- package/dist/esm/types/extension-types.d.ts +9 -0
- package/dist/esm/types/global-augmentations.js +1 -0
- package/dist/esm/types/index.d.ts +2 -0
- package/dist/esm/types/index.js +3 -0
- package/dist/esm/utils/config.d.ts +4 -0
- package/dist/esm/utils/config.js +20 -0
- package/dist/esm/utils/helpers.d.ts +5 -0
- package/dist/esm/utils/helpers.js +30 -0
- package/dist/esm/utils/index.d.ts +2 -0
- package/dist/esm/utils/index.js +3 -0
- package/dist/types/array/index.d.ts +1 -0
- package/dist/types/core/index.d.ts +2 -0
- package/dist/types/{performance.d.ts → core/performance.d.ts} +1 -3
- package/dist/types/extensions/index.d.ts +4 -0
- package/dist/types/index.d.ts +13 -17
- package/dist/types/init/index.d.ts +2 -0
- package/dist/types/init/initializer.d.ts +3 -0
- package/dist/types/init/options.d.ts +3 -0
- package/dist/types/number/index.d.ts +1 -0
- package/dist/types/object/index.d.ts +1 -0
- package/dist/types/string/index.d.ts +1 -0
- package/dist/types/types/extension-types.d.ts +9 -0
- package/dist/types/types/index.d.ts +2 -0
- package/dist/types/utils/config.d.ts +4 -0
- package/dist/types/utils/helpers.d.ts +5 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/package.json +1 -1
- package/dist/cjs/object-extensions.js +0 -103
- package/dist/esm/object-extensions.js +0 -100
- /package/dist/cjs/{array-extensions.d.ts → array/array-extensions.d.ts} +0 -0
- /package/dist/cjs/{validation.d.ts → core/validation.d.ts} +0 -0
- /package/dist/cjs/{validation.js → core/validation.js} +0 -0
- /package/dist/cjs/{number-extensions.d.ts → number/number-extensions.d.ts} +0 -0
- /package/dist/cjs/{object-extensions.d.ts → object/object-extensions.d.ts} +0 -0
- /package/dist/cjs/{string-extensions.d.ts → string/string-extensions.d.ts} +0 -0
- /package/dist/cjs/{types.js → types/extension-types.js} +0 -0
- /package/dist/cjs/{types.d.ts → types/global-augmentations.d.ts} +0 -0
- /package/dist/esm/{array-extensions.d.ts → array/array-extensions.d.ts} +0 -0
- /package/dist/esm/{validation.d.ts → core/validation.d.ts} +0 -0
- /package/dist/esm/{validation.js → core/validation.js} +0 -0
- /package/dist/esm/{number-extensions.d.ts → number/number-extensions.d.ts} +0 -0
- /package/dist/esm/{object-extensions.d.ts → object/object-extensions.d.ts} +0 -0
- /package/dist/esm/{string-extensions.d.ts → string/string-extensions.d.ts} +0 -0
- /package/dist/esm/{types.js → types/extension-types.js} +0 -0
- /package/dist/esm/{types.d.ts → types/global-augmentations.d.ts} +0 -0
- /package/dist/types/{array-extensions.d.ts → array/array-extensions.d.ts} +0 -0
- /package/dist/types/{validation.d.ts → core/validation.d.ts} +0 -0
- /package/dist/types/{number-extensions.d.ts → number/number-extensions.d.ts} +0 -0
- /package/dist/types/{object-extensions.d.ts → object/object-extensions.d.ts} +0 -0
- /package/dist/types/{string-extensions.d.ts → string/string-extensions.d.ts} +0 -0
- /package/dist/types/{types.d.ts → types/global-augmentations.d.ts} +0 -0
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extendObject = extendObject;
|
|
4
|
-
// Object prototype extensions
|
|
5
|
-
const performance_1 = require("./performance");
|
|
6
|
-
function extendObject() {
|
|
7
|
-
Object.prototype.isEmpty = function () {
|
|
8
|
-
return Object.keys(this).length === 0;
|
|
9
|
-
};
|
|
10
|
-
Object.prototype.pick = function (keys) {
|
|
11
|
-
const result = {};
|
|
12
|
-
const obj = this;
|
|
13
|
-
keys.forEach(key => {
|
|
14
|
-
if (key in obj) {
|
|
15
|
-
result[key] = obj[key];
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
return result;
|
|
19
|
-
};
|
|
20
|
-
Object.prototype.omit = function (keys) {
|
|
21
|
-
const result = { ...this };
|
|
22
|
-
keys.forEach(key => {
|
|
23
|
-
delete result[key];
|
|
24
|
-
});
|
|
25
|
-
return result;
|
|
26
|
-
};
|
|
27
|
-
Object.prototype.deepClone = function () {
|
|
28
|
-
return (0, performance_1.withCache)(`clone_${JSON.stringify(this)}`, () => {
|
|
29
|
-
if (this === null || typeof this !== 'object')
|
|
30
|
-
return this;
|
|
31
|
-
// Handle Date objects
|
|
32
|
-
if (this instanceof Date)
|
|
33
|
-
return new Date(this.getTime());
|
|
34
|
-
// Handle Array objects
|
|
35
|
-
if (Array.isArray(this)) {
|
|
36
|
-
return this.map(item => {
|
|
37
|
-
if (item && typeof item === 'object' && typeof item.deepClone === 'function') {
|
|
38
|
-
return item.deepClone();
|
|
39
|
-
}
|
|
40
|
-
return item;
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
// Handle regular objects
|
|
44
|
-
const cloned = {};
|
|
45
|
-
Object.keys(this).forEach(key => {
|
|
46
|
-
const value = this[key];
|
|
47
|
-
if (value && typeof value === 'object' && typeof value.deepClone === 'function') {
|
|
48
|
-
cloned[key] = value.deepClone();
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
cloned[key] = value;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
return cloned;
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
Object.prototype.merge = function (other) {
|
|
58
|
-
return { ...this, ...other };
|
|
59
|
-
};
|
|
60
|
-
Object.prototype.deepFreeze = function () {
|
|
61
|
-
const propNames = Object.getOwnPropertyNames(this);
|
|
62
|
-
for (const name of propNames) {
|
|
63
|
-
const value = this[name];
|
|
64
|
-
if (value && typeof value === 'object') {
|
|
65
|
-
value.deepFreeze();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return Object.freeze(this);
|
|
69
|
-
};
|
|
70
|
-
Object.prototype.hasPath = function (path) {
|
|
71
|
-
const keys = path.split('.');
|
|
72
|
-
let current = this;
|
|
73
|
-
for (const key of keys) {
|
|
74
|
-
if (current == null || !(key in current))
|
|
75
|
-
return false;
|
|
76
|
-
current = current[key];
|
|
77
|
-
}
|
|
78
|
-
return true;
|
|
79
|
-
};
|
|
80
|
-
Object.prototype.getPath = function (path, defaultValue) {
|
|
81
|
-
const keys = path.split('.');
|
|
82
|
-
let current = this;
|
|
83
|
-
for (const key of keys) {
|
|
84
|
-
if (current == null || !(key in current))
|
|
85
|
-
return defaultValue;
|
|
86
|
-
current = current[key];
|
|
87
|
-
}
|
|
88
|
-
return current;
|
|
89
|
-
};
|
|
90
|
-
Object.prototype.setPath = function (path, value) {
|
|
91
|
-
const keys = path.split('.');
|
|
92
|
-
let current = this;
|
|
93
|
-
for (let i = 0; i < keys.length - 1; i++) {
|
|
94
|
-
const key = keys[i];
|
|
95
|
-
if (!(key in current) || typeof current[key] !== 'object') {
|
|
96
|
-
current[key] = {};
|
|
97
|
-
}
|
|
98
|
-
current = current[key];
|
|
99
|
-
}
|
|
100
|
-
current[keys[keys.length - 1]] = value;
|
|
101
|
-
return this;
|
|
102
|
-
};
|
|
103
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
// Object prototype extensions
|
|
2
|
-
import { withCache } from './performance';
|
|
3
|
-
export function extendObject() {
|
|
4
|
-
Object.prototype.isEmpty = function () {
|
|
5
|
-
return Object.keys(this).length === 0;
|
|
6
|
-
};
|
|
7
|
-
Object.prototype.pick = function (keys) {
|
|
8
|
-
const result = {};
|
|
9
|
-
const obj = this;
|
|
10
|
-
keys.forEach(key => {
|
|
11
|
-
if (key in obj) {
|
|
12
|
-
result[key] = obj[key];
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
return result;
|
|
16
|
-
};
|
|
17
|
-
Object.prototype.omit = function (keys) {
|
|
18
|
-
const result = { ...this };
|
|
19
|
-
keys.forEach(key => {
|
|
20
|
-
delete result[key];
|
|
21
|
-
});
|
|
22
|
-
return result;
|
|
23
|
-
};
|
|
24
|
-
Object.prototype.deepClone = function () {
|
|
25
|
-
return withCache(`clone_${JSON.stringify(this)}`, () => {
|
|
26
|
-
if (this === null || typeof this !== 'object')
|
|
27
|
-
return this;
|
|
28
|
-
// Handle Date objects
|
|
29
|
-
if (this instanceof Date)
|
|
30
|
-
return new Date(this.getTime());
|
|
31
|
-
// Handle Array objects
|
|
32
|
-
if (Array.isArray(this)) {
|
|
33
|
-
return this.map(item => {
|
|
34
|
-
if (item && typeof item === 'object' && typeof item.deepClone === 'function') {
|
|
35
|
-
return item.deepClone();
|
|
36
|
-
}
|
|
37
|
-
return item;
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
// Handle regular objects
|
|
41
|
-
const cloned = {};
|
|
42
|
-
Object.keys(this).forEach(key => {
|
|
43
|
-
const value = this[key];
|
|
44
|
-
if (value && typeof value === 'object' && typeof value.deepClone === 'function') {
|
|
45
|
-
cloned[key] = value.deepClone();
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
cloned[key] = value;
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
return cloned;
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
Object.prototype.merge = function (other) {
|
|
55
|
-
return { ...this, ...other };
|
|
56
|
-
};
|
|
57
|
-
Object.prototype.deepFreeze = function () {
|
|
58
|
-
const propNames = Object.getOwnPropertyNames(this);
|
|
59
|
-
for (const name of propNames) {
|
|
60
|
-
const value = this[name];
|
|
61
|
-
if (value && typeof value === 'object') {
|
|
62
|
-
value.deepFreeze();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return Object.freeze(this);
|
|
66
|
-
};
|
|
67
|
-
Object.prototype.hasPath = function (path) {
|
|
68
|
-
const keys = path.split('.');
|
|
69
|
-
let current = this;
|
|
70
|
-
for (const key of keys) {
|
|
71
|
-
if (current == null || !(key in current))
|
|
72
|
-
return false;
|
|
73
|
-
current = current[key];
|
|
74
|
-
}
|
|
75
|
-
return true;
|
|
76
|
-
};
|
|
77
|
-
Object.prototype.getPath = function (path, defaultValue) {
|
|
78
|
-
const keys = path.split('.');
|
|
79
|
-
let current = this;
|
|
80
|
-
for (const key of keys) {
|
|
81
|
-
if (current == null || !(key in current))
|
|
82
|
-
return defaultValue;
|
|
83
|
-
current = current[key];
|
|
84
|
-
}
|
|
85
|
-
return current;
|
|
86
|
-
};
|
|
87
|
-
Object.prototype.setPath = function (path, value) {
|
|
88
|
-
const keys = path.split('.');
|
|
89
|
-
let current = this;
|
|
90
|
-
for (let i = 0; i < keys.length - 1; i++) {
|
|
91
|
-
const key = keys[i];
|
|
92
|
-
if (!(key in current) || typeof current[key] !== 'object') {
|
|
93
|
-
current[key] = {};
|
|
94
|
-
}
|
|
95
|
-
current = current[key];
|
|
96
|
-
}
|
|
97
|
-
current[keys[keys.length - 1]] = value;
|
|
98
|
-
return this;
|
|
99
|
-
};
|
|
100
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|