@naman_deep_singh/js-extensions 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/README.md +48 -8
  2. package/dist/cjs/{array-extensions.js → array/array-extensions.js} +33 -2
  3. package/dist/cjs/array/index.d.ts +1 -0
  4. package/dist/cjs/array/index.js +5 -0
  5. package/dist/cjs/core/index.d.ts +2 -0
  6. package/dist/cjs/core/index.js +19 -0
  7. package/dist/cjs/{performance.d.ts → core/performance.d.ts} +0 -10
  8. package/dist/cjs/{performance.js → core/performance.js} +15 -4
  9. package/dist/cjs/extensions/index.d.ts +4 -0
  10. package/dist/cjs/extensions/index.js +21 -0
  11. package/dist/cjs/index.d.ts +13 -17
  12. package/dist/cjs/index.js +24 -35
  13. package/dist/cjs/init/index.d.ts +2 -0
  14. package/dist/cjs/init/index.js +19 -0
  15. package/dist/cjs/init/initializer.d.ts +3 -0
  16. package/dist/cjs/init/initializer.js +27 -0
  17. package/dist/cjs/init/options.d.ts +3 -0
  18. package/dist/cjs/init/options.js +23 -0
  19. package/dist/cjs/number/index.d.ts +1 -0
  20. package/dist/cjs/number/index.js +5 -0
  21. package/dist/cjs/{number-extensions.js → number/number-extensions.js} +23 -3
  22. package/dist/cjs/object/index.d.ts +1 -0
  23. package/dist/cjs/object/index.js +5 -0
  24. package/dist/cjs/object/object-extensions.js +146 -0
  25. package/dist/cjs/string/index.d.ts +1 -0
  26. package/dist/cjs/string/index.js +5 -0
  27. package/dist/cjs/{string-extensions.js → string/string-extensions.js} +27 -0
  28. package/dist/cjs/types/extension-types.d.ts +9 -0
  29. package/dist/cjs/types/global-augmentations.js +2 -0
  30. package/dist/cjs/types/index.d.ts +2 -0
  31. package/dist/cjs/types/index.js +19 -0
  32. package/dist/cjs/utils/config.d.ts +4 -0
  33. package/dist/cjs/utils/config.js +25 -0
  34. package/dist/cjs/utils/helpers.d.ts +5 -0
  35. package/dist/cjs/utils/helpers.js +37 -0
  36. package/dist/cjs/utils/index.d.ts +2 -0
  37. package/dist/cjs/utils/index.js +19 -0
  38. package/dist/esm/{array-extensions.js → array/array-extensions.js} +33 -2
  39. package/dist/esm/array/index.d.ts +1 -0
  40. package/dist/esm/array/index.js +1 -0
  41. package/dist/esm/core/index.d.ts +2 -0
  42. package/dist/esm/core/index.js +3 -0
  43. package/dist/esm/{performance.d.ts → core/performance.d.ts} +0 -10
  44. package/dist/esm/{performance.js → core/performance.js} +15 -3
  45. package/dist/esm/extensions/index.d.ts +4 -0
  46. package/dist/esm/extensions/index.js +5 -0
  47. package/dist/esm/index.d.ts +13 -17
  48. package/dist/esm/index.js +16 -23
  49. package/dist/esm/init/index.d.ts +2 -0
  50. package/dist/esm/init/index.js +3 -0
  51. package/dist/esm/init/initializer.d.ts +3 -0
  52. package/dist/esm/init/initializer.js +23 -0
  53. package/dist/esm/init/options.d.ts +3 -0
  54. package/dist/esm/init/options.js +19 -0
  55. package/dist/esm/number/index.d.ts +1 -0
  56. package/dist/esm/number/index.js +1 -0
  57. package/dist/esm/{number-extensions.js → number/number-extensions.js} +23 -3
  58. package/dist/esm/object/index.d.ts +1 -0
  59. package/dist/esm/object/index.js +1 -0
  60. package/dist/esm/object/object-extensions.js +143 -0
  61. package/dist/esm/string/index.d.ts +1 -0
  62. package/dist/esm/string/index.js +1 -0
  63. package/dist/esm/{string-extensions.js → string/string-extensions.js} +27 -0
  64. package/dist/esm/types/extension-types.d.ts +9 -0
  65. package/dist/esm/types/global-augmentations.js +1 -0
  66. package/dist/esm/types/index.d.ts +2 -0
  67. package/dist/esm/types/index.js +3 -0
  68. package/dist/esm/utils/config.d.ts +4 -0
  69. package/dist/esm/utils/config.js +20 -0
  70. package/dist/esm/utils/helpers.d.ts +5 -0
  71. package/dist/esm/utils/helpers.js +30 -0
  72. package/dist/esm/utils/index.d.ts +2 -0
  73. package/dist/esm/utils/index.js +3 -0
  74. package/dist/types/array/index.d.ts +1 -0
  75. package/dist/types/core/index.d.ts +2 -0
  76. package/dist/types/{performance.d.ts → core/performance.d.ts} +0 -10
  77. package/dist/types/extensions/index.d.ts +4 -0
  78. package/dist/types/index.d.ts +13 -17
  79. package/dist/types/init/index.d.ts +2 -0
  80. package/dist/types/init/initializer.d.ts +3 -0
  81. package/dist/types/init/options.d.ts +3 -0
  82. package/dist/types/number/index.d.ts +1 -0
  83. package/dist/types/object/index.d.ts +1 -0
  84. package/dist/types/string/index.d.ts +1 -0
  85. package/dist/types/types/extension-types.d.ts +9 -0
  86. package/dist/types/types/index.d.ts +2 -0
  87. package/dist/types/utils/config.d.ts +4 -0
  88. package/dist/types/utils/helpers.d.ts +5 -0
  89. package/dist/types/utils/index.d.ts +2 -0
  90. package/package.json +1 -1
  91. package/dist/cjs/object-extensions.js +0 -103
  92. package/dist/esm/object-extensions.js +0 -100
  93. /package/dist/cjs/{array-extensions.d.ts → array/array-extensions.d.ts} +0 -0
  94. /package/dist/cjs/{validation.d.ts → core/validation.d.ts} +0 -0
  95. /package/dist/cjs/{validation.js → core/validation.js} +0 -0
  96. /package/dist/cjs/{number-extensions.d.ts → number/number-extensions.d.ts} +0 -0
  97. /package/dist/cjs/{object-extensions.d.ts → object/object-extensions.d.ts} +0 -0
  98. /package/dist/cjs/{string-extensions.d.ts → string/string-extensions.d.ts} +0 -0
  99. /package/dist/cjs/{types.js → types/extension-types.js} +0 -0
  100. /package/dist/cjs/{types.d.ts → types/global-augmentations.d.ts} +0 -0
  101. /package/dist/esm/{array-extensions.d.ts → array/array-extensions.d.ts} +0 -0
  102. /package/dist/esm/{validation.d.ts → core/validation.d.ts} +0 -0
  103. /package/dist/esm/{validation.js → core/validation.js} +0 -0
  104. /package/dist/esm/{number-extensions.d.ts → number/number-extensions.d.ts} +0 -0
  105. /package/dist/esm/{object-extensions.d.ts → object/object-extensions.d.ts} +0 -0
  106. /package/dist/esm/{string-extensions.d.ts → string/string-extensions.d.ts} +0 -0
  107. /package/dist/esm/{types.js → types/extension-types.js} +0 -0
  108. /package/dist/esm/{types.d.ts → types/global-augmentations.d.ts} +0 -0
  109. /package/dist/types/{array-extensions.d.ts → array/array-extensions.d.ts} +0 -0
  110. /package/dist/types/{validation.d.ts → core/validation.d.ts} +0 -0
  111. /package/dist/types/{number-extensions.d.ts → number/number-extensions.d.ts} +0 -0
  112. /package/dist/types/{object-extensions.d.ts → object/object-extensions.d.ts} +0 -0
  113. /package/dist/types/{string-extensions.d.ts → string/string-extensions.d.ts} +0 -0
  114. /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