@naman_deep_singh/utils 2.1.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 (122) hide show
  1. package/README.md +218 -0
  2. package/dist/cjs/array/array-extensions.d.ts +1 -0
  3. package/dist/cjs/array/array-extensions.js +152 -0
  4. package/dist/cjs/array/index.d.ts +1 -0
  5. package/dist/cjs/array/index.js +5 -0
  6. package/dist/cjs/core/index.d.ts +2 -0
  7. package/dist/cjs/core/index.js +19 -0
  8. package/dist/cjs/core/performance.d.ts +17 -0
  9. package/dist/cjs/core/performance.js +82 -0
  10. package/dist/cjs/core/validation.d.ts +4 -0
  11. package/dist/cjs/core/validation.js +31 -0
  12. package/dist/cjs/core/version.d.ts +1 -0
  13. package/dist/cjs/core/version.js +9 -0
  14. package/dist/cjs/extensions/index.d.ts +4 -0
  15. package/dist/cjs/extensions/index.js +21 -0
  16. package/dist/cjs/index.d.ts +61 -0
  17. package/dist/cjs/index.js +77 -0
  18. package/dist/cjs/init/index.d.ts +2 -0
  19. package/dist/cjs/init/index.js +19 -0
  20. package/dist/cjs/init/initializer.d.ts +3 -0
  21. package/dist/cjs/init/initializer.js +28 -0
  22. package/dist/cjs/init/options.d.ts +3 -0
  23. package/dist/cjs/init/options.js +23 -0
  24. package/dist/cjs/number/index.d.ts +1 -0
  25. package/dist/cjs/number/index.js +5 -0
  26. package/dist/cjs/number/number-extensions.d.ts +1 -0
  27. package/dist/cjs/number/number-extensions.js +142 -0
  28. package/dist/cjs/object/index.d.ts +1 -0
  29. package/dist/cjs/object/index.js +5 -0
  30. package/dist/cjs/object/object-extensions.d.ts +1 -0
  31. package/dist/cjs/object/object-extensions.js +148 -0
  32. package/dist/cjs/string/index.d.ts +1 -0
  33. package/dist/cjs/string/index.js +5 -0
  34. package/dist/cjs/string/string-extensions.d.ts +1 -0
  35. package/dist/cjs/string/string-extensions.js +127 -0
  36. package/dist/cjs/types/extension-types.d.ts +9 -0
  37. package/dist/cjs/types/extension-types.js +2 -0
  38. package/dist/cjs/types/global-augmentations.d.ts +72 -0
  39. package/dist/cjs/types/global-augmentations.js +2 -0
  40. package/dist/cjs/types/index.d.ts +2 -0
  41. package/dist/cjs/types/index.js +19 -0
  42. package/dist/cjs/utils/config.d.ts +4 -0
  43. package/dist/cjs/utils/config.js +25 -0
  44. package/dist/cjs/utils/defineExtension.d.ts +1 -0
  45. package/dist/cjs/utils/defineExtension.js +13 -0
  46. package/dist/cjs/utils/helpers.d.ts +5 -0
  47. package/dist/cjs/utils/helpers.js +37 -0
  48. package/dist/cjs/utils/index.d.ts +3 -0
  49. package/dist/cjs/utils/index.js +20 -0
  50. package/dist/esm/array/array-extensions.d.ts +1 -0
  51. package/dist/esm/array/array-extensions.js +149 -0
  52. package/dist/esm/array/index.d.ts +1 -0
  53. package/dist/esm/array/index.js +1 -0
  54. package/dist/esm/core/index.d.ts +2 -0
  55. package/dist/esm/core/index.js +3 -0
  56. package/dist/esm/core/performance.d.ts +17 -0
  57. package/dist/esm/core/performance.js +74 -0
  58. package/dist/esm/core/validation.d.ts +4 -0
  59. package/dist/esm/core/validation.js +25 -0
  60. package/dist/esm/core/version.d.ts +1 -0
  61. package/dist/esm/core/version.js +5 -0
  62. package/dist/esm/extensions/index.d.ts +4 -0
  63. package/dist/esm/extensions/index.js +5 -0
  64. package/dist/esm/index.d.ts +61 -0
  65. package/dist/esm/index.js +68 -0
  66. package/dist/esm/init/index.d.ts +2 -0
  67. package/dist/esm/init/index.js +3 -0
  68. package/dist/esm/init/initializer.d.ts +3 -0
  69. package/dist/esm/init/initializer.js +24 -0
  70. package/dist/esm/init/options.d.ts +3 -0
  71. package/dist/esm/init/options.js +19 -0
  72. package/dist/esm/number/index.d.ts +1 -0
  73. package/dist/esm/number/index.js +1 -0
  74. package/dist/esm/number/number-extensions.d.ts +1 -0
  75. package/dist/esm/number/number-extensions.js +139 -0
  76. package/dist/esm/object/index.d.ts +1 -0
  77. package/dist/esm/object/index.js +1 -0
  78. package/dist/esm/object/object-extensions.d.ts +1 -0
  79. package/dist/esm/object/object-extensions.js +145 -0
  80. package/dist/esm/string/index.d.ts +1 -0
  81. package/dist/esm/string/index.js +1 -0
  82. package/dist/esm/string/string-extensions.d.ts +1 -0
  83. package/dist/esm/string/string-extensions.js +124 -0
  84. package/dist/esm/types/extension-types.d.ts +9 -0
  85. package/dist/esm/types/extension-types.js +1 -0
  86. package/dist/esm/types/global-augmentations.d.ts +72 -0
  87. package/dist/esm/types/global-augmentations.js +1 -0
  88. package/dist/esm/types/index.d.ts +2 -0
  89. package/dist/esm/types/index.js +3 -0
  90. package/dist/esm/utils/config.d.ts +4 -0
  91. package/dist/esm/utils/config.js +20 -0
  92. package/dist/esm/utils/defineExtension.d.ts +1 -0
  93. package/dist/esm/utils/defineExtension.js +10 -0
  94. package/dist/esm/utils/helpers.d.ts +5 -0
  95. package/dist/esm/utils/helpers.js +30 -0
  96. package/dist/esm/utils/index.d.ts +3 -0
  97. package/dist/esm/utils/index.js +4 -0
  98. package/dist/types/array/array-extensions.d.ts +1 -0
  99. package/dist/types/array/index.d.ts +1 -0
  100. package/dist/types/core/index.d.ts +2 -0
  101. package/dist/types/core/performance.d.ts +17 -0
  102. package/dist/types/core/validation.d.ts +4 -0
  103. package/dist/types/core/version.d.ts +1 -0
  104. package/dist/types/extensions/index.d.ts +4 -0
  105. package/dist/types/index.d.ts +61 -0
  106. package/dist/types/init/index.d.ts +2 -0
  107. package/dist/types/init/initializer.d.ts +3 -0
  108. package/dist/types/init/options.d.ts +3 -0
  109. package/dist/types/number/index.d.ts +1 -0
  110. package/dist/types/number/number-extensions.d.ts +1 -0
  111. package/dist/types/object/index.d.ts +1 -0
  112. package/dist/types/object/object-extensions.d.ts +1 -0
  113. package/dist/types/string/index.d.ts +1 -0
  114. package/dist/types/string/string-extensions.d.ts +1 -0
  115. package/dist/types/types/extension-types.d.ts +9 -0
  116. package/dist/types/types/global-augmentations.d.ts +72 -0
  117. package/dist/types/types/index.d.ts +2 -0
  118. package/dist/types/utils/config.d.ts +4 -0
  119. package/dist/types/utils/defineExtension.d.ts +1 -0
  120. package/dist/types/utils/helpers.d.ts +5 -0
  121. package/dist/types/utils/index.d.ts +3 -0
  122. package/package.json +46 -0
@@ -0,0 +1,72 @@
1
+ declare global {
2
+ interface String {
3
+ toCapitalize(): string;
4
+ toCamelCase(): string;
5
+ toKebabCase(): string;
6
+ toSnakeCase(): string;
7
+ truncate(length: number, suffix?: string): string;
8
+ isEmail(): boolean;
9
+ isUrl(): boolean;
10
+ removeWhitespace(): string;
11
+ reverse(): string;
12
+ isPalindrome(): boolean;
13
+ toTitleCase(): string;
14
+ stripHtml(): string;
15
+ padStart(targetLength: number, padString?: string): string;
16
+ padEnd(targetLength: number, padString?: string): string;
17
+ count(substring: string): number;
18
+ words(): string[];
19
+ lines(): string[];
20
+ }
21
+ interface Array<T> {
22
+ unique(): T[];
23
+ shuffle(): T[];
24
+ chunk(size: number): T[][];
25
+ groupBy<K extends string | number>(keyFn: (item: T) => K): Record<K, T[]>;
26
+ sum(): number;
27
+ average(): number;
28
+ compact(): T[];
29
+ compactTruthy(): T[];
30
+ pluck<K extends keyof T>(key: K): T[K][];
31
+ findLast(predicate: (item: T) => boolean): T | undefined;
32
+ partition(predicate: (item: T) => boolean): [T[], T[]];
33
+ flatten(depth?: number): any[];
34
+ deepFlatten(): any[];
35
+ difference(other: T[]): T[];
36
+ intersection(other: T[]): T[];
37
+ union(other: T[]): T[];
38
+ sample(): T | undefined;
39
+ take(count: number): T[];
40
+ drop(count: number): T[];
41
+ }
42
+ interface Object {
43
+ isEmpty(): boolean;
44
+ pick<T extends Record<string, any>, K extends keyof T>(keys: K[]): Pick<T, K>;
45
+ omit<T extends Record<string, any>, K extends keyof T>(keys: K[]): Omit<T, K>;
46
+ deepClone<T>(): T;
47
+ merge(other: Record<string, any>): Record<string, any>;
48
+ deepFreeze<T>(): T;
49
+ hasPath(path: string): boolean;
50
+ getPath(path: string, defaultValue?: any): any;
51
+ setPath(path: string, value: any): any;
52
+ }
53
+ interface Number {
54
+ toPercent(decimals?: number): string;
55
+ toCurrency(currency?: string, locale?: string): string;
56
+ clamp(min: number, max: number): number;
57
+ isEven(): boolean;
58
+ isOdd(): boolean;
59
+ isPrime(): boolean;
60
+ factorial(): number;
61
+ toOrdinal(): string;
62
+ toRoman(): string;
63
+ inRange(min: number, max: number): boolean;
64
+ round(decimals?: number): number;
65
+ ceil(decimals?: number): number;
66
+ floor(decimals?: number): number;
67
+ abs(): number;
68
+ sign(): number;
69
+ times(callback: (index: number) => void): void;
70
+ }
71
+ }
72
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export * from './extension-types';
2
+ export * from './global-augmentations';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ // Re-export all types
18
+ __exportStar(require("./extension-types"), exports);
19
+ __exportStar(require("./global-augmentations"), exports);
@@ -0,0 +1,4 @@
1
+ import type { 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,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateConfig = validateConfig;
4
+ exports.validatePerformanceSettings = validatePerformanceSettings;
5
+ exports.mergeConfigs = mergeConfigs;
6
+ function validateConfig(config, defaultConfig) {
7
+ return { ...defaultConfig, ...config };
8
+ }
9
+ function validatePerformanceSettings(settings) {
10
+ const validated = {
11
+ enableCaching: settings.enableCaching ?? false,
12
+ maxCacheSize: Math.max(1, settings.maxCacheSize ?? 100),
13
+ enableValidation: settings.enableValidation ?? true,
14
+ };
15
+ return validated;
16
+ }
17
+ function mergeConfigs(base, override) {
18
+ const result = { ...base };
19
+ for (const key in override) {
20
+ if (override[key] !== undefined) {
21
+ result[key] = override[key];
22
+ }
23
+ }
24
+ return result;
25
+ }
@@ -0,0 +1 @@
1
+ export declare function defineExtension<T extends object>(prototype: T, name: string, fn: Function): void;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defineExtension = defineExtension;
4
+ function defineExtension(prototype, name, fn) {
5
+ if (!Object.prototype.hasOwnProperty.call(prototype, name)) {
6
+ Object.defineProperty(prototype, name, {
7
+ value: fn,
8
+ writable: false,
9
+ configurable: false,
10
+ enumerable: false,
11
+ });
12
+ }
13
+ }
@@ -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,37 @@
1
+ "use strict";
2
+ // Shared helper functions for extensions
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.isValidArrayIndex = isValidArrayIndex;
5
+ exports.ensurePositiveInteger = ensurePositiveInteger;
6
+ exports.safeClone = safeClone;
7
+ exports.getPathSegments = getPathSegments;
8
+ exports.hasOwnProperty = hasOwnProperty;
9
+ function isValidArrayIndex(index) {
10
+ return Number.isInteger(index) && index >= 0;
11
+ }
12
+ function ensurePositiveInteger(value, name) {
13
+ if (!Number.isInteger(value) || value < 0) {
14
+ throw new TypeError(`${name} must be a positive integer`);
15
+ }
16
+ }
17
+ function safeClone(obj) {
18
+ if (obj === null || typeof obj !== 'object')
19
+ return obj;
20
+ if (obj instanceof Date)
21
+ return new Date(obj.getTime());
22
+ if (Array.isArray(obj))
23
+ return obj.map((item) => safeClone(item));
24
+ const cloned = {};
25
+ for (const key in obj) {
26
+ if (obj.hasOwnProperty(key)) {
27
+ cloned[key] = safeClone(obj[key]);
28
+ }
29
+ }
30
+ return cloned;
31
+ }
32
+ function getPathSegments(path) {
33
+ return path.split('.').filter((segment) => segment.length > 0);
34
+ }
35
+ function hasOwnProperty(obj, key) {
36
+ return Object.prototype.hasOwnProperty.call(obj, key);
37
+ }
@@ -0,0 +1,3 @@
1
+ export * from './config';
2
+ export * from './helpers';
3
+ export * from './defineExtension';
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ // Re-export all utilities
18
+ __exportStar(require("./config"), exports);
19
+ __exportStar(require("./helpers"), exports);
20
+ __exportStar(require("./defineExtension"), exports);
@@ -0,0 +1 @@
1
+ export declare function extendArray(): void;
@@ -0,0 +1,149 @@
1
+ import { defineExtension } from 'src/utils';
2
+ let arrayExtended = false;
3
+ export function extendArray() {
4
+ if (arrayExtended)
5
+ return;
6
+ arrayExtended = true;
7
+ defineExtension(Array.prototype, 'unique', function () {
8
+ return [...new Set(this)];
9
+ });
10
+ defineExtension(Array.prototype, 'shuffle', function () {
11
+ const arr = [...this];
12
+ for (let i = arr.length - 1; i > 0; i--) {
13
+ const j = Math.floor(Math.random() * (i + 1));
14
+ [arr[i], arr[j]] = [arr[j], arr[i]];
15
+ }
16
+ return arr;
17
+ });
18
+ defineExtension(Array.prototype, 'chunk', function (size) {
19
+ if (!Number.isInteger(size) || size <= 0) {
20
+ throw new TypeError(`chunk: size must be a positive integer, got ${size}`);
21
+ }
22
+ const chunks = [];
23
+ for (let i = 0; i < this.length; i += size) {
24
+ chunks.push(this.slice(i, i + size));
25
+ }
26
+ return chunks;
27
+ });
28
+ defineExtension(Array.prototype, 'groupBy', function (keyFn) {
29
+ if (typeof keyFn !== 'function') {
30
+ throw new TypeError(`groupBy: keyFn must be a function, got ${typeof keyFn}`);
31
+ }
32
+ return this.reduce((groups, item) => {
33
+ const key = keyFn(item);
34
+ if (!groups[key])
35
+ groups[key] = [];
36
+ groups[key].push(item);
37
+ return groups;
38
+ }, {});
39
+ });
40
+ defineExtension(Array.prototype, 'sum', function () {
41
+ if (this.length === 0) {
42
+ throw new TypeError('sum: array must contain at least one number');
43
+ }
44
+ return this.reduce((sum, num) => sum + num, 0);
45
+ });
46
+ defineExtension(Array.prototype, 'average', function () {
47
+ if (this.length === 0) {
48
+ throw new TypeError('average: array must contain at least one number');
49
+ }
50
+ return this.reduce((sum, num) => sum + num, 0) / this.length;
51
+ });
52
+ defineExtension(Array.prototype, 'compact', function () {
53
+ return this.filter((item) => item !== null && item !== undefined && item !== '');
54
+ });
55
+ defineExtension(Array.prototype, 'compactTruthy', function () {
56
+ return this.filter(Boolean);
57
+ });
58
+ defineExtension(Array.prototype, 'pluck', function (key) {
59
+ return this.map((item) => item[key]).filter((val) => val !== undefined);
60
+ });
61
+ defineExtension(Array.prototype, 'findLast', function (predicate) {
62
+ if (typeof predicate !== 'function') {
63
+ throw new TypeError(`findLast: predicate must be a function, got ${typeof predicate}`);
64
+ }
65
+ for (let i = this.length - 1; i >= 0; i--) {
66
+ if (predicate(this[i]))
67
+ return this[i];
68
+ }
69
+ return undefined;
70
+ });
71
+ defineExtension(Array.prototype, 'partition', function (predicate) {
72
+ if (typeof predicate !== 'function') {
73
+ throw new TypeError(`partition: predicate must be a function, got ${typeof predicate}`);
74
+ }
75
+ const truthy = [];
76
+ const falsy = [];
77
+ this.forEach((item) => predicate(item) ? truthy.push(item) : falsy.push(item));
78
+ return [truthy, falsy];
79
+ });
80
+ defineExtension(Array.prototype, 'flatten', function (depth = 1) {
81
+ return depth > 0
82
+ ? this.reduce((acc, val) => acc.concat(Array.isArray(val) ? val.flatten(depth - 1) : val), [])
83
+ : this.slice();
84
+ });
85
+ defineExtension(Array.prototype, 'deepFlatten', function () {
86
+ return this.reduce((acc, val) => acc.concat(Array.isArray(val) ? val.deepFlatten() : val), []);
87
+ });
88
+ defineExtension(Array.prototype, 'difference', function (other) {
89
+ if (!Array.isArray(other)) {
90
+ throw new TypeError(`difference: other must be an array, got ${typeof other}`);
91
+ }
92
+ return this.filter((item) => !other.includes(item));
93
+ });
94
+ defineExtension(Array.prototype, 'intersection', function (other) {
95
+ if (!Array.isArray(other)) {
96
+ throw new TypeError(`intersection: other must be an array, got ${typeof other}`);
97
+ }
98
+ return this.filter((item) => other.includes(item));
99
+ });
100
+ defineExtension(Array.prototype, 'union', function (other) {
101
+ if (!Array.isArray(other)) {
102
+ throw new TypeError(`union: other must be an array, got ${typeof other}`);
103
+ }
104
+ return [...new Set([...this, ...other])];
105
+ });
106
+ defineExtension(Array.prototype, 'sample', function () {
107
+ return this.length > 0
108
+ ? this[Math.floor(Math.random() * this.length)]
109
+ : undefined;
110
+ });
111
+ defineExtension(Array.prototype, 'take', function (count) {
112
+ return this.slice(0, Math.max(0, count));
113
+ });
114
+ defineExtension(Array.prototype, 'drop', function (count) {
115
+ return this.slice(Math.max(0, count));
116
+ });
117
+ defineExtension(Array.prototype, 'uniqueBy', function (keyFn) {
118
+ if (typeof keyFn !== 'function') {
119
+ throw new TypeError(`uniqueBy: keyFn must be a function, got ${typeof keyFn}`);
120
+ }
121
+ const seen = new Set();
122
+ const result = [];
123
+ for (const item of this) {
124
+ const key = keyFn(item);
125
+ if (!seen.has(key)) {
126
+ seen.add(key);
127
+ result.push(item);
128
+ }
129
+ }
130
+ return result;
131
+ });
132
+ defineExtension(Array.prototype, 'sortBy', function (keyFn) {
133
+ if (typeof keyFn !== 'function') {
134
+ throw new TypeError(`sortBy: keyFn must be a function, got ${typeof keyFn}`);
135
+ }
136
+ return [...this].sort((a, b) => {
137
+ const aVal = keyFn(a);
138
+ const bVal = keyFn(b);
139
+ if (aVal < bVal)
140
+ return -1;
141
+ if (aVal > bVal)
142
+ return 1;
143
+ return 0;
144
+ });
145
+ });
146
+ defineExtension(Array.prototype, 'last', function () {
147
+ return this.length > 0 ? this[this.length - 1] : undefined;
148
+ });
149
+ }
@@ -0,0 +1 @@
1
+ export { extendArray } from './array-extensions';
@@ -0,0 +1 @@
1
+ export { extendArray } from './array-extensions';
@@ -0,0 +1,2 @@
1
+ export * from './validation';
2
+ export * from './performance';
@@ -0,0 +1,3 @@
1
+ // Re-export core utilities
2
+ export * from './validation';
3
+ export * from './performance';
@@ -0,0 +1,17 @@
1
+ export interface PerformanceConfig {
2
+ enableCaching?: boolean;
3
+ maxCacheSize?: number;
4
+ enableValidation?: boolean;
5
+ }
6
+ export declare function setPerformanceConfig(newConfig: Partial<PerformanceConfig>): void;
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
+ }
16
+ export declare function makeInternalCacheKey(domain: string, key: string | number): string;
17
+ export declare function withCache<T>(key: string, fn: () => T): T;
@@ -0,0 +1,74 @@
1
+ import { getPackageVersion } from './version';
2
+ const defaultConfig = {
3
+ enableCaching: false,
4
+ maxCacheSize: 100,
5
+ enableValidation: true,
6
+ };
7
+ let config = { ...defaultConfig };
8
+ export function setPerformanceConfig(newConfig) {
9
+ const oldMaxSize = config.maxCacheSize;
10
+ config = { ...config, ...newConfig };
11
+ // Recreate cache if maxCacheSize changed
12
+ if (cache && oldMaxSize !== config.maxCacheSize) {
13
+ cache = new LRUCache(config.maxCacheSize);
14
+ }
15
+ }
16
+ export function getPerformanceConfig() {
17
+ return { ...config };
18
+ }
19
+ // Simple LRU cache for expensive operations
20
+ export class LRUCache {
21
+ constructor(maxSize = 100) {
22
+ this.cache = new Map();
23
+ this.maxSize = maxSize;
24
+ }
25
+ get(key) {
26
+ const value = this.cache.get(key);
27
+ if (value !== undefined) {
28
+ // Move to end (most recently used)
29
+ this.cache.delete(key);
30
+ this.cache.set(key, value);
31
+ }
32
+ return value;
33
+ }
34
+ set(key, value) {
35
+ if (this.cache.has(key)) {
36
+ this.cache.delete(key);
37
+ }
38
+ else if (this.cache.size >= this.maxSize) {
39
+ // Remove least recently used (first item)
40
+ const firstKey = this.cache.keys().next().value;
41
+ if (firstKey !== undefined) {
42
+ this.cache.delete(firstKey);
43
+ }
44
+ }
45
+ this.cache.set(key, value);
46
+ }
47
+ clear() {
48
+ this.cache.clear();
49
+ }
50
+ }
51
+ let cache = null;
52
+ function getOrCreateCache() {
53
+ if (!cache) {
54
+ cache = new LRUCache(config.maxCacheSize);
55
+ }
56
+ return cache;
57
+ }
58
+ export function makeInternalCacheKey(domain, key) {
59
+ const INTERNAL_CACHE_PREFIX = '@js-ext' + getPackageVersion();
60
+ return `${INTERNAL_CACHE_PREFIX}:${domain}:${key}`;
61
+ }
62
+ export function withCache(key, fn) {
63
+ if (!config.enableCaching) {
64
+ return fn();
65
+ }
66
+ const currentCache = getOrCreateCache();
67
+ const cached = currentCache.get(key);
68
+ if (cached !== undefined) {
69
+ return cached;
70
+ }
71
+ const result = fn();
72
+ currentCache.set(key, result);
73
+ return result;
74
+ }
@@ -0,0 +1,4 @@
1
+ export declare function validateExtensionInput(value: any, type: string, methodName: string): void;
2
+ export declare function validateArrayInput<T>(arr: T[], methodName: string): void;
3
+ export declare function validateNumberRange(num: number, min: number, max: number, methodName: string): void;
4
+ export declare function validatePositiveInteger(num: number, methodName: string): void;
@@ -0,0 +1,25 @@
1
+ // Validation utilities for extensions
2
+ export function validateExtensionInput(value, type, methodName) {
3
+ if (value == null) {
4
+ throw new TypeError(`Cannot call ${methodName} on ${value}`);
5
+ }
6
+ const actualType = typeof value;
7
+ if (actualType !== type) {
8
+ throw new TypeError(`${methodName} can only be called on ${type} values, got ${actualType}`);
9
+ }
10
+ }
11
+ export function validateArrayInput(arr, methodName) {
12
+ if (!Array.isArray(arr)) {
13
+ throw new TypeError(`${methodName} can only be called on arrays`);
14
+ }
15
+ }
16
+ export function validateNumberRange(num, min, max, methodName) {
17
+ if (num < min || num > max) {
18
+ throw new RangeError(`${methodName}: number must be between ${min} and ${max}, got ${num}`);
19
+ }
20
+ }
21
+ export function validatePositiveInteger(num, methodName) {
22
+ if (!Number.isInteger(num) || num < 0) {
23
+ throw new TypeError(`${methodName}: expected positive integer, got ${num}`);
24
+ }
25
+ }
@@ -0,0 +1 @@
1
+ export declare const getPackageVersion: () => string;
@@ -0,0 +1,5 @@
1
+ import { createRequire } from 'node:module';
2
+ const requireFn = createRequire('../../package.json');
3
+ export const getPackageVersion = () => {
4
+ return requireFn('../package.json').version;
5
+ };
@@ -0,0 +1,4 @@
1
+ export * from '../string';
2
+ export * from '../array';
3
+ export * from '../object';
4
+ export * from '../number';
@@ -0,0 +1,5 @@
1
+ // Re-export all extensions
2
+ export * from '../string';
3
+ export * from '../array';
4
+ export * from '../object';
5
+ export * from '../number';
@@ -0,0 +1,61 @@
1
+ import '../types/global-augmentations';
2
+ import { extendArray } from './array';
3
+ import { extendNumber } from './number';
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';
10
+ import { ExtensionOptions, PerformanceConfig } from './types/extension-types';
11
+ export { ExtensionOptions, PerformanceConfig };
12
+ export { withCache };
13
+ import { extendAll } from './init/initializer';
14
+ /**
15
+ * Initialize JavaScript prototype extensions
16
+ * @param options - Configure which extensions to enable (default: all enabled)
17
+ */
18
+ export declare function initializeExtensions(options?: ExtensionOptions): void;
19
+ /**
20
+ * Initialize all extensions (convenience function)
21
+ */
22
+ export { extendAll };
23
+ /**
24
+ * Selective prototype extension helpers
25
+ * Initialize only specific extensions
26
+ */
27
+ export declare const extend: {
28
+ string: typeof extendString;
29
+ array: typeof extendArray;
30
+ object: typeof extendObject;
31
+ number: typeof extendNumber;
32
+ };
33
+ export { validateExtensionInput, validateArrayInput, validateNumberRange, validatePositiveInteger, };
34
+ export { validateConfig, validatePerformanceSettings, mergeConfigs, isValidArrayIndex, ensurePositiveInteger, safeClone, getPathSegments, hasOwnProperty, };
35
+ export { LRUCache, setPerformanceConfig, getPerformanceConfig };
36
+ declare const _default: {
37
+ initializeExtensions: typeof initializeExtensions;
38
+ extendAll: typeof extendAll;
39
+ extend: {
40
+ string: typeof extendString;
41
+ array: typeof extendArray;
42
+ object: typeof extendObject;
43
+ number: typeof extendNumber;
44
+ };
45
+ LRUCache: typeof LRUCache;
46
+ setPerformanceConfig: typeof setPerformanceConfig;
47
+ getPerformanceConfig: typeof getPerformanceConfig;
48
+ validateExtensionInput: typeof validateExtensionInput;
49
+ validateArrayInput: typeof validateArrayInput;
50
+ validateNumberRange: typeof validateNumberRange;
51
+ validatePositiveInteger: typeof validatePositiveInteger;
52
+ validateConfig: typeof validateConfig;
53
+ validatePerformanceSettings: typeof validatePerformanceSettings;
54
+ mergeConfigs: typeof mergeConfigs;
55
+ isValidArrayIndex: typeof isValidArrayIndex;
56
+ ensurePositiveInteger: typeof ensurePositiveInteger;
57
+ safeClone: typeof safeClone;
58
+ getPathSegments: typeof getPathSegments;
59
+ hasOwnProperty: typeof hasOwnProperty;
60
+ };
61
+ export default _default;
@@ -0,0 +1,68 @@
1
+ // Import types first
2
+ import '../types/global-augmentations';
3
+ import { extendArray } from './array';
4
+ import { extendNumber } from './number';
5
+ import { extendObject } from './object';
6
+ // Import extension modules
7
+ import { extendString } from './string';
8
+ // Import core utilities
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';
15
+ // Export withCache for use in extensions
16
+ export { withCache };
17
+ // Import initialization functions
18
+ import { extendAll, initExtensions } from './init/initializer';
19
+ /**
20
+ * Initialize JavaScript prototype extensions
21
+ * @param options - Configure which extensions to enable (default: all enabled)
22
+ */
23
+ export function initializeExtensions(options = {}) {
24
+ initExtensions(options);
25
+ }
26
+ /**
27
+ * Initialize all extensions (convenience function)
28
+ */
29
+ export { extendAll };
30
+ /**
31
+ * Selective prototype extension helpers
32
+ * Initialize only specific extensions
33
+ */
34
+ export const extend = {
35
+ string: extendString,
36
+ array: extendArray,
37
+ object: extendObject,
38
+ number: extendNumber,
39
+ };
40
+ // Export validation utilities
41
+ export { validateExtensionInput, validateArrayInput, validateNumberRange, validatePositiveInteger, };
42
+ // Export utility functions
43
+ export { validateConfig, validatePerformanceSettings, mergeConfigs, isValidArrayIndex, ensurePositiveInteger, safeClone, getPathSegments, hasOwnProperty, };
44
+ // Export performance utilities
45
+ export { LRUCache, setPerformanceConfig, getPerformanceConfig };
46
+ // Default export
47
+ export default {
48
+ initializeExtensions,
49
+ extendAll,
50
+ extend,
51
+ LRUCache,
52
+ setPerformanceConfig,
53
+ getPerformanceConfig,
54
+ // Validation utilities
55
+ validateExtensionInput,
56
+ validateArrayInput,
57
+ validateNumberRange,
58
+ validatePositiveInteger,
59
+ // Utility functions
60
+ validateConfig,
61
+ validatePerformanceSettings,
62
+ mergeConfigs,
63
+ isValidArrayIndex,
64
+ ensurePositiveInteger,
65
+ safeClone,
66
+ getPathSegments,
67
+ hasOwnProperty,
68
+ };