@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,2 @@
1
+ export * from './initializer';
2
+ export * from './options';
@@ -0,0 +1,3 @@
1
+ // Re-export initialization logic
2
+ export * from './initializer';
3
+ export * from './options';
@@ -0,0 +1,3 @@
1
+ import type { ExtensionOptions } from '../types/extension-types';
2
+ export declare function initExtensions(options?: ExtensionOptions): void;
3
+ export declare function extendAll(): void;
@@ -0,0 +1,24 @@
1
+ // Extension initialization logic
2
+ import { extendArray } from '../array';
3
+ import { setPerformanceConfig } from '../core/performance';
4
+ import { extendNumber } from '../number';
5
+ import { extendObject } from '../object';
6
+ import { extendString } from '../string';
7
+ export function initExtensions(options = {}) {
8
+ const { string = true, array = true, object = true, number = true, performance, } = options;
9
+ if (performance) {
10
+ // Set performance config if provided
11
+ setPerformanceConfig(performance);
12
+ }
13
+ if (string)
14
+ extendString();
15
+ if (array)
16
+ extendArray();
17
+ if (object)
18
+ extendObject();
19
+ if (number)
20
+ extendNumber();
21
+ }
22
+ export function extendAll() {
23
+ initExtensions();
24
+ }
@@ -0,0 +1,3 @@
1
+ import type { 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';
@@ -0,0 +1 @@
1
+ export declare function extendNumber(): void;
@@ -0,0 +1,139 @@
1
+ import { defineExtension } from 'src/utils';
2
+ import { makeInternalCacheKey, withCache } from '../core/performance';
3
+ let numberExtended = false;
4
+ export function extendNumber() {
5
+ if (numberExtended)
6
+ return;
7
+ numberExtended = true;
8
+ defineExtension(Number.prototype, 'toPercent', function (decimals = 2) {
9
+ return `${(this * 100).toFixed(decimals)}%`;
10
+ });
11
+ defineExtension(Number.prototype, 'toCurrency', function (currency = 'USD', locale = 'en-US') {
12
+ return new Intl.NumberFormat(locale, {
13
+ style: 'currency',
14
+ currency,
15
+ }).format(this);
16
+ });
17
+ defineExtension(Number.prototype, 'clamp', function (min, max) {
18
+ if (min > max)
19
+ throw new RangeError(`clamp: min (${min}) cannot be greater than max (${max})`);
20
+ return Math.min(Math.max(this, min), max);
21
+ });
22
+ defineExtension(Number.prototype, 'isEven', function () {
23
+ return this % 2 === 0;
24
+ });
25
+ defineExtension(Number.prototype, 'isOdd', function () {
26
+ return this % 2 !== 0;
27
+ });
28
+ defineExtension(Number.prototype, 'isPrime', function () {
29
+ const num = this;
30
+ return withCache(makeInternalCacheKey('prime', num), () => {
31
+ if (num < 2)
32
+ return false;
33
+ for (let i = 2; i <= Math.sqrt(num); i++)
34
+ if (num % i === 0)
35
+ return false;
36
+ return true;
37
+ });
38
+ });
39
+ defineExtension(Number.prototype, 'factorial', function () {
40
+ const num = Math.floor(this);
41
+ return withCache(makeInternalCacheKey('factorial', num), () => {
42
+ if (num < 0)
43
+ return NaN;
44
+ if (num <= 1)
45
+ return 1;
46
+ let result = 1;
47
+ for (let i = 2; i <= num; i++)
48
+ result *= i;
49
+ return result;
50
+ });
51
+ });
52
+ defineExtension(Number.prototype, 'toOrdinal', function () {
53
+ const num = Math.floor(this);
54
+ const suffix = ['th', 'st', 'nd', 'rd'];
55
+ const v = num % 100;
56
+ return num + (suffix[(v - 20) % 10] || suffix[v] || suffix[0]);
57
+ });
58
+ defineExtension(Number.prototype, 'toRoman', function () {
59
+ const num = Math.floor(this);
60
+ if (num <= 0)
61
+ throw new RangeError('toRoman: number must be positive');
62
+ if (num >= 4000)
63
+ throw new RangeError('toRoman: number must be less than 4000');
64
+ return withCache(makeInternalCacheKey('roman', num), () => {
65
+ const values = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
66
+ const symbols = [
67
+ 'M',
68
+ 'CM',
69
+ 'D',
70
+ 'CD',
71
+ 'C',
72
+ 'XC',
73
+ 'L',
74
+ 'XL',
75
+ 'X',
76
+ 'IX',
77
+ 'V',
78
+ 'IV',
79
+ 'I',
80
+ ];
81
+ let n = num;
82
+ let result = '';
83
+ for (let i = 0; i < values.length; i++) {
84
+ while (n >= values[i]) {
85
+ result += symbols[i];
86
+ n -= values[i];
87
+ }
88
+ }
89
+ return result;
90
+ });
91
+ });
92
+ defineExtension(Number.prototype, 'inRange', function (min, max) {
93
+ return this >= min && this <= max;
94
+ });
95
+ defineExtension(Number.prototype, 'round', function (decimals = 0) {
96
+ if (!Number.isInteger(decimals) || decimals < 0)
97
+ throw new TypeError('round: decimals must be non-negative integer');
98
+ const factor = Math.pow(10, decimals);
99
+ return Math.round(this * factor) / factor;
100
+ });
101
+ defineExtension(Number.prototype, 'ceil', function (decimals = 0) {
102
+ if (!Number.isInteger(decimals) || decimals < 0)
103
+ throw new TypeError('ceil: decimals must be non-negative integer');
104
+ const factor = Math.pow(10, decimals);
105
+ return Math.ceil(this * factor) / factor;
106
+ });
107
+ defineExtension(Number.prototype, 'floor', function (decimals = 0) {
108
+ if (!Number.isInteger(decimals) || decimals < 0)
109
+ throw new TypeError('floor: decimals must be non-negative integer');
110
+ const factor = Math.pow(10, decimals);
111
+ return Math.floor(this * factor) / factor;
112
+ });
113
+ defineExtension(Number.prototype, 'abs', function () {
114
+ return Math.abs(this);
115
+ });
116
+ defineExtension(Number.prototype, 'sign', function () {
117
+ return Math.sign(this);
118
+ });
119
+ defineExtension(Number.prototype, 'times', function (callback) {
120
+ if (typeof callback !== 'function')
121
+ throw new TypeError('times: callback must be a function');
122
+ for (let i = 0; i < Math.floor(this); i++)
123
+ callback(i);
124
+ });
125
+ defineExtension(Number.prototype, 'toFixedNumber', function (decimals = 0) {
126
+ if (!Number.isInteger(decimals) || decimals < 0) {
127
+ throw new TypeError(`toFixedNumber: decimals must be a non-negative integer, got ${decimals}`);
128
+ }
129
+ const factor = Math.pow(10, decimals);
130
+ return Math.round(this.valueOf() * factor) / factor;
131
+ });
132
+ defineExtension(Number.prototype, 'randomUpTo', function () {
133
+ const max = this.valueOf();
134
+ if (!Number.isFinite(max)) {
135
+ throw new TypeError(`randomUpTo: number must be finite, got ${max}`);
136
+ }
137
+ return Math.random() * max;
138
+ });
139
+ }
@@ -0,0 +1 @@
1
+ export { extendObject } from './object-extensions';
@@ -0,0 +1 @@
1
+ export { extendObject } from './object-extensions';
@@ -0,0 +1 @@
1
+ export declare function extendObject(): void;
@@ -0,0 +1,145 @@
1
+ import { defineExtension } from 'src/utils';
2
+ let objectExtended = false;
3
+ export function extendObject() {
4
+ if (objectExtended)
5
+ return;
6
+ objectExtended = true;
7
+ defineExtension(Object.prototype, 'isEmpty', function () {
8
+ return Object.keys(this).length === 0;
9
+ });
10
+ defineExtension(Object.prototype, 'pick', function (keys) {
11
+ if (!Array.isArray(keys))
12
+ throw new TypeError('pick: keys must be an array');
13
+ if (!keys.length)
14
+ throw new TypeError('pick: keys array cannot be empty');
15
+ const result = {};
16
+ keys.forEach((key) => {
17
+ if (key in this)
18
+ result[key] = this[key];
19
+ });
20
+ return result;
21
+ });
22
+ defineExtension(Object.prototype, 'omit', function (keys) {
23
+ if (!Array.isArray(keys))
24
+ throw new TypeError('omit: keys must be an array');
25
+ if (!keys.length)
26
+ throw new TypeError('omit: keys array cannot be empty');
27
+ const result = { ...this };
28
+ keys.forEach((key) => delete result[key]);
29
+ return result;
30
+ });
31
+ defineExtension(Object.prototype, 'deepClone', function () {
32
+ const visited = new WeakSet();
33
+ function deepCloneSafe(obj) {
34
+ if (obj === null || typeof obj !== 'object')
35
+ return obj;
36
+ if (visited.has(obj))
37
+ throw new Error('Circular reference detected in deepClone');
38
+ visited.add(obj);
39
+ if (obj instanceof Date)
40
+ return new Date(obj.getTime());
41
+ if (Array.isArray(obj))
42
+ return obj.map((item) => deepCloneSafe(item));
43
+ const cloned = {};
44
+ Object.keys(obj).forEach((key) => {
45
+ cloned[key] = deepCloneSafe(obj[key]);
46
+ });
47
+ return cloned;
48
+ }
49
+ return deepCloneSafe(this);
50
+ });
51
+ defineExtension(Object.prototype, 'merge', function (other) {
52
+ return { ...this, ...other };
53
+ });
54
+ defineExtension(Object.prototype, 'deepFreeze', function () {
55
+ Object.getOwnPropertyNames(this).forEach((name) => {
56
+ const value = this[name];
57
+ if (value && typeof value === 'object')
58
+ value.deepFreeze?.();
59
+ });
60
+ return Object.freeze(this);
61
+ });
62
+ defineExtension(Object.prototype, 'hasPath', function (path) {
63
+ if (!path.trim())
64
+ throw new TypeError('hasPath: path cannot be empty');
65
+ let current = this;
66
+ return path.split('.').every((key) => {
67
+ if (current == null || !(key in current))
68
+ return false;
69
+ current = current[key];
70
+ return true;
71
+ });
72
+ });
73
+ defineExtension(Object.prototype, 'getPath', function (path, defaultValue) {
74
+ if (!path.trim())
75
+ throw new TypeError('getPath: path cannot be empty');
76
+ return path
77
+ .split('.')
78
+ .reduce((acc, key) => (acc && key in acc ? acc[key] : defaultValue), this);
79
+ });
80
+ defineExtension(Object.prototype, 'setPath', function (path, value) {
81
+ if (!path.trim())
82
+ throw new TypeError('setPath: path cannot be empty');
83
+ const keys = path.split('.');
84
+ let current = this;
85
+ for (let i = 0; i < keys.length - 1; i++) {
86
+ if (!(keys[i] in current) || typeof current[keys[i]] !== 'object')
87
+ current[keys[i]] = {};
88
+ current = current[keys[i]];
89
+ }
90
+ current[keys[keys.length - 1]] = value;
91
+ return this;
92
+ });
93
+ defineExtension(Object.prototype, 'mapValues', function (fn) {
94
+ if (typeof fn !== 'function') {
95
+ throw new TypeError(`mapValues: fn must be a function, got ${typeof fn}`);
96
+ }
97
+ const result = {};
98
+ for (const key in this) {
99
+ if (Object.prototype.hasOwnProperty.call(this, key)) {
100
+ result[key] = fn(this[key], key);
101
+ }
102
+ }
103
+ return result;
104
+ });
105
+ defineExtension(Object.prototype, 'mapKeys', function (fn) {
106
+ if (typeof fn !== 'function') {
107
+ throw new TypeError(`mapKeys: fn must be a function, got ${typeof fn}`);
108
+ }
109
+ const result = {};
110
+ for (const key in this) {
111
+ if (Object.prototype.hasOwnProperty.call(this, key)) {
112
+ const newKey = fn(key);
113
+ result[newKey] = this[key];
114
+ }
115
+ }
116
+ return result;
117
+ });
118
+ defineExtension(Object.prototype, 'filterKeys', function (keys) {
119
+ if (!Array.isArray(keys)) {
120
+ throw new TypeError(`filterKeys: keys must be an array, got ${typeof keys}`);
121
+ }
122
+ const result = {};
123
+ for (const key of keys) {
124
+ if (key in this) {
125
+ result[key] = this[key];
126
+ }
127
+ }
128
+ return result;
129
+ });
130
+ defineExtension(Object.prototype, 'filterValues', function (fn) {
131
+ if (typeof fn !== 'function') {
132
+ throw new TypeError(`filterValues: fn must be a function, got ${typeof fn}`);
133
+ }
134
+ const result = {};
135
+ for (const key in this) {
136
+ if (Object.prototype.hasOwnProperty.call(this, key)) {
137
+ const val = this[key];
138
+ if (fn(val, key)) {
139
+ result[key] = val;
140
+ }
141
+ }
142
+ }
143
+ return result;
144
+ });
145
+ }
@@ -0,0 +1 @@
1
+ export { extendString } from './string-extensions';
@@ -0,0 +1 @@
1
+ export { extendString } from './string-extensions';
@@ -0,0 +1 @@
1
+ export declare function extendString(): void;
@@ -0,0 +1,124 @@
1
+ import { defineExtension } from 'src/utils';
2
+ let stringExtended = false;
3
+ export function extendString() {
4
+ if (stringExtended)
5
+ return;
6
+ stringExtended = true;
7
+ defineExtension(String.prototype, 'toCapitalize', function () {
8
+ return this.charAt(0).toUpperCase() + this.slice(1).toLowerCase();
9
+ });
10
+ defineExtension(String.prototype, 'toCamelCase', function () {
11
+ return this.replace(/[-_\s]+(.)?/g, (_, char) => char ? char.toUpperCase() : '');
12
+ });
13
+ defineExtension(String.prototype, 'toKebabCase', function () {
14
+ return this.replace(/([a-z])([A-Z])/g, '$1-$2')
15
+ .replace(/[\s_]+/g, '-')
16
+ .toLowerCase();
17
+ });
18
+ defineExtension(String.prototype, 'toSnakeCase', function () {
19
+ return this.replace(/([a-z])([A-Z])/g, '$1_$2')
20
+ .replace(/[\s-]+/g, '_')
21
+ .toLowerCase();
22
+ });
23
+ defineExtension(String.prototype, 'truncate', function (length, suffix = '...') {
24
+ if (!Number.isInteger(length) || length < 0) {
25
+ throw new TypeError(`truncate: length must be a non-negative integer, got ${length}`);
26
+ }
27
+ return this.length > length
28
+ ? this.substring(0, length) + suffix
29
+ : this.toString();
30
+ });
31
+ defineExtension(String.prototype, 'isEmail', function () {
32
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
33
+ return emailRegex.test(this.toString());
34
+ });
35
+ defineExtension(String.prototype, 'isUrl', function () {
36
+ try {
37
+ new URL(this.toString());
38
+ return true;
39
+ }
40
+ catch {
41
+ return false;
42
+ }
43
+ });
44
+ defineExtension(String.prototype, 'removeWhitespace', function () {
45
+ return this.replace(/\s+/g, '');
46
+ });
47
+ defineExtension(String.prototype, 'reverse', function () {
48
+ return this.split('').reverse().join('');
49
+ });
50
+ defineExtension(String.prototype, 'isPalindrome', function () {
51
+ const cleaned = this.toLowerCase().replace(/[^a-z0-9]/g, '');
52
+ return cleaned === cleaned.split('').reverse().join('');
53
+ });
54
+ defineExtension(String.prototype, 'toTitleCase', function () {
55
+ return this.replace(/\w\S*/g, (txt) => txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase());
56
+ });
57
+ defineExtension(String.prototype, 'stripHtml', function () {
58
+ return this.replace(/<[^>]*>/g, '');
59
+ });
60
+ defineExtension(String.prototype, 'padStart', function (targetLength, padString = ' ') {
61
+ if (!Number.isInteger(targetLength) || targetLength < 0) {
62
+ throw new TypeError(`padStart: targetLength must be a non-negative integer, got ${targetLength}`);
63
+ }
64
+ if (typeof padString !== 'string') {
65
+ throw new TypeError(`padStart: padString must be a string, got ${typeof padString}`);
66
+ }
67
+ if (padString.length === 0) {
68
+ throw new TypeError('padStart: padString cannot be empty');
69
+ }
70
+ return this.toString().padStart(targetLength, padString);
71
+ });
72
+ defineExtension(String.prototype, 'padEnd', function (targetLength, padString = ' ') {
73
+ if (!Number.isInteger(targetLength) || targetLength < 0) {
74
+ throw new TypeError(`padEnd: targetLength must be a non-negative integer, got ${targetLength}`);
75
+ }
76
+ if (typeof padString !== 'string') {
77
+ throw new TypeError(`padEnd: padString must be a string, got ${typeof padString}`);
78
+ }
79
+ if (padString.length === 0) {
80
+ throw new TypeError('padEnd: padString cannot be empty');
81
+ }
82
+ return this.toString().padEnd(targetLength, padString);
83
+ });
84
+ defineExtension(String.prototype, 'count', function (substring) {
85
+ if (typeof substring !== 'string') {
86
+ throw new TypeError(`count: substring must be a string, got ${typeof substring}`);
87
+ }
88
+ if (substring === '') {
89
+ throw new TypeError('count: substring cannot be empty');
90
+ }
91
+ const escaped = substring.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
92
+ return (this.match(new RegExp(escaped, 'g')) || []).length;
93
+ });
94
+ defineExtension(String.prototype, 'words', function () {
95
+ return this.trim()
96
+ .split(/\s+/)
97
+ .filter((word) => word.length > 0);
98
+ });
99
+ defineExtension(String.prototype, 'lines', function () {
100
+ return this.split(/\r?\n/);
101
+ });
102
+ defineExtension(String.prototype, 'capitalizeWords', function () {
103
+ return this.toString().replace(/\b\w/g, (char) => char.toUpperCase());
104
+ });
105
+ defineExtension(String.prototype, 'reverseWords', function () {
106
+ return this.toString().split(/\s+/).reverse().join(' ');
107
+ });
108
+ defineExtension(String.prototype, 'truncateWords', function (count, suffix = '...') {
109
+ if (!Number.isInteger(count) || count < 0) {
110
+ throw new TypeError(`truncateWords: count must be a non-negative integer, got ${count}`);
111
+ }
112
+ const words = this.toString().split(/\s+/);
113
+ if (words.length <= count)
114
+ return this.toString();
115
+ return words.slice(0, count).join(' ') + suffix;
116
+ });
117
+ defineExtension(String.prototype, 'slugify', function () {
118
+ return this.toString()
119
+ .toLowerCase()
120
+ .replace(/[^\w\s-]/g, '')
121
+ .trim()
122
+ .replace(/[\s_-]+/g, '-');
123
+ });
124
+ }
@@ -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,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 @@
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 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,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 @@
1
+ export declare function defineExtension<T extends object>(prototype: T, name: string, fn: Function): void;
@@ -0,0 +1,10 @@
1
+ export function defineExtension(prototype, name, fn) {
2
+ if (!Object.prototype.hasOwnProperty.call(prototype, name)) {
3
+ Object.defineProperty(prototype, name, {
4
+ value: fn,
5
+ writable: false,
6
+ configurable: false,
7
+ enumerable: false,
8
+ });
9
+ }
10
+ }
@@ -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;