@naman_deep_singh/js-extensions 1.3.0 → 1.3.2

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 (37) hide show
  1. package/README.md +14 -23
  2. package/dist/cjs/array/array-extensions.js +16 -10
  3. package/dist/cjs/core/performance.d.ts +8 -0
  4. package/dist/cjs/core/performance.js +3 -1
  5. package/dist/cjs/index.d.ts +22 -4
  6. package/dist/cjs/index.js +41 -8
  7. package/dist/cjs/init/initializer.d.ts +1 -1
  8. package/dist/cjs/init/initializer.js +5 -4
  9. package/dist/cjs/init/options.d.ts +1 -1
  10. package/dist/cjs/init/options.js +2 -2
  11. package/dist/cjs/number/number-extensions.js +18 -4
  12. package/dist/cjs/object/object-extensions.js +10 -7
  13. package/dist/cjs/string/string-extensions.js +6 -2
  14. package/dist/cjs/utils/config.d.ts +1 -1
  15. package/dist/cjs/utils/config.js +1 -1
  16. package/dist/cjs/utils/helpers.js +2 -2
  17. package/dist/esm/array/array-extensions.js +16 -10
  18. package/dist/esm/core/performance.d.ts +8 -0
  19. package/dist/esm/core/performance.js +2 -2
  20. package/dist/esm/index.d.ts +22 -4
  21. package/dist/esm/index.js +32 -8
  22. package/dist/esm/init/initializer.d.ts +1 -1
  23. package/dist/esm/init/initializer.js +5 -4
  24. package/dist/esm/init/options.d.ts +1 -1
  25. package/dist/esm/init/options.js +2 -2
  26. package/dist/esm/number/number-extensions.js +18 -4
  27. package/dist/esm/object/object-extensions.js +10 -7
  28. package/dist/esm/string/string-extensions.js +6 -2
  29. package/dist/esm/utils/config.d.ts +1 -1
  30. package/dist/esm/utils/config.js +1 -1
  31. package/dist/esm/utils/helpers.js +2 -2
  32. package/dist/types/core/performance.d.ts +8 -0
  33. package/dist/types/index.d.ts +22 -4
  34. package/dist/types/init/initializer.d.ts +1 -1
  35. package/dist/types/init/options.d.ts +1 -1
  36. package/dist/types/utils/config.d.ts +1 -1
  37. package/package.json +1 -1
package/README.md CHANGED
@@ -1,9 +1,8 @@
1
-
2
1
  # @naman_deep_singh/js-extensions
3
2
 
4
- **Version:** 1.3.0
3
+ **Version:** 1.3.2
5
4
 
6
- Universal JavaScript prototype extensions for common development utilities. Works in both Node.js and browser environments with 50+ utility methods.
5
+ Universal JavaScript prototype extensions for common development utilities. Works in both Node.js and browser environments with 67+ utility methods.
7
6
 
8
7
  ## Installation
9
8
 
@@ -16,7 +15,6 @@ pnpm add @naman_deep_singh/js-extensions
16
15
  ## Quick Start
17
16
 
18
17
  ```typescript
19
-
20
18
  import { initializeExtensions } from '@naman_deep_singh/js-extensions';
21
19
 
22
20
  // Initialize all extensions
@@ -69,11 +67,10 @@ import { setPerformanceConfig } from '@naman_deep_singh/js-extensions';
69
67
  // Validation is enabled by default for reliability
70
68
  setPerformanceConfig({
71
69
  enableCaching: true, // Cache expensive operations
72
- enableValidation: true // Input validation enabled (default)
70
+ enableValidation: true // Input validation enabled (built-in, cannot be disabled)
73
71
  });
74
72
 
75
- // Note: Currently validation cannot be disabled as it's built into the methods
76
- // Future versions may add an option to disable validation for maximum performance
73
+ // Note: Validation is built into all methods and cannot be disabled for maximum performance
77
74
  ```
78
75
 
79
76
  ## Configuration
@@ -81,7 +78,6 @@ setPerformanceConfig({
81
78
  ### Selective Extensions
82
79
 
83
80
  ```typescript
84
-
85
81
  import { initializeExtensions, extend } from '@naman_deep_singh/js-extensions';
86
82
 
87
83
  // Only specific types
@@ -100,15 +96,13 @@ extend.array(); // Only array methods
100
96
  ### Performance Configuration
101
97
 
102
98
  ```typescript
103
-
104
99
  import { initializeExtensions, setPerformanceConfig } from '@naman_deep_singh/js-extensions';
105
100
 
106
101
  // Configure performance options
107
102
  initializeExtensions({
108
103
  performance: {
109
104
  enableCaching: true, // Cache expensive operations
110
- maxCacheSize: 200, // LRU cache size
111
- enableValidation: false // Skip input validation for speed
105
+ maxCacheSize: 200 // LRU cache size
112
106
  }
113
107
  });
114
108
 
@@ -307,13 +301,12 @@ import { setPerformanceConfig, getPerformanceConfig } from '@naman_deep_singh/js
307
301
  // Enable caching for expensive operations
308
302
  setPerformanceConfig({
309
303
  enableCaching: true,
310
- maxCacheSize: 200,
311
- enableValidation: true
304
+ maxCacheSize: 200
312
305
  });
313
306
 
314
307
  // Check current config
315
308
  const config = getPerformanceConfig();
316
- console.log(config); // {enableCaching: true, maxCacheSize: 200, enableValidation: true}
309
+ console.log(config); // {enableCaching: true, maxCacheSize: 200}
317
310
  ```
318
311
 
319
312
  ### Methods with Built-in Caching
@@ -321,7 +314,6 @@ The following methods automatically use LRU cache when enabled:
321
314
  - **`isPrime()`** - Prime number calculations cached for repeated calls
322
315
  - **`factorial()`** - Factorial results cached to avoid recalculation
323
316
  - **`toRoman()`** - Roman numeral conversions cached for reuse
324
- - **`deepClone()`** - Deep clone operations cached for identical objects
325
317
 
326
318
  ### External Caching
327
319
  ```typescript
@@ -368,15 +360,14 @@ const picked: Pick<{a: number, b: string}, 'a'> = {a: 1, b: "test"}.pick(['a']);
368
360
  // Performance configuration is also typed
369
361
  const config: PerformanceConfig = {
370
362
  enableCaching: true,
371
- maxCacheSize: 100,
372
- enableValidation: false
363
+ maxCacheSize: 100
373
364
  };
374
365
  ```
375
366
 
376
367
 
377
368
  ## Package Stats
378
369
 
379
- - **60 utility methods** across 4 JavaScript types
370
+ - **67 utility methods** across 4 JavaScript types
380
371
  - **Zero dependencies** - lightweight and fast
381
372
  - **Universal compatibility** - Node.js and browser
382
373
  - **TypeScript native** - complete type definitions
@@ -388,7 +379,6 @@ const config: PerformanceConfig = {
388
379
 
389
380
  ### Core Functions
390
381
  ```typescript
391
-
392
382
  initializeExtensions(options?: ExtensionOptions): void
393
383
  extendAll(): void
394
384
  setPerformanceConfig(config: Partial<PerformanceConfig>): void
@@ -401,7 +391,7 @@ extend.object(): void
401
391
  extend.number(): void
402
392
  ```
403
393
 
404
- ### String Methods (17 methods)
394
+ ### String Methods (19 methods)
405
395
  ```typescript
406
396
  toCapitalize(): string
407
397
  toCamelCase(): string
@@ -422,7 +412,7 @@ words(): string[]
422
412
  lines(): string[]
423
413
  ```
424
414
 
425
- ### Array Methods (18 methods)
415
+ ### Array Methods (21 methods)
426
416
  ```typescript
427
417
  unique<T>(): T[]
428
418
  shuffle<T>(): T[]
@@ -457,7 +447,7 @@ getPath(path: string, defaultValue?: any): any
457
447
  setPath(path: string, value: any): any
458
448
  ```
459
449
 
460
- ### Number Methods (16 methods)
450
+ ### Number Methods (18 methods)
461
451
  ```typescript
462
452
  toPercent(decimals?: number): string
463
453
  toCurrency(currency?: string, locale?: string): string
@@ -475,4 +465,5 @@ floor(decimals?: number): number
475
465
  abs(): number
476
466
  sign(): number
477
467
  times(callback: (index: number) => void): void
478
- ```
468
+ ```
469
+
@@ -37,27 +37,29 @@ function extendArray() {
37
37
  }, {});
38
38
  };
39
39
  Array.prototype.sum = function () {
40
- const numbers = this.filter(item => typeof item === 'number');
40
+ const numbers = this.filter((item) => typeof item === 'number');
41
41
  if (numbers.length === 0) {
42
42
  throw new TypeError('sum: array must contain at least one number');
43
43
  }
44
44
  return numbers.reduce((sum, num) => sum + num, 0);
45
45
  };
46
46
  Array.prototype.average = function () {
47
- const numbers = this.filter(item => typeof item === 'number');
47
+ const numbers = this.filter((item) => typeof item === 'number');
48
48
  if (numbers.length === 0) {
49
49
  throw new TypeError('average: array must contain at least one number');
50
50
  }
51
51
  return numbers.reduce((sum, num) => sum + num, 0) / numbers.length;
52
52
  };
53
53
  Array.prototype.compact = function () {
54
- return this.filter(item => item != null && item !== '' && item !== false);
54
+ return this.filter((item) => item != null && item !== '' && item !== false);
55
55
  };
56
56
  Array.prototype.pluck = function (key) {
57
- if (typeof key !== 'string' && typeof key !== 'number' && typeof key !== 'symbol') {
57
+ if (typeof key !== 'string' &&
58
+ typeof key !== 'number' &&
59
+ typeof key !== 'symbol') {
58
60
  throw new TypeError(`pluck: key must be a string, number, or symbol, got ${typeof key}`);
59
61
  }
60
- return this.map(item => item && typeof item === 'object' ? item[key] : undefined).filter(val => val !== undefined);
62
+ return this.map((item) => item && typeof item === 'object' ? item[key] : undefined).filter((val) => val !== undefined);
61
63
  };
62
64
  Array.prototype.findLast = function (predicate) {
63
65
  if (typeof predicate !== 'function') {
@@ -75,11 +77,13 @@ function extendArray() {
75
77
  }
76
78
  const truthy = [];
77
79
  const falsy = [];
78
- this.forEach(item => predicate(item) ? truthy.push(item) : falsy.push(item));
80
+ this.forEach((item) => predicate(item) ? truthy.push(item) : falsy.push(item));
79
81
  return [truthy, falsy];
80
82
  };
81
83
  Array.prototype.flatten = function (depth = 1) {
82
- return depth > 0 ? this.reduce((acc, val) => acc.concat(Array.isArray(val) ? val.flatten(depth - 1) : val), []) : this.slice();
84
+ return depth > 0
85
+ ? this.reduce((acc, val) => acc.concat(Array.isArray(val) ? val.flatten(depth - 1) : val), [])
86
+ : this.slice();
83
87
  };
84
88
  Array.prototype.deepFlatten = function () {
85
89
  return this.reduce((acc, val) => acc.concat(Array.isArray(val) ? val.deepFlatten() : val), []);
@@ -88,13 +92,13 @@ function extendArray() {
88
92
  if (!Array.isArray(other)) {
89
93
  throw new TypeError(`difference: other must be an array, got ${typeof other}`);
90
94
  }
91
- return this.filter(item => !other.includes(item));
95
+ return this.filter((item) => !other.includes(item));
92
96
  };
93
97
  Array.prototype.intersection = function (other) {
94
98
  if (!Array.isArray(other)) {
95
99
  throw new TypeError(`intersection: other must be an array, got ${typeof other}`);
96
100
  }
97
- return this.filter(item => other.includes(item));
101
+ return this.filter((item) => other.includes(item));
98
102
  };
99
103
  Array.prototype.union = function (other) {
100
104
  if (!Array.isArray(other)) {
@@ -103,7 +107,9 @@ function extendArray() {
103
107
  return [...new Set([...this, ...other])];
104
108
  };
105
109
  Array.prototype.sample = function () {
106
- return this.length > 0 ? this[Math.floor(Math.random() * this.length)] : undefined;
110
+ return this.length > 0
111
+ ? this[Math.floor(Math.random() * this.length)]
112
+ : undefined;
107
113
  };
108
114
  Array.prototype.take = function (count) {
109
115
  return this.slice(0, Math.max(0, count));
@@ -5,4 +5,12 @@ export interface PerformanceConfig {
5
5
  }
6
6
  export declare function setPerformanceConfig(newConfig: Partial<PerformanceConfig>): void;
7
7
  export declare function getPerformanceConfig(): PerformanceConfig;
8
+ export 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
+ }
8
16
  export declare function withCache<T>(key: string, fn: () => T): T;
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LRUCache = void 0;
3
4
  exports.setPerformanceConfig = setPerformanceConfig;
4
5
  exports.getPerformanceConfig = getPerformanceConfig;
5
6
  exports.withCache = withCache;
6
7
  const defaultConfig = {
7
8
  enableCaching: false,
8
9
  maxCacheSize: 100,
9
- enableValidation: true
10
+ enableValidation: true,
10
11
  };
11
12
  let config = { ...defaultConfig };
12
13
  function setPerformanceConfig(newConfig) {
@@ -52,6 +53,7 @@ class LRUCache {
52
53
  this.cache.clear();
53
54
  }
54
55
  }
56
+ exports.LRUCache = LRUCache;
55
57
  let cache = null;
56
58
  function getOrCreateCache() {
57
59
  if (!cache) {
@@ -1,9 +1,12 @@
1
1
  import '../types/global-augmentations';
2
- import { extendString } from './string';
3
2
  import { extendArray } from './array';
4
- import { extendObject } from './object';
5
3
  import { extendNumber } from './number';
6
- import { withCache, setPerformanceConfig, getPerformanceConfig } from './core/performance';
4
+ import { extendObject } from './object';
5
+ import { extendString } from './string';
6
+ import { LRUCache, getPerformanceConfig, setPerformanceConfig, withCache } from './core/performance';
7
+ import { validateArrayInput, validateExtensionInput, validateNumberRange, validatePositiveInteger } from './core/validation';
8
+ import { mergeConfigs, validateConfig, validatePerformanceSettings } from './utils/config';
9
+ import { ensurePositiveInteger, getPathSegments, hasOwnProperty, isValidArrayIndex, safeClone } from './utils/helpers';
7
10
  import { ExtensionOptions, PerformanceConfig } from './types/extension-types';
8
11
  export { ExtensionOptions, PerformanceConfig };
9
12
  export { withCache };
@@ -26,7 +29,9 @@ export declare const extend: {
26
29
  object: typeof extendObject;
27
30
  number: typeof extendNumber;
28
31
  };
29
- export { setPerformanceConfig, getPerformanceConfig };
32
+ export { validateExtensionInput, validateArrayInput, validateNumberRange, validatePositiveInteger, };
33
+ export { validateConfig, validatePerformanceSettings, mergeConfigs, isValidArrayIndex, ensurePositiveInteger, safeClone, getPathSegments, hasOwnProperty, };
34
+ export { LRUCache, setPerformanceConfig, getPerformanceConfig };
30
35
  declare const _default: {
31
36
  initializeExtensions: typeof initializeExtensions;
32
37
  extendAll: typeof extendAll;
@@ -36,7 +41,20 @@ declare const _default: {
36
41
  object: typeof extendObject;
37
42
  number: typeof extendNumber;
38
43
  };
44
+ LRUCache: typeof LRUCache;
39
45
  setPerformanceConfig: typeof setPerformanceConfig;
40
46
  getPerformanceConfig: typeof getPerformanceConfig;
47
+ validateExtensionInput: typeof validateExtensionInput;
48
+ validateArrayInput: typeof validateArrayInput;
49
+ validateNumberRange: typeof validateNumberRange;
50
+ validatePositiveInteger: typeof validatePositiveInteger;
51
+ validateConfig: typeof validateConfig;
52
+ validatePerformanceSettings: typeof validatePerformanceSettings;
53
+ mergeConfigs: typeof mergeConfigs;
54
+ isValidArrayIndex: typeof isValidArrayIndex;
55
+ ensurePositiveInteger: typeof ensurePositiveInteger;
56
+ safeClone: typeof safeClone;
57
+ getPathSegments: typeof getPathSegments;
58
+ hasOwnProperty: typeof hasOwnProperty;
41
59
  };
42
60
  export default _default;
package/dist/cjs/index.js CHANGED
@@ -1,19 +1,37 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPerformanceConfig = exports.setPerformanceConfig = exports.extend = exports.extendAll = exports.withCache = void 0;
3
+ exports.getPerformanceConfig = exports.setPerformanceConfig = exports.LRUCache = exports.hasOwnProperty = exports.getPathSegments = exports.safeClone = exports.ensurePositiveInteger = exports.isValidArrayIndex = exports.mergeConfigs = exports.validatePerformanceSettings = exports.validateConfig = exports.validatePositiveInteger = exports.validateNumberRange = exports.validateArrayInput = exports.validateExtensionInput = exports.extend = exports.extendAll = exports.withCache = void 0;
4
4
  exports.initializeExtensions = initializeExtensions;
5
5
  // Import types first
6
6
  require("../types/global-augmentations");
7
- // Import extension modules
8
- const string_1 = require("./string");
9
7
  const array_1 = require("./array");
10
- const object_1 = require("./object");
11
8
  const number_1 = require("./number");
9
+ const object_1 = require("./object");
10
+ // Import extension modules
11
+ const string_1 = require("./string");
12
12
  // Import core utilities
13
13
  const performance_1 = require("./core/performance");
14
- Object.defineProperty(exports, "withCache", { enumerable: true, get: function () { return performance_1.withCache; } });
15
- Object.defineProperty(exports, "setPerformanceConfig", { enumerable: true, get: function () { return performance_1.setPerformanceConfig; } });
14
+ Object.defineProperty(exports, "LRUCache", { enumerable: true, get: function () { return performance_1.LRUCache; } });
16
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; } });
17
35
  // Import initialization functions
18
36
  const initializer_1 = require("./init/initializer");
19
37
  Object.defineProperty(exports, "extendAll", { enumerable: true, get: function () { return initializer_1.extendAll; } });
@@ -31,13 +49,28 @@ exports.extend = {
31
49
  string: string_1.extendString,
32
50
  array: array_1.extendArray,
33
51
  object: object_1.extendObject,
34
- number: number_1.extendNumber
52
+ number: number_1.extendNumber,
35
53
  };
36
54
  // Default export
37
55
  exports.default = {
38
56
  initializeExtensions,
39
57
  extendAll: initializer_1.extendAll,
40
58
  extend: exports.extend,
59
+ LRUCache: performance_1.LRUCache,
41
60
  setPerformanceConfig: performance_1.setPerformanceConfig,
42
- getPerformanceConfig: performance_1.getPerformanceConfig
61
+ getPerformanceConfig: performance_1.getPerformanceConfig,
62
+ // Validation utilities
63
+ validateExtensionInput: validation_1.validateExtensionInput,
64
+ validateArrayInput: validation_1.validateArrayInput,
65
+ validateNumberRange: validation_1.validateNumberRange,
66
+ validatePositiveInteger: validation_1.validatePositiveInteger,
67
+ // Utility functions
68
+ validateConfig: config_1.validateConfig,
69
+ validatePerformanceSettings: config_1.validatePerformanceSettings,
70
+ mergeConfigs: config_1.mergeConfigs,
71
+ isValidArrayIndex: helpers_1.isValidArrayIndex,
72
+ ensurePositiveInteger: helpers_1.ensurePositiveInteger,
73
+ safeClone: helpers_1.safeClone,
74
+ getPathSegments: helpers_1.getPathSegments,
75
+ hasOwnProperty: helpers_1.hasOwnProperty,
43
76
  };
@@ -1,3 +1,3 @@
1
- import { ExtensionOptions } from '../types/extension-types';
1
+ import type { ExtensionOptions } from '../types/extension-types';
2
2
  export declare function initExtensions(options?: ExtensionOptions): void;
3
3
  export declare function extendAll(): void;
@@ -2,13 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.initExtensions = initExtensions;
4
4
  exports.extendAll = extendAll;
5
- const string_1 = require("../string");
5
+ // Extension initialization logic
6
6
  const array_1 = require("../array");
7
- const object_1 = require("../object");
8
- const number_1 = require("../number");
9
7
  const performance_1 = require("../core/performance");
8
+ const number_1 = require("../number");
9
+ const object_1 = require("../object");
10
+ const string_1 = require("../string");
10
11
  function initExtensions(options = {}) {
11
- const { string = true, array = true, object = true, number = true, performance } = options;
12
+ const { string = true, array = true, object = true, number = true, performance, } = options;
12
13
  if (performance) {
13
14
  // Set performance config if provided
14
15
  (0, performance_1.setPerformanceConfig)(performance);
@@ -1,3 +1,3 @@
1
- import { ExtensionOptions } from '../types/extension-types';
1
+ import type { ExtensionOptions } from '../types/extension-types';
2
2
  export declare function validateExtensionOptions(options: Partial<ExtensionOptions>): ExtensionOptions;
3
3
  export declare function createExtensionOptions(enableString?: boolean, enableArray?: boolean, enableObject?: boolean, enableNumber?: boolean, performanceConfig?: any): ExtensionOptions;
@@ -8,7 +8,7 @@ function validateExtensionOptions(options) {
8
8
  array: options.array !== false,
9
9
  object: options.object !== false,
10
10
  number: options.number !== false,
11
- performance: options.performance
11
+ performance: options.performance,
12
12
  };
13
13
  return validated;
14
14
  }
@@ -18,6 +18,6 @@ function createExtensionOptions(enableString = true, enableArray = true, enableO
18
18
  array: enableArray,
19
19
  object: enableObject,
20
20
  number: enableNumber,
21
- performance: performanceConfig
21
+ performance: performanceConfig,
22
22
  };
23
23
  }
@@ -5,12 +5,12 @@ exports.extendNumber = extendNumber;
5
5
  const performance_1 = require("../core/performance");
6
6
  function extendNumber() {
7
7
  Number.prototype.toPercent = function (decimals = 2) {
8
- return (this.valueOf() * 100).toFixed(decimals) + '%';
8
+ return `${(this.valueOf() * 100).toFixed(decimals)}%`;
9
9
  };
10
10
  Number.prototype.toCurrency = function (currency = 'USD', locale = 'en-US') {
11
11
  return new Intl.NumberFormat(locale, {
12
12
  style: 'currency',
13
- currency: currency
13
+ currency,
14
14
  }).format(this.valueOf());
15
15
  };
16
16
  Number.prototype.clamp = function (min, max) {
@@ -41,7 +41,7 @@ function extendNumber() {
41
41
  const num = Math.floor(this.valueOf());
42
42
  return (0, performance_1.withCache)(`factorial_${num}`, () => {
43
43
  if (num < 0)
44
- return NaN;
44
+ return Number.NaN;
45
45
  if (num === 0 || num === 1)
46
46
  return 1;
47
47
  let result = 1;
@@ -68,7 +68,21 @@ function extendNumber() {
68
68
  }
69
69
  return (0, performance_1.withCache)(`roman_${num}`, () => {
70
70
  const values = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
71
- const symbols = ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I'];
71
+ const symbols = [
72
+ 'M',
73
+ 'CM',
74
+ 'D',
75
+ 'CD',
76
+ 'C',
77
+ 'XC',
78
+ 'L',
79
+ 'XL',
80
+ 'X',
81
+ 'IX',
82
+ 'V',
83
+ 'IV',
84
+ 'I',
85
+ ];
72
86
  let result = '';
73
87
  let n = num;
74
88
  for (let i = 0; i < values.length; i++) {
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ // Object prototype extensions
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.extendObject = extendObject;
4
5
  function extendObject() {
@@ -17,7 +18,7 @@ function extendObject() {
17
18
  }
18
19
  const result = {};
19
20
  const obj = this;
20
- keys.forEach(key => {
21
+ keys.forEach((key) => {
21
22
  if (key in obj) {
22
23
  result[key] = obj[key];
23
24
  }
@@ -35,7 +36,7 @@ function extendObject() {
35
36
  throw new TypeError('omit: keys array cannot be empty');
36
37
  }
37
38
  const result = { ...this };
38
- keys.forEach(key => {
39
+ keys.forEach((key) => {
39
40
  delete result[key];
40
41
  });
41
42
  return result;
@@ -49,10 +50,12 @@ function extendObject() {
49
50
  // Handle Date objects
50
51
  if (this instanceof Date)
51
52
  return new Date(this.getTime());
52
- // Handle Array objects
53
+ // Handle Array objects
53
54
  if (Array.isArray(this)) {
54
- return this.map(item => {
55
- if (item && typeof item === 'object' && typeof item.deepClone === 'function') {
55
+ return this.map((item) => {
56
+ if (item &&
57
+ typeof item === 'object' &&
58
+ typeof item.deepClone === 'function') {
56
59
  return item.deepClone();
57
60
  }
58
61
  return item;
@@ -70,9 +73,9 @@ function extendObject() {
70
73
  if (obj instanceof Date)
71
74
  return new Date(obj.getTime());
72
75
  if (Array.isArray(obj))
73
- return obj.map(item => deepCloneSafe(item));
76
+ return obj.map((item) => deepCloneSafe(item));
74
77
  const cloned = {};
75
- Object.keys(obj).forEach(key => {
78
+ Object.keys(obj).forEach((key) => {
76
79
  cloned[key] = deepCloneSafe(obj[key]);
77
80
  });
78
81
  return cloned;
@@ -23,7 +23,9 @@ function extendString() {
23
23
  if (!Number.isInteger(length) || length < 0) {
24
24
  throw new TypeError(`truncate: length must be a non-negative integer, got ${length}`);
25
25
  }
26
- return this.length > length ? this.substring(0, length) + suffix : this.toString();
26
+ return this.length > length
27
+ ? this.substring(0, length) + suffix
28
+ : this.toString();
27
29
  };
28
30
  String.prototype.isEmail = function () {
29
31
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
@@ -88,7 +90,9 @@ function extendString() {
88
90
  return (this.match(new RegExp(substring, 'g')) || []).length;
89
91
  };
90
92
  String.prototype.words = function () {
91
- return this.trim().split(/\s+/).filter(word => word.length > 0);
93
+ return this.trim()
94
+ .split(/\s+/)
95
+ .filter((word) => word.length > 0);
92
96
  };
93
97
  String.prototype.lines = function () {
94
98
  return this.split(/\r?\n/);
@@ -1,4 +1,4 @@
1
- import { PerformanceConfig } from '../core/performance';
1
+ import type { PerformanceConfig } from '../core/performance';
2
2
  export declare function validateConfig(config: Partial<PerformanceConfig>, defaultConfig: PerformanceConfig): PerformanceConfig;
3
3
  export declare function validatePerformanceSettings(settings: Partial<PerformanceConfig>): PerformanceConfig;
4
4
  export declare function mergeConfigs<T extends Record<string, any>>(base: T, override: Partial<T>): T;
@@ -10,7 +10,7 @@ function validatePerformanceSettings(settings) {
10
10
  const validated = {
11
11
  enableCaching: settings.enableCaching ?? false,
12
12
  maxCacheSize: Math.max(1, settings.maxCacheSize ?? 100),
13
- enableValidation: settings.enableValidation ?? true
13
+ enableValidation: settings.enableValidation ?? true,
14
14
  };
15
15
  return validated;
16
16
  }
@@ -20,7 +20,7 @@ function safeClone(obj) {
20
20
  if (obj instanceof Date)
21
21
  return new Date(obj.getTime());
22
22
  if (Array.isArray(obj))
23
- return obj.map(item => safeClone(item));
23
+ return obj.map((item) => safeClone(item));
24
24
  const cloned = {};
25
25
  for (const key in obj) {
26
26
  if (obj.hasOwnProperty(key)) {
@@ -30,7 +30,7 @@ function safeClone(obj) {
30
30
  return cloned;
31
31
  }
32
32
  function getPathSegments(path) {
33
- return path.split('.').filter(segment => segment.length > 0);
33
+ return path.split('.').filter((segment) => segment.length > 0);
34
34
  }
35
35
  function hasOwnProperty(obj, key) {
36
36
  return Object.prototype.hasOwnProperty.call(obj, key);
@@ -34,27 +34,29 @@ export function extendArray() {
34
34
  }, {});
35
35
  };
36
36
  Array.prototype.sum = function () {
37
- const numbers = this.filter(item => typeof item === 'number');
37
+ const numbers = this.filter((item) => typeof item === 'number');
38
38
  if (numbers.length === 0) {
39
39
  throw new TypeError('sum: array must contain at least one number');
40
40
  }
41
41
  return numbers.reduce((sum, num) => sum + num, 0);
42
42
  };
43
43
  Array.prototype.average = function () {
44
- const numbers = this.filter(item => typeof item === 'number');
44
+ const numbers = this.filter((item) => typeof item === 'number');
45
45
  if (numbers.length === 0) {
46
46
  throw new TypeError('average: array must contain at least one number');
47
47
  }
48
48
  return numbers.reduce((sum, num) => sum + num, 0) / numbers.length;
49
49
  };
50
50
  Array.prototype.compact = function () {
51
- return this.filter(item => item != null && item !== '' && item !== false);
51
+ return this.filter((item) => item != null && item !== '' && item !== false);
52
52
  };
53
53
  Array.prototype.pluck = function (key) {
54
- if (typeof key !== 'string' && typeof key !== 'number' && typeof key !== 'symbol') {
54
+ if (typeof key !== 'string' &&
55
+ typeof key !== 'number' &&
56
+ typeof key !== 'symbol') {
55
57
  throw new TypeError(`pluck: key must be a string, number, or symbol, got ${typeof key}`);
56
58
  }
57
- return this.map(item => item && typeof item === 'object' ? item[key] : undefined).filter(val => val !== undefined);
59
+ return this.map((item) => item && typeof item === 'object' ? item[key] : undefined).filter((val) => val !== undefined);
58
60
  };
59
61
  Array.prototype.findLast = function (predicate) {
60
62
  if (typeof predicate !== 'function') {
@@ -72,11 +74,13 @@ export function extendArray() {
72
74
  }
73
75
  const truthy = [];
74
76
  const falsy = [];
75
- this.forEach(item => predicate(item) ? truthy.push(item) : falsy.push(item));
77
+ this.forEach((item) => predicate(item) ? truthy.push(item) : falsy.push(item));
76
78
  return [truthy, falsy];
77
79
  };
78
80
  Array.prototype.flatten = function (depth = 1) {
79
- return depth > 0 ? this.reduce((acc, val) => acc.concat(Array.isArray(val) ? val.flatten(depth - 1) : val), []) : this.slice();
81
+ return depth > 0
82
+ ? this.reduce((acc, val) => acc.concat(Array.isArray(val) ? val.flatten(depth - 1) : val), [])
83
+ : this.slice();
80
84
  };
81
85
  Array.prototype.deepFlatten = function () {
82
86
  return this.reduce((acc, val) => acc.concat(Array.isArray(val) ? val.deepFlatten() : val), []);
@@ -85,13 +89,13 @@ export function extendArray() {
85
89
  if (!Array.isArray(other)) {
86
90
  throw new TypeError(`difference: other must be an array, got ${typeof other}`);
87
91
  }
88
- return this.filter(item => !other.includes(item));
92
+ return this.filter((item) => !other.includes(item));
89
93
  };
90
94
  Array.prototype.intersection = function (other) {
91
95
  if (!Array.isArray(other)) {
92
96
  throw new TypeError(`intersection: other must be an array, got ${typeof other}`);
93
97
  }
94
- return this.filter(item => other.includes(item));
98
+ return this.filter((item) => other.includes(item));
95
99
  };
96
100
  Array.prototype.union = function (other) {
97
101
  if (!Array.isArray(other)) {
@@ -100,7 +104,9 @@ export function extendArray() {
100
104
  return [...new Set([...this, ...other])];
101
105
  };
102
106
  Array.prototype.sample = function () {
103
- return this.length > 0 ? this[Math.floor(Math.random() * this.length)] : undefined;
107
+ return this.length > 0
108
+ ? this[Math.floor(Math.random() * this.length)]
109
+ : undefined;
104
110
  };
105
111
  Array.prototype.take = function (count) {
106
112
  return this.slice(0, Math.max(0, count));
@@ -5,4 +5,12 @@ export interface PerformanceConfig {
5
5
  }
6
6
  export declare function setPerformanceConfig(newConfig: Partial<PerformanceConfig>): void;
7
7
  export declare function getPerformanceConfig(): PerformanceConfig;
8
+ export 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
+ }
8
16
  export declare function withCache<T>(key: string, fn: () => T): T;
@@ -1,7 +1,7 @@
1
1
  const defaultConfig = {
2
2
  enableCaching: false,
3
3
  maxCacheSize: 100,
4
- enableValidation: true
4
+ enableValidation: true,
5
5
  };
6
6
  let config = { ...defaultConfig };
7
7
  export function setPerformanceConfig(newConfig) {
@@ -16,7 +16,7 @@ export function getPerformanceConfig() {
16
16
  return { ...config };
17
17
  }
18
18
  // Simple LRU cache for expensive operations
19
- class LRUCache {
19
+ export class LRUCache {
20
20
  constructor(maxSize = 100) {
21
21
  this.cache = new Map();
22
22
  this.maxSize = maxSize;
@@ -1,9 +1,12 @@
1
1
  import '../types/global-augmentations';
2
- import { extendString } from './string';
3
2
  import { extendArray } from './array';
4
- import { extendObject } from './object';
5
3
  import { extendNumber } from './number';
6
- import { withCache, setPerformanceConfig, getPerformanceConfig } from './core/performance';
4
+ import { extendObject } from './object';
5
+ import { extendString } from './string';
6
+ import { LRUCache, getPerformanceConfig, setPerformanceConfig, withCache } from './core/performance';
7
+ import { validateArrayInput, validateExtensionInput, validateNumberRange, validatePositiveInteger } from './core/validation';
8
+ import { mergeConfigs, validateConfig, validatePerformanceSettings } from './utils/config';
9
+ import { ensurePositiveInteger, getPathSegments, hasOwnProperty, isValidArrayIndex, safeClone } from './utils/helpers';
7
10
  import { ExtensionOptions, PerformanceConfig } from './types/extension-types';
8
11
  export { ExtensionOptions, PerformanceConfig };
9
12
  export { withCache };
@@ -26,7 +29,9 @@ export declare const extend: {
26
29
  object: typeof extendObject;
27
30
  number: typeof extendNumber;
28
31
  };
29
- export { setPerformanceConfig, getPerformanceConfig };
32
+ export { validateExtensionInput, validateArrayInput, validateNumberRange, validatePositiveInteger, };
33
+ export { validateConfig, validatePerformanceSettings, mergeConfigs, isValidArrayIndex, ensurePositiveInteger, safeClone, getPathSegments, hasOwnProperty, };
34
+ export { LRUCache, setPerformanceConfig, getPerformanceConfig };
30
35
  declare const _default: {
31
36
  initializeExtensions: typeof initializeExtensions;
32
37
  extendAll: typeof extendAll;
@@ -36,7 +41,20 @@ declare const _default: {
36
41
  object: typeof extendObject;
37
42
  number: typeof extendNumber;
38
43
  };
44
+ LRUCache: typeof LRUCache;
39
45
  setPerformanceConfig: typeof setPerformanceConfig;
40
46
  getPerformanceConfig: typeof getPerformanceConfig;
47
+ validateExtensionInput: typeof validateExtensionInput;
48
+ validateArrayInput: typeof validateArrayInput;
49
+ validateNumberRange: typeof validateNumberRange;
50
+ validatePositiveInteger: typeof validatePositiveInteger;
51
+ validateConfig: typeof validateConfig;
52
+ validatePerformanceSettings: typeof validatePerformanceSettings;
53
+ mergeConfigs: typeof mergeConfigs;
54
+ isValidArrayIndex: typeof isValidArrayIndex;
55
+ ensurePositiveInteger: typeof ensurePositiveInteger;
56
+ safeClone: typeof safeClone;
57
+ getPathSegments: typeof getPathSegments;
58
+ hasOwnProperty: typeof hasOwnProperty;
41
59
  };
42
60
  export default _default;
package/dist/esm/index.js CHANGED
@@ -1,16 +1,21 @@
1
1
  // Import types first
2
2
  import '../types/global-augmentations';
3
- // Import extension modules
4
- import { extendString } from './string';
5
3
  import { extendArray } from './array';
6
- import { extendObject } from './object';
7
4
  import { extendNumber } from './number';
5
+ import { extendObject } from './object';
6
+ // Import extension modules
7
+ import { extendString } from './string';
8
8
  // Import core utilities
9
- import { withCache, setPerformanceConfig, getPerformanceConfig } from './core/performance';
9
+ import { LRUCache, getPerformanceConfig, setPerformanceConfig, withCache, } from './core/performance';
10
+ // Import validation utilities
11
+ import { validateArrayInput, validateExtensionInput, validateNumberRange, validatePositiveInteger, } from './core/validation';
12
+ // Import utility functions
13
+ import { mergeConfigs, validateConfig, validatePerformanceSettings, } from './utils/config';
14
+ import { ensurePositiveInteger, getPathSegments, hasOwnProperty, isValidArrayIndex, safeClone, } from './utils/helpers';
10
15
  // Export withCache for use in extensions
11
16
  export { withCache };
12
17
  // Import initialization functions
13
- import { initExtensions, extendAll } from './init/initializer';
18
+ import { extendAll, initExtensions } from './init/initializer';
14
19
  /**
15
20
  * Initialize JavaScript prototype extensions
16
21
  * @param options - Configure which extensions to enable (default: all enabled)
@@ -29,15 +34,34 @@ export const extend = {
29
34
  string: extendString,
30
35
  array: extendArray,
31
36
  object: extendObject,
32
- number: extendNumber
37
+ number: extendNumber,
33
38
  };
39
+ // Export validation utilities
40
+ export { validateExtensionInput, validateArrayInput, validateNumberRange, validatePositiveInteger, };
41
+ // Export utility functions
42
+ export { validateConfig, validatePerformanceSettings, mergeConfigs, isValidArrayIndex, ensurePositiveInteger, safeClone, getPathSegments, hasOwnProperty, };
34
43
  // Export performance utilities
35
- export { setPerformanceConfig, getPerformanceConfig };
44
+ export { LRUCache, setPerformanceConfig, getPerformanceConfig };
36
45
  // Default export
37
46
  export default {
38
47
  initializeExtensions,
39
48
  extendAll,
40
49
  extend,
50
+ LRUCache,
41
51
  setPerformanceConfig,
42
- getPerformanceConfig
52
+ getPerformanceConfig,
53
+ // Validation utilities
54
+ validateExtensionInput,
55
+ validateArrayInput,
56
+ validateNumberRange,
57
+ validatePositiveInteger,
58
+ // Utility functions
59
+ validateConfig,
60
+ validatePerformanceSettings,
61
+ mergeConfigs,
62
+ isValidArrayIndex,
63
+ ensurePositiveInteger,
64
+ safeClone,
65
+ getPathSegments,
66
+ hasOwnProperty,
43
67
  };
@@ -1,3 +1,3 @@
1
- import { ExtensionOptions } from '../types/extension-types';
1
+ import type { ExtensionOptions } from '../types/extension-types';
2
2
  export declare function initExtensions(options?: ExtensionOptions): void;
3
3
  export declare function extendAll(): void;
@@ -1,10 +1,11 @@
1
- import { extendString } from '../string';
1
+ // Extension initialization logic
2
2
  import { extendArray } from '../array';
3
- import { extendObject } from '../object';
4
- import { extendNumber } from '../number';
5
3
  import { setPerformanceConfig } from '../core/performance';
4
+ import { extendNumber } from '../number';
5
+ import { extendObject } from '../object';
6
+ import { extendString } from '../string';
6
7
  export function initExtensions(options = {}) {
7
- const { string = true, array = true, object = true, number = true, performance } = options;
8
+ const { string = true, array = true, object = true, number = true, performance, } = options;
8
9
  if (performance) {
9
10
  // Set performance config if provided
10
11
  setPerformanceConfig(performance);
@@ -1,3 +1,3 @@
1
- import { ExtensionOptions } from '../types/extension-types';
1
+ import type { ExtensionOptions } from '../types/extension-types';
2
2
  export declare function validateExtensionOptions(options: Partial<ExtensionOptions>): ExtensionOptions;
3
3
  export declare function createExtensionOptions(enableString?: boolean, enableArray?: boolean, enableObject?: boolean, enableNumber?: boolean, performanceConfig?: any): ExtensionOptions;
@@ -4,7 +4,7 @@ export function validateExtensionOptions(options) {
4
4
  array: options.array !== false,
5
5
  object: options.object !== false,
6
6
  number: options.number !== false,
7
- performance: options.performance
7
+ performance: options.performance,
8
8
  };
9
9
  return validated;
10
10
  }
@@ -14,6 +14,6 @@ export function createExtensionOptions(enableString = true, enableArray = true,
14
14
  array: enableArray,
15
15
  object: enableObject,
16
16
  number: enableNumber,
17
- performance: performanceConfig
17
+ performance: performanceConfig,
18
18
  };
19
19
  }
@@ -2,12 +2,12 @@
2
2
  import { withCache } from '../core/performance';
3
3
  export function extendNumber() {
4
4
  Number.prototype.toPercent = function (decimals = 2) {
5
- return (this.valueOf() * 100).toFixed(decimals) + '%';
5
+ return `${(this.valueOf() * 100).toFixed(decimals)}%`;
6
6
  };
7
7
  Number.prototype.toCurrency = function (currency = 'USD', locale = 'en-US') {
8
8
  return new Intl.NumberFormat(locale, {
9
9
  style: 'currency',
10
- currency: currency
10
+ currency,
11
11
  }).format(this.valueOf());
12
12
  };
13
13
  Number.prototype.clamp = function (min, max) {
@@ -38,7 +38,7 @@ export function extendNumber() {
38
38
  const num = Math.floor(this.valueOf());
39
39
  return withCache(`factorial_${num}`, () => {
40
40
  if (num < 0)
41
- return NaN;
41
+ return Number.NaN;
42
42
  if (num === 0 || num === 1)
43
43
  return 1;
44
44
  let result = 1;
@@ -65,7 +65,21 @@ export function extendNumber() {
65
65
  }
66
66
  return withCache(`roman_${num}`, () => {
67
67
  const values = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
68
- const symbols = ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I'];
68
+ const symbols = [
69
+ 'M',
70
+ 'CM',
71
+ 'D',
72
+ 'CD',
73
+ 'C',
74
+ 'XC',
75
+ 'L',
76
+ 'XL',
77
+ 'X',
78
+ 'IX',
79
+ 'V',
80
+ 'IV',
81
+ 'I',
82
+ ];
69
83
  let result = '';
70
84
  let n = num;
71
85
  for (let i = 0; i < values.length; i++) {
@@ -1,3 +1,4 @@
1
+ // Object prototype extensions
1
2
  export function extendObject() {
2
3
  Object.prototype.isEmpty = function () {
3
4
  return Object.keys(this).length === 0;
@@ -14,7 +15,7 @@ export function extendObject() {
14
15
  }
15
16
  const result = {};
16
17
  const obj = this;
17
- keys.forEach(key => {
18
+ keys.forEach((key) => {
18
19
  if (key in obj) {
19
20
  result[key] = obj[key];
20
21
  }
@@ -32,7 +33,7 @@ export function extendObject() {
32
33
  throw new TypeError('omit: keys array cannot be empty');
33
34
  }
34
35
  const result = { ...this };
35
- keys.forEach(key => {
36
+ keys.forEach((key) => {
36
37
  delete result[key];
37
38
  });
38
39
  return result;
@@ -46,10 +47,12 @@ export function extendObject() {
46
47
  // Handle Date objects
47
48
  if (this instanceof Date)
48
49
  return new Date(this.getTime());
49
- // Handle Array objects
50
+ // Handle Array objects
50
51
  if (Array.isArray(this)) {
51
- return this.map(item => {
52
- if (item && typeof item === 'object' && typeof item.deepClone === 'function') {
52
+ return this.map((item) => {
53
+ if (item &&
54
+ typeof item === 'object' &&
55
+ typeof item.deepClone === 'function') {
53
56
  return item.deepClone();
54
57
  }
55
58
  return item;
@@ -67,9 +70,9 @@ export function extendObject() {
67
70
  if (obj instanceof Date)
68
71
  return new Date(obj.getTime());
69
72
  if (Array.isArray(obj))
70
- return obj.map(item => deepCloneSafe(item));
73
+ return obj.map((item) => deepCloneSafe(item));
71
74
  const cloned = {};
72
- Object.keys(obj).forEach(key => {
75
+ Object.keys(obj).forEach((key) => {
73
76
  cloned[key] = deepCloneSafe(obj[key]);
74
77
  });
75
78
  return cloned;
@@ -20,7 +20,9 @@ export function extendString() {
20
20
  if (!Number.isInteger(length) || length < 0) {
21
21
  throw new TypeError(`truncate: length must be a non-negative integer, got ${length}`);
22
22
  }
23
- return this.length > length ? this.substring(0, length) + suffix : this.toString();
23
+ return this.length > length
24
+ ? this.substring(0, length) + suffix
25
+ : this.toString();
24
26
  };
25
27
  String.prototype.isEmail = function () {
26
28
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
@@ -85,7 +87,9 @@ export function extendString() {
85
87
  return (this.match(new RegExp(substring, 'g')) || []).length;
86
88
  };
87
89
  String.prototype.words = function () {
88
- return this.trim().split(/\s+/).filter(word => word.length > 0);
90
+ return this.trim()
91
+ .split(/\s+/)
92
+ .filter((word) => word.length > 0);
89
93
  };
90
94
  String.prototype.lines = function () {
91
95
  return this.split(/\r?\n/);
@@ -1,4 +1,4 @@
1
- import { PerformanceConfig } from '../core/performance';
1
+ import type { PerformanceConfig } from '../core/performance';
2
2
  export declare function validateConfig(config: Partial<PerformanceConfig>, defaultConfig: PerformanceConfig): PerformanceConfig;
3
3
  export declare function validatePerformanceSettings(settings: Partial<PerformanceConfig>): PerformanceConfig;
4
4
  export declare function mergeConfigs<T extends Record<string, any>>(base: T, override: Partial<T>): T;
@@ -5,7 +5,7 @@ export function validatePerformanceSettings(settings) {
5
5
  const validated = {
6
6
  enableCaching: settings.enableCaching ?? false,
7
7
  maxCacheSize: Math.max(1, settings.maxCacheSize ?? 100),
8
- enableValidation: settings.enableValidation ?? true
8
+ enableValidation: settings.enableValidation ?? true,
9
9
  };
10
10
  return validated;
11
11
  }
@@ -13,7 +13,7 @@ export function safeClone(obj) {
13
13
  if (obj instanceof Date)
14
14
  return new Date(obj.getTime());
15
15
  if (Array.isArray(obj))
16
- return obj.map(item => safeClone(item));
16
+ return obj.map((item) => safeClone(item));
17
17
  const cloned = {};
18
18
  for (const key in obj) {
19
19
  if (obj.hasOwnProperty(key)) {
@@ -23,7 +23,7 @@ export function safeClone(obj) {
23
23
  return cloned;
24
24
  }
25
25
  export function getPathSegments(path) {
26
- return path.split('.').filter(segment => segment.length > 0);
26
+ return path.split('.').filter((segment) => segment.length > 0);
27
27
  }
28
28
  export function hasOwnProperty(obj, key) {
29
29
  return Object.prototype.hasOwnProperty.call(obj, key);
@@ -5,4 +5,12 @@ export interface PerformanceConfig {
5
5
  }
6
6
  export declare function setPerformanceConfig(newConfig: Partial<PerformanceConfig>): void;
7
7
  export declare function getPerformanceConfig(): PerformanceConfig;
8
+ export 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
+ }
8
16
  export declare function withCache<T>(key: string, fn: () => T): T;
@@ -1,9 +1,12 @@
1
1
  import '../types/global-augmentations';
2
- import { extendString } from './string';
3
2
  import { extendArray } from './array';
4
- import { extendObject } from './object';
5
3
  import { extendNumber } from './number';
6
- import { withCache, setPerformanceConfig, getPerformanceConfig } from './core/performance';
4
+ import { extendObject } from './object';
5
+ import { extendString } from './string';
6
+ import { LRUCache, getPerformanceConfig, setPerformanceConfig, withCache } from './core/performance';
7
+ import { validateArrayInput, validateExtensionInput, validateNumberRange, validatePositiveInteger } from './core/validation';
8
+ import { mergeConfigs, validateConfig, validatePerformanceSettings } from './utils/config';
9
+ import { ensurePositiveInteger, getPathSegments, hasOwnProperty, isValidArrayIndex, safeClone } from './utils/helpers';
7
10
  import { ExtensionOptions, PerformanceConfig } from './types/extension-types';
8
11
  export { ExtensionOptions, PerformanceConfig };
9
12
  export { withCache };
@@ -26,7 +29,9 @@ export declare const extend: {
26
29
  object: typeof extendObject;
27
30
  number: typeof extendNumber;
28
31
  };
29
- export { setPerformanceConfig, getPerformanceConfig };
32
+ export { validateExtensionInput, validateArrayInput, validateNumberRange, validatePositiveInteger, };
33
+ export { validateConfig, validatePerformanceSettings, mergeConfigs, isValidArrayIndex, ensurePositiveInteger, safeClone, getPathSegments, hasOwnProperty, };
34
+ export { LRUCache, setPerformanceConfig, getPerformanceConfig };
30
35
  declare const _default: {
31
36
  initializeExtensions: typeof initializeExtensions;
32
37
  extendAll: typeof extendAll;
@@ -36,7 +41,20 @@ declare const _default: {
36
41
  object: typeof extendObject;
37
42
  number: typeof extendNumber;
38
43
  };
44
+ LRUCache: typeof LRUCache;
39
45
  setPerformanceConfig: typeof setPerformanceConfig;
40
46
  getPerformanceConfig: typeof getPerformanceConfig;
47
+ validateExtensionInput: typeof validateExtensionInput;
48
+ validateArrayInput: typeof validateArrayInput;
49
+ validateNumberRange: typeof validateNumberRange;
50
+ validatePositiveInteger: typeof validatePositiveInteger;
51
+ validateConfig: typeof validateConfig;
52
+ validatePerformanceSettings: typeof validatePerformanceSettings;
53
+ mergeConfigs: typeof mergeConfigs;
54
+ isValidArrayIndex: typeof isValidArrayIndex;
55
+ ensurePositiveInteger: typeof ensurePositiveInteger;
56
+ safeClone: typeof safeClone;
57
+ getPathSegments: typeof getPathSegments;
58
+ hasOwnProperty: typeof hasOwnProperty;
41
59
  };
42
60
  export default _default;
@@ -1,3 +1,3 @@
1
- import { ExtensionOptions } from '../types/extension-types';
1
+ import type { ExtensionOptions } from '../types/extension-types';
2
2
  export declare function initExtensions(options?: ExtensionOptions): void;
3
3
  export declare function extendAll(): void;
@@ -1,3 +1,3 @@
1
- import { ExtensionOptions } from '../types/extension-types';
1
+ import type { ExtensionOptions } from '../types/extension-types';
2
2
  export declare function validateExtensionOptions(options: Partial<ExtensionOptions>): ExtensionOptions;
3
3
  export declare function createExtensionOptions(enableString?: boolean, enableArray?: boolean, enableObject?: boolean, enableNumber?: boolean, performanceConfig?: any): ExtensionOptions;
@@ -1,4 +1,4 @@
1
- import { PerformanceConfig } from '../core/performance';
1
+ import type { PerformanceConfig } from '../core/performance';
2
2
  export declare function validateConfig(config: Partial<PerformanceConfig>, defaultConfig: PerformanceConfig): PerformanceConfig;
3
3
  export declare function validatePerformanceSettings(settings: Partial<PerformanceConfig>): PerformanceConfig;
4
4
  export declare function mergeConfigs<T extends Record<string, any>>(base: T, override: Partial<T>): T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naman_deep_singh/js-extensions",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "Universal JavaScript prototype extensions for common development utilities",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",