@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
@@ -0,0 +1,23 @@
1
+ import { extendString } from '../string';
2
+ import { extendArray } from '../array';
3
+ import { extendObject } from '../object';
4
+ import { extendNumber } from '../number';
5
+ import { setPerformanceConfig } from '../core/performance';
6
+ export function initExtensions(options = {}) {
7
+ const { string = true, array = true, object = true, number = true, performance } = options;
8
+ if (performance) {
9
+ // Set performance config if provided
10
+ setPerformanceConfig(performance);
11
+ }
12
+ if (string)
13
+ extendString();
14
+ if (array)
15
+ extendArray();
16
+ if (object)
17
+ extendObject();
18
+ if (number)
19
+ extendNumber();
20
+ }
21
+ export function extendAll() {
22
+ initExtensions();
23
+ }
@@ -0,0 +1,3 @@
1
+ import { ExtensionOptions } from '../types/extension-types';
2
+ export declare function validateExtensionOptions(options: Partial<ExtensionOptions>): ExtensionOptions;
3
+ export declare function createExtensionOptions(enableString?: boolean, enableArray?: boolean, enableObject?: boolean, enableNumber?: boolean, performanceConfig?: any): ExtensionOptions;
@@ -0,0 +1,19 @@
1
+ export function validateExtensionOptions(options) {
2
+ const validated = {
3
+ string: options.string !== false,
4
+ array: options.array !== false,
5
+ object: options.object !== false,
6
+ number: options.number !== false,
7
+ performance: options.performance
8
+ };
9
+ return validated;
10
+ }
11
+ export function createExtensionOptions(enableString = true, enableArray = true, enableObject = true, enableNumber = true, performanceConfig) {
12
+ return {
13
+ string: enableString,
14
+ array: enableArray,
15
+ object: enableObject,
16
+ number: enableNumber,
17
+ performance: performanceConfig
18
+ };
19
+ }
@@ -0,0 +1 @@
1
+ export { extendNumber } from './number-extensions';
@@ -0,0 +1 @@
1
+ export { extendNumber } from './number-extensions';
@@ -1,5 +1,5 @@
1
1
  // Number prototype extensions
2
- import { withCache } from './performance';
2
+ import { withCache } from '../core/performance';
3
3
  export function extendNumber() {
4
4
  Number.prototype.toPercent = function (decimals = 2) {
5
5
  return (this.valueOf() * 100).toFixed(decimals) + '%';
@@ -11,6 +11,9 @@ export function extendNumber() {
11
11
  }).format(this.valueOf());
12
12
  };
13
13
  Number.prototype.clamp = function (min, max) {
14
+ if (min > max) {
15
+ throw new RangeError(`clamp: min (${min}) cannot be greater than max (${max})`);
16
+ }
14
17
  return Math.min(Math.max(this.valueOf(), min), max);
15
18
  };
16
19
  Number.prototype.isEven = function () {
@@ -53,9 +56,14 @@ export function extendNumber() {
53
56
  };
54
57
  Number.prototype.toRoman = function () {
55
58
  const num = Math.floor(this.valueOf());
59
+ // Better validation for roman numerals
60
+ if (num <= 0) {
61
+ throw new RangeError('toRoman: number must be positive');
62
+ }
63
+ if (num >= 4000) {
64
+ throw new RangeError('toRoman: number must be less than 4000');
65
+ }
56
66
  return withCache(`roman_${num}`, () => {
57
- if (num <= 0 || num >= 4000)
58
- return num.toString();
59
67
  const values = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
60
68
  const symbols = ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I'];
61
69
  let result = '';
@@ -74,14 +82,23 @@ export function extendNumber() {
74
82
  return num >= min && num <= max;
75
83
  };
76
84
  Number.prototype.round = function (decimals = 0) {
85
+ if (!Number.isInteger(decimals) || decimals < 0) {
86
+ throw new TypeError(`round: decimals must be a non-negative integer, got ${decimals}`);
87
+ }
77
88
  const factor = Math.pow(10, decimals);
78
89
  return Math.round(this.valueOf() * factor) / factor;
79
90
  };
80
91
  Number.prototype.ceil = function (decimals = 0) {
92
+ if (!Number.isInteger(decimals) || decimals < 0) {
93
+ throw new TypeError(`ceil: decimals must be a non-negative integer, got ${decimals}`);
94
+ }
81
95
  const factor = Math.pow(10, decimals);
82
96
  return Math.ceil(this.valueOf() * factor) / factor;
83
97
  };
84
98
  Number.prototype.floor = function (decimals = 0) {
99
+ if (!Number.isInteger(decimals) || decimals < 0) {
100
+ throw new TypeError(`floor: decimals must be a non-negative integer, got ${decimals}`);
101
+ }
85
102
  const factor = Math.pow(10, decimals);
86
103
  return Math.floor(this.valueOf() * factor) / factor;
87
104
  };
@@ -92,6 +109,9 @@ export function extendNumber() {
92
109
  return Math.sign(this.valueOf());
93
110
  };
94
111
  Number.prototype.times = function (callback) {
112
+ if (typeof callback !== 'function') {
113
+ throw new TypeError(`times: callback must be a function, got ${typeof callback}`);
114
+ }
95
115
  const num = Math.floor(this.valueOf());
96
116
  for (let i = 0; i < num; i++) {
97
117
  callback(i);
@@ -0,0 +1 @@
1
+ export { extendObject } from './object-extensions';
@@ -0,0 +1 @@
1
+ export { extendObject } from './object-extensions';
@@ -0,0 +1,143 @@
1
+ export function extendObject() {
2
+ Object.prototype.isEmpty = function () {
3
+ return Object.keys(this).length === 0;
4
+ };
5
+ Object.prototype.pick = function (keys) {
6
+ if (this === null || this === undefined) {
7
+ throw new TypeError('pick: cannot be called on null or undefined');
8
+ }
9
+ if (!Array.isArray(keys)) {
10
+ throw new TypeError(`pick: keys must be an array, got ${typeof keys}`);
11
+ }
12
+ if (keys.length === 0) {
13
+ throw new TypeError('pick: keys array cannot be empty');
14
+ }
15
+ const result = {};
16
+ const obj = this;
17
+ keys.forEach(key => {
18
+ if (key in obj) {
19
+ result[key] = obj[key];
20
+ }
21
+ });
22
+ return result;
23
+ };
24
+ Object.prototype.omit = function (keys) {
25
+ if (this === null || this === undefined) {
26
+ throw new TypeError('omit: cannot be called on null or undefined');
27
+ }
28
+ if (!Array.isArray(keys)) {
29
+ throw new TypeError(`omit: keys must be an array, got ${typeof keys}`);
30
+ }
31
+ if (keys.length === 0) {
32
+ throw new TypeError('omit: keys array cannot be empty');
33
+ }
34
+ const result = { ...this };
35
+ keys.forEach(key => {
36
+ delete result[key];
37
+ });
38
+ return result;
39
+ };
40
+ Object.prototype.deepClone = function () {
41
+ // Create a more robust cache key using WeakMap for cycle detection
42
+ const cloneId = Symbol('clone');
43
+ // Simple cycle detection without caching key generation
44
+ if (this === null || typeof this !== 'object')
45
+ return this;
46
+ // Handle Date objects
47
+ if (this instanceof Date)
48
+ return new Date(this.getTime());
49
+ // Handle Array objects
50
+ if (Array.isArray(this)) {
51
+ return this.map(item => {
52
+ if (item && typeof item === 'object' && typeof item.deepClone === 'function') {
53
+ return item.deepClone();
54
+ }
55
+ return item;
56
+ });
57
+ }
58
+ // Handle regular objects with better cycle detection
59
+ const visited = new WeakSet();
60
+ function deepCloneSafe(obj) {
61
+ if (obj === null || typeof obj !== 'object')
62
+ return obj;
63
+ if (visited.has(obj)) {
64
+ throw new Error('Circular reference detected in deepClone');
65
+ }
66
+ visited.add(obj);
67
+ if (obj instanceof Date)
68
+ return new Date(obj.getTime());
69
+ if (Array.isArray(obj))
70
+ return obj.map(item => deepCloneSafe(item));
71
+ const cloned = {};
72
+ Object.keys(obj).forEach(key => {
73
+ cloned[key] = deepCloneSafe(obj[key]);
74
+ });
75
+ return cloned;
76
+ }
77
+ return deepCloneSafe(this);
78
+ };
79
+ Object.prototype.merge = function (other) {
80
+ return { ...this, ...other };
81
+ };
82
+ Object.prototype.deepFreeze = function () {
83
+ const propNames = Object.getOwnPropertyNames(this);
84
+ for (const name of propNames) {
85
+ const value = this[name];
86
+ if (value && typeof value === 'object') {
87
+ value.deepFreeze();
88
+ }
89
+ }
90
+ return Object.freeze(this);
91
+ };
92
+ Object.prototype.hasPath = function (path) {
93
+ if (typeof path !== 'string') {
94
+ throw new TypeError(`hasPath: path must be a string, got ${typeof path}`);
95
+ }
96
+ if (path.trim() === '') {
97
+ throw new TypeError('hasPath: path cannot be empty or whitespace');
98
+ }
99
+ const keys = path.split('.');
100
+ let current = this;
101
+ for (const key of keys) {
102
+ if (current == null || !(key in current))
103
+ return false;
104
+ current = current[key];
105
+ }
106
+ return true;
107
+ };
108
+ Object.prototype.getPath = function (path, defaultValue) {
109
+ if (typeof path !== 'string') {
110
+ throw new TypeError(`getPath: path must be a string, got ${typeof path}`);
111
+ }
112
+ if (path.trim() === '') {
113
+ throw new TypeError('getPath: path cannot be empty or whitespace');
114
+ }
115
+ const keys = path.split('.');
116
+ let current = this;
117
+ for (const key of keys) {
118
+ if (current == null || !(key in current))
119
+ return defaultValue;
120
+ current = current[key];
121
+ }
122
+ return current;
123
+ };
124
+ Object.prototype.setPath = function (path, value) {
125
+ if (typeof path !== 'string') {
126
+ throw new TypeError(`setPath: path must be a string, got ${typeof path}`);
127
+ }
128
+ if (path.trim() === '') {
129
+ throw new TypeError('setPath: path cannot be empty or whitespace');
130
+ }
131
+ const keys = path.split('.');
132
+ let current = this;
133
+ for (let i = 0; i < keys.length - 1; i++) {
134
+ const key = keys[i];
135
+ if (!(key in current) || typeof current[key] !== 'object') {
136
+ current[key] = {};
137
+ }
138
+ current = current[key];
139
+ }
140
+ current[keys[keys.length - 1]] = value;
141
+ return this;
142
+ };
143
+ }
@@ -0,0 +1 @@
1
+ export { extendString } from './string-extensions';
@@ -0,0 +1 @@
1
+ export { extendString } from './string-extensions';
@@ -17,6 +17,9 @@ export function extendString() {
17
17
  .toLowerCase();
18
18
  };
19
19
  String.prototype.truncate = function (length, suffix = '...') {
20
+ if (!Number.isInteger(length) || length < 0) {
21
+ throw new TypeError(`truncate: length must be a non-negative integer, got ${length}`);
22
+ }
20
23
  return this.length > length ? this.substring(0, length) + suffix : this.toString();
21
24
  };
22
25
  String.prototype.isEmail = function () {
@@ -49,12 +52,36 @@ export function extendString() {
49
52
  return this.replace(/<[^>]*>/g, '');
50
53
  };
51
54
  String.prototype.padStart = function (targetLength, padString = ' ') {
55
+ if (!Number.isInteger(targetLength) || targetLength < 0) {
56
+ throw new TypeError(`padStart: targetLength must be a non-negative integer, got ${targetLength}`);
57
+ }
58
+ if (typeof padString !== 'string') {
59
+ throw new TypeError(`padStart: padString must be a string, got ${typeof padString}`);
60
+ }
61
+ if (padString.length === 0) {
62
+ throw new TypeError('padStart: padString cannot be empty');
63
+ }
52
64
  return this.toString().padStart(targetLength, padString);
53
65
  };
54
66
  String.prototype.padEnd = function (targetLength, padString = ' ') {
67
+ if (!Number.isInteger(targetLength) || targetLength < 0) {
68
+ throw new TypeError(`padEnd: targetLength must be a non-negative integer, got ${targetLength}`);
69
+ }
70
+ if (typeof padString !== 'string') {
71
+ throw new TypeError(`padEnd: padString must be a string, got ${typeof padString}`);
72
+ }
73
+ if (padString.length === 0) {
74
+ throw new TypeError('padEnd: padString cannot be empty');
75
+ }
55
76
  return this.toString().padEnd(targetLength, padString);
56
77
  };
57
78
  String.prototype.count = function (substring) {
79
+ if (typeof substring !== 'string') {
80
+ throw new TypeError(`count: substring must be a string, got ${typeof substring}`);
81
+ }
82
+ if (substring === '') {
83
+ throw new TypeError('count: substring cannot be empty');
84
+ }
58
85
  return (this.match(new RegExp(substring, 'g')) || []).length;
59
86
  };
60
87
  String.prototype.words = function () {
@@ -0,0 +1,9 @@
1
+ import { PerformanceConfig } from '../core/performance';
2
+ export interface ExtensionOptions {
3
+ string?: boolean;
4
+ array?: boolean;
5
+ object?: boolean;
6
+ number?: boolean;
7
+ performance?: PerformanceConfig;
8
+ }
9
+ export { PerformanceConfig };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from './extension-types';
2
+ export * from './global-augmentations';
@@ -0,0 +1,3 @@
1
+ // Re-export all types
2
+ export * from './extension-types';
3
+ export * from './global-augmentations';
@@ -0,0 +1,4 @@
1
+ import { PerformanceConfig } from '../core/performance';
2
+ export declare function validateConfig(config: Partial<PerformanceConfig>, defaultConfig: PerformanceConfig): PerformanceConfig;
3
+ export declare function validatePerformanceSettings(settings: Partial<PerformanceConfig>): PerformanceConfig;
4
+ export declare function mergeConfigs<T extends Record<string, any>>(base: T, override: Partial<T>): T;
@@ -0,0 +1,20 @@
1
+ export function validateConfig(config, defaultConfig) {
2
+ return { ...defaultConfig, ...config };
3
+ }
4
+ export function validatePerformanceSettings(settings) {
5
+ const validated = {
6
+ enableCaching: settings.enableCaching ?? false,
7
+ maxCacheSize: Math.max(1, settings.maxCacheSize ?? 100),
8
+ enableValidation: settings.enableValidation ?? true
9
+ };
10
+ return validated;
11
+ }
12
+ export function mergeConfigs(base, override) {
13
+ const result = { ...base };
14
+ for (const key in override) {
15
+ if (override[key] !== undefined) {
16
+ result[key] = override[key];
17
+ }
18
+ }
19
+ return result;
20
+ }
@@ -0,0 +1,5 @@
1
+ export declare function isValidArrayIndex(index: number): boolean;
2
+ export declare function ensurePositiveInteger(value: number, name: string): void;
3
+ export declare function safeClone<T>(obj: T): T;
4
+ export declare function getPathSegments(path: string): string[];
5
+ export declare function hasOwnProperty(obj: any, key: string): boolean;
@@ -0,0 +1,30 @@
1
+ // Shared helper functions for extensions
2
+ export function isValidArrayIndex(index) {
3
+ return Number.isInteger(index) && index >= 0;
4
+ }
5
+ export function ensurePositiveInteger(value, name) {
6
+ if (!Number.isInteger(value) || value < 0) {
7
+ throw new TypeError(`${name} must be a positive integer`);
8
+ }
9
+ }
10
+ export function safeClone(obj) {
11
+ if (obj === null || typeof obj !== 'object')
12
+ return obj;
13
+ if (obj instanceof Date)
14
+ return new Date(obj.getTime());
15
+ if (Array.isArray(obj))
16
+ return obj.map(item => safeClone(item));
17
+ const cloned = {};
18
+ for (const key in obj) {
19
+ if (obj.hasOwnProperty(key)) {
20
+ cloned[key] = safeClone(obj[key]);
21
+ }
22
+ }
23
+ return cloned;
24
+ }
25
+ export function getPathSegments(path) {
26
+ return path.split('.').filter(segment => segment.length > 0);
27
+ }
28
+ export function hasOwnProperty(obj, key) {
29
+ return Object.prototype.hasOwnProperty.call(obj, key);
30
+ }
@@ -0,0 +1,2 @@
1
+ export * from './config';
2
+ export * from './helpers';
@@ -0,0 +1,3 @@
1
+ // Re-export all utilities
2
+ export * from './config';
3
+ export * from './helpers';
@@ -0,0 +1 @@
1
+ export { extendArray } from './array-extensions';
@@ -0,0 +1,2 @@
1
+ export * from './validation';
2
+ export * from './performance';
@@ -5,14 +5,4 @@ export interface PerformanceConfig {
5
5
  }
6
6
  export declare function setPerformanceConfig(newConfig: Partial<PerformanceConfig>): void;
7
7
  export declare function getPerformanceConfig(): PerformanceConfig;
8
- declare class LRUCache<K, V> {
9
- private cache;
10
- private maxSize;
11
- constructor(maxSize?: number);
12
- get(key: K): V | undefined;
13
- set(key: K, value: V): void;
14
- clear(): void;
15
- }
16
- export declare const cache: LRUCache<unknown, unknown>;
17
8
  export declare function withCache<T>(key: string, fn: () => T): T;
18
- export {};
@@ -0,0 +1,4 @@
1
+ export * from '../string';
2
+ export * from '../array';
3
+ export * from '../object';
4
+ export * from '../number';
@@ -1,26 +1,22 @@
1
- import { extendString } from './string-extensions';
2
- import { extendArray } from './array-extensions';
3
- import { extendObject } from './object-extensions';
4
- import { extendNumber } from './number-extensions';
5
- import { setPerformanceConfig, getPerformanceConfig, type PerformanceConfig, withCache } from './performance';
6
- import './types';
1
+ import '../types/global-augmentations';
2
+ import { extendString } from './string';
3
+ import { extendArray } from './array';
4
+ import { extendObject } from './object';
5
+ import { extendNumber } from './number';
6
+ import { withCache, setPerformanceConfig, getPerformanceConfig } from './core/performance';
7
+ import { ExtensionOptions, PerformanceConfig } from './types/extension-types';
8
+ export { ExtensionOptions, PerformanceConfig };
7
9
  export { withCache };
8
- export interface ExtensionOptions {
9
- string?: boolean;
10
- array?: boolean;
11
- object?: boolean;
12
- number?: boolean;
13
- performance?: PerformanceConfig;
14
- }
10
+ import { extendAll } from './init/initializer';
15
11
  /**
16
12
  * Initialize JavaScript prototype extensions
17
13
  * @param options - Configure which extensions to enable (default: all enabled)
18
14
  */
19
- export declare function initExtensions(options?: ExtensionOptions): void;
15
+ export declare function initializeExtensions(options?: ExtensionOptions): void;
20
16
  /**
21
17
  * Initialize all extensions (convenience function)
22
18
  */
23
- export declare function extendAll(): void;
19
+ export { extendAll };
24
20
  /**
25
21
  * Initialize only specific extensions
26
22
  */
@@ -30,9 +26,9 @@ export declare const extend: {
30
26
  object: typeof extendObject;
31
27
  number: typeof extendNumber;
32
28
  };
33
- export { setPerformanceConfig, getPerformanceConfig, type PerformanceConfig };
29
+ export { setPerformanceConfig, getPerformanceConfig };
34
30
  declare const _default: {
35
- initExtensions: typeof initExtensions;
31
+ initializeExtensions: typeof initializeExtensions;
36
32
  extendAll: typeof extendAll;
37
33
  extend: {
38
34
  string: typeof extendString;
@@ -0,0 +1,2 @@
1
+ export * from './initializer';
2
+ export * from './options';
@@ -0,0 +1,3 @@
1
+ import { ExtensionOptions } from '../types/extension-types';
2
+ export declare function initExtensions(options?: ExtensionOptions): void;
3
+ export declare function extendAll(): void;
@@ -0,0 +1,3 @@
1
+ import { ExtensionOptions } from '../types/extension-types';
2
+ export declare function validateExtensionOptions(options: Partial<ExtensionOptions>): ExtensionOptions;
3
+ export declare function createExtensionOptions(enableString?: boolean, enableArray?: boolean, enableObject?: boolean, enableNumber?: boolean, performanceConfig?: any): ExtensionOptions;
@@ -0,0 +1 @@
1
+ export { extendNumber } from './number-extensions';
@@ -0,0 +1 @@
1
+ export { extendObject } from './object-extensions';
@@ -0,0 +1 @@
1
+ export { extendString } from './string-extensions';
@@ -0,0 +1,9 @@
1
+ import { PerformanceConfig } from '../core/performance';
2
+ export interface ExtensionOptions {
3
+ string?: boolean;
4
+ array?: boolean;
5
+ object?: boolean;
6
+ number?: boolean;
7
+ performance?: PerformanceConfig;
8
+ }
9
+ export { PerformanceConfig };
@@ -0,0 +1,2 @@
1
+ export * from './extension-types';
2
+ export * from './global-augmentations';
@@ -0,0 +1,4 @@
1
+ import { PerformanceConfig } from '../core/performance';
2
+ export declare function validateConfig(config: Partial<PerformanceConfig>, defaultConfig: PerformanceConfig): PerformanceConfig;
3
+ export declare function validatePerformanceSettings(settings: Partial<PerformanceConfig>): PerformanceConfig;
4
+ export declare function mergeConfigs<T extends Record<string, any>>(base: T, override: Partial<T>): T;
@@ -0,0 +1,5 @@
1
+ export declare function isValidArrayIndex(index: number): boolean;
2
+ export declare function ensurePositiveInteger(value: number, name: string): void;
3
+ export declare function safeClone<T>(obj: T): T;
4
+ export declare function getPathSegments(path: string): string[];
5
+ export declare function hasOwnProperty(obj: any, key: string): boolean;
@@ -0,0 +1,2 @@
1
+ export * from './config';
2
+ export * from './helpers';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naman_deep_singh/js-extensions",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Universal JavaScript prototype extensions for common development utilities",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",