toolbox-x 1.2.1 → 2.0.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.
- package/dist/{Color-Dsut0Bex.d.cts → Color-B8MR8Vp0.d.cts} +1 -1
- package/dist/{Color-DCfoQk_-.d.mts → Color-D2MfZx7L.d.mts} +1 -1
- package/dist/{Stylog-DXZtHAbp.d.mts → Stylog-CSbLtqrZ.d.mts} +5 -5
- package/dist/{Stylog-TyLCTRtT.d.cts → Stylog-DF0CWtZb.d.cts} +5 -5
- package/dist/{area-CvSC96va.d.mts → area-C4tDXnGC.d.mts} +3 -3
- package/dist/{area-CcRQ6TfR.d.cts → area-CMJZ0gVm.d.cts} +3 -3
- package/dist/{array-B6jWzJ4F.d.mts → array-26Vs2HCs.d.mts} +1 -1
- package/dist/{array-CqDu610k.d.cts → array-DJAq9Qj8.d.cts} +1 -1
- package/dist/{basics-K8BDSYD6.cjs → basics-CJmdhXoo.cjs} +567 -14
- package/dist/{basics-1_M7UvCn.mjs → basics-CebgkY-n.mjs} +449 -16
- package/dist/{basics-KobRNhV-.d.cts → basics-Cis9Ej6c.d.mts} +5 -5
- package/dist/{basics-V5M2oltn.d.mts → basics-D4yU0NQ_.d.cts} +5 -5
- package/dist/{case-uKFzt5TY.cjs → case-Bd7QLHYw.cjs} +3 -3
- package/dist/{case-KdrBKjjK.d.mts → case-ChRzRBnY.d.mts} +12 -12
- package/dist/{case-BQwn5N-k.mjs → case-DBC4Rj0h.mjs} +3 -3
- package/dist/{case--Vjea9DS.d.cts → case-DkYSKSeV.d.cts} +12 -12
- package/dist/change-case.cjs +1 -1
- package/dist/change-case.d.cts +1 -1
- package/dist/change-case.d.mts +1 -1
- package/dist/change-case.mjs +1 -1
- package/dist/colors.d.cts +2 -2
- package/dist/colors.d.mts +2 -2
- package/dist/constants.d.cts +1 -1
- package/dist/constants.d.mts +1 -1
- package/dist/converter.cjs +2 -2
- package/dist/converter.d.cts +2 -2
- package/dist/converter.d.mts +2 -2
- package/dist/converter.mjs +2 -2
- package/dist/date.cjs +10 -10
- package/dist/date.d.cts +4 -4
- package/dist/date.d.mts +4 -4
- package/dist/date.mjs +10 -10
- package/dist/dom.cjs +5 -6
- package/dist/dom.d.cts +3 -3
- package/dist/dom.d.mts +3 -3
- package/dist/dom.mjs +4 -5
- package/dist/{form-DoQGMTOc.d.mts → form-Cp1OyCRI.d.cts} +2 -2
- package/dist/{form-mP-nl8EC.d.cts → form-DPdS2AhM.d.mts} +2 -2
- package/dist/guards-B2s2wlVN.mjs +425 -0
- package/dist/{guards-C0smSAKC.mjs → guards-BK1QuvFZ.mjs} +2 -2
- package/dist/{guards-ClGDJrQp.cjs → guards-Bsh6Bfdq.cjs} +2 -2
- package/dist/{guards-0VjySrPM.cjs → guards-DMJcjPDt.cjs} +279 -3
- package/dist/guards.cjs +9 -8
- package/dist/guards.d.cts +6 -5
- package/dist/guards.d.mts +6 -5
- package/dist/guards.mjs +5 -5
- package/dist/{hash-BcoFHSu1.d.cts → hash-DfhOK0Fi.d.mts} +1 -1
- package/dist/{hash-GYRx2ee_.d.mts → hash-IdZN0mIe.d.cts} +1 -1
- package/dist/hash.cjs +8 -8
- package/dist/hash.d.cts +8 -8
- package/dist/hash.d.mts +8 -8
- package/dist/hash.mjs +4 -5
- package/dist/{http-status-xrlR-LlB.d.mts → http-status-B-yBZr-J.d.mts} +1 -1
- package/dist/{http-status-C0DOpCDf.d.cts → http-status-Dq_hoSG6.d.cts} +1 -1
- package/dist/http-status.cjs +4 -4
- package/dist/http-status.d.cts +6 -6
- package/dist/http-status.d.mts +6 -6
- package/dist/http-status.mjs +4 -4
- package/dist/index-C5FoCCbF.d.cts +292 -0
- package/dist/index-CIJWxnDS.d.mts +292 -0
- package/dist/index.cjs +67 -248
- package/dist/index.d.cts +25 -280
- package/dist/index.d.mts +25 -280
- package/dist/index.mjs +11 -194
- package/dist/{object-ChFVh95z.d.cts → object-X5fSMx-I.d.cts} +13 -1
- package/dist/{object-ChFVh95z.d.mts → object-X5fSMx-I.d.mts} +13 -1
- package/dist/{objectify-DEnFpPt1.mjs → objectify-CQa8gQib.mjs} +3 -4
- package/dist/{objectify-DewBSJP_.cjs → objectify-xQvZS3UI.cjs} +5 -6
- package/dist/paginator.d.cts +1 -1
- package/dist/paginator.d.mts +1 -1
- package/dist/{parse-DovagZFA.cjs → parse-DT7jbWx7.cjs} +3 -3
- package/dist/{parse-BhZ6-tKg.mjs → parse-erxBG2hd.mjs} +3 -3
- package/dist/{pluralizer-CdG-VJ6t.d.cts → pluralizer-B8vuljyy.d.cts} +1 -1
- package/dist/{pluralizer-D2Lh8CdU.d.mts → pluralizer-DOdDskzF.d.mts} +1 -1
- package/dist/pluralizer.cjs +6 -6
- package/dist/pluralizer.d.cts +6 -6
- package/dist/pluralizer.d.mts +6 -6
- package/dist/pluralizer.mjs +6 -6
- package/dist/{specials-Cye93-uo.mjs → specials-Hq5Ncd6y.mjs} +2 -2
- package/dist/{specials-BM6cx43o.cjs → specials-dkYP1Nh2.cjs} +2 -2
- package/dist/{string-CkwTVFeL.d.mts → string-C51m7T6d.d.mts} +4 -2
- package/dist/{string-Dq2b8rcN.d.cts → string-CO7HP50i.d.cts} +4 -2
- package/dist/stylog.cjs +5 -5
- package/dist/stylog.d.cts +2 -2
- package/dist/stylog.d.mts +2 -2
- package/dist/stylog.mjs +5 -5
- package/dist/types/array.d.cts +1 -1
- package/dist/types/array.d.mts +1 -1
- package/dist/types/colors.d.cts +1 -1
- package/dist/types/colors.d.mts +1 -1
- package/dist/types/converter.d.cts +1 -1
- package/dist/types/converter.d.mts +1 -1
- package/dist/types/date.d.cts +1 -1
- package/dist/types/date.d.mts +1 -1
- package/dist/types/form.d.cts +1 -1
- package/dist/types/form.d.mts +1 -1
- package/dist/types/hash.d.cts +1 -1
- package/dist/types/hash.d.mts +1 -1
- package/dist/types/http-status.d.cts +1 -1
- package/dist/types/http-status.d.mts +1 -1
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.mts +2 -2
- package/dist/types/number.d.cts +1 -1
- package/dist/types/number.d.mts +1 -1
- package/dist/types/object.d.cts +2 -2
- package/dist/types/object.d.mts +2 -2
- package/dist/types/pluralizer.d.cts +1 -1
- package/dist/types/pluralizer.d.mts +1 -1
- package/dist/types/string.d.cts +2 -2
- package/dist/types/string.d.mts +2 -2
- package/dist/types/stylog.d.cts +1 -1
- package/dist/types/stylog.d.mts +1 -1
- package/dist/types/utils.d.cts +1 -1
- package/dist/types/utils.d.mts +1 -1
- package/dist/{utilities-CzyXCRHM.cjs → utilities-CWV1GPGY.cjs} +1 -1
- package/dist/{utilities-B9axOvOX.mjs → utilities-DPscNbS1.mjs} +1 -1
- package/dist/{uuid-DgTBxcVu.d.cts → uuid-BUI3Jt8n.d.cts} +3 -3
- package/dist/{uuid-Yc3Uu8qr.d.mts → uuid-mEiy14sf.d.mts} +3 -3
- package/dist/verbalizer.cjs +3 -3
- package/dist/verbalizer.d.cts +3 -3
- package/dist/verbalizer.d.mts +3 -3
- package/dist/verbalizer.mjs +3 -3
- package/package.json +7 -6
- package/dist/guards-DeO4ukiK.mjs +0 -221
- package/dist/utils-BxguWSoa.cjs +0 -568
- package/dist/utils-DXovsTKs.mjs +0 -449
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { G as ConditionFns, Jr as ProtoMethodOptions, K as Constructor, U as ClassDetails, dt as Primitive, mt as VoidFn, nt as Maybe, q as DelayedFn, vr as ArrayOfObjectsToStringOptions, y as GenericObject, yr as ArrayOfPrimitivesToStringOptions } from "./object-X5fSMx-I.mjs";
|
|
18
|
+
import { a as Flattened } from "./array-26Vs2HCs.mjs";
|
|
19
|
+
|
|
20
|
+
//#region src/array/basics.d.ts
|
|
21
|
+
/**
|
|
22
|
+
* * Flattens a nested array recursively or wraps any non-array data type in an array.
|
|
23
|
+
*
|
|
24
|
+
* @param input - The input value, which can be a nested array or a non-array value.
|
|
25
|
+
* @returns A fully flattened array of type `Flatten<T>`. If the input is not an array, it wraps it in a single-element array.
|
|
26
|
+
*/
|
|
27
|
+
declare const flattenArray: <T>(input: T | T[]) => Flattened<T>[];
|
|
28
|
+
/**
|
|
29
|
+
* * Filters an array of objects based on multiple conditions for specified keys.
|
|
30
|
+
*
|
|
31
|
+
* @param array - The array of objects to filter.
|
|
32
|
+
* @param conditions - An object where keys represent the property names and values represent filter conditions.
|
|
33
|
+
* The conditions can be a function `(value: T[K]) => boolean`.
|
|
34
|
+
* @returns The filtered array of objects.
|
|
35
|
+
* @throws `Error` If the input is not a valid array.
|
|
36
|
+
*
|
|
37
|
+
* @remarks Use `findAll` instance method from `Finder` class for **more advanced filtering and searching.**
|
|
38
|
+
*/
|
|
39
|
+
declare const filterArrayOfObjects: <T extends GenericObject>(array: Maybe<T[]>, conditions: ConditionFns<T>) => T[];
|
|
40
|
+
/**
|
|
41
|
+
* * Checks if a value is an empty array or an array with only empty values.
|
|
42
|
+
*
|
|
43
|
+
* @param value - The value to check.
|
|
44
|
+
* @returns `true` if the value is not an array, an empty array, or an array containing only `null`, `undefined`, empty objects, or empty arrays.
|
|
45
|
+
*/
|
|
46
|
+
declare const isInvalidOrEmptyArray: <T>(value: T) => boolean;
|
|
47
|
+
/**
|
|
48
|
+
* * Shuffle the elements of an array.
|
|
49
|
+
*
|
|
50
|
+
* @param array Array to shuffle.
|
|
51
|
+
* @returns Shuffled array.
|
|
52
|
+
*/
|
|
53
|
+
declare const shuffleArray: <T>(array: T[]) => T[];
|
|
54
|
+
/**
|
|
55
|
+
* * Get the last element of an array.
|
|
56
|
+
*
|
|
57
|
+
* @param array Array to get the last element from.
|
|
58
|
+
* @returns The last element or `undefined` if the array is empty.
|
|
59
|
+
*/
|
|
60
|
+
declare const getLastArrayElement: <T>(array: T[]) => Maybe<T>;
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/number/prime.d.ts
|
|
63
|
+
/**
|
|
64
|
+
* * Checks if a number is prime.
|
|
65
|
+
*
|
|
66
|
+
* @param number The number to check.
|
|
67
|
+
* @returns Boolean: `true` if the number is prime, otherwise `false`.
|
|
68
|
+
*/
|
|
69
|
+
declare const isPrime: (number: number) => boolean;
|
|
70
|
+
/**
|
|
71
|
+
* * Find prime numbers in a given range.
|
|
72
|
+
*
|
|
73
|
+
* @param start The starting number of the range. Default is `1`.
|
|
74
|
+
* @param end The ending number of the range. Default is `1000`.
|
|
75
|
+
* @returns An array of prime numbers within the range (inclusive).
|
|
76
|
+
*/
|
|
77
|
+
declare const findPrimeNumbers: (start?: number, end?: number) => number[];
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/utils/index.d.ts
|
|
80
|
+
/**
|
|
81
|
+
* * Deeply compare two values (arrays, objects, or primitive values).
|
|
82
|
+
*
|
|
83
|
+
* @param a First value to compare.
|
|
84
|
+
* @param b Second value to compare.
|
|
85
|
+
* @returns Whether the values are deeply equal.
|
|
86
|
+
*/
|
|
87
|
+
declare const isDeepEqual: (a: unknown, b: unknown) => boolean;
|
|
88
|
+
/**
|
|
89
|
+
* * Converts an array of objects to a string using a specific property (supports nested path to primitive values) and separator.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* const users = [
|
|
93
|
+
* { id: 1, name: { first: 'Alice' }, city: 'Bangu', },
|
|
94
|
+
* { id: 4, name: { first: 'Bob' }, city: 'Banguland', },
|
|
95
|
+
* ];
|
|
96
|
+
* convertArrayToString(users, { target: 'name.first', separator: ' | ' });
|
|
97
|
+
* // "Alice | Bob"
|
|
98
|
+
*
|
|
99
|
+
* @param array Array of objects to convert.
|
|
100
|
+
* @param options Options including the target property and separator.
|
|
101
|
+
* @returns String formed by joining the property values with the given separator.
|
|
102
|
+
*/
|
|
103
|
+
declare function convertArrayToString<T extends GenericObject>(array: Maybe<T[]>, options: ArrayOfObjectsToStringOptions<T>): string;
|
|
104
|
+
/**
|
|
105
|
+
* * Converts an array of primitive values to a string using a custom separator.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* convertArrayToString(['red', 'green', 'blue'], { separator: ' - ' });
|
|
109
|
+
* // "red - green - blue"
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* convertArrayToString([1, 2, 3]);
|
|
113
|
+
* // "1, 2, 3"
|
|
114
|
+
*
|
|
115
|
+
* @param array Array of primitive values to convert.
|
|
116
|
+
* @param options Optional separator configuration.
|
|
117
|
+
* @returns String formed by joining array elements with the given separator.
|
|
118
|
+
*/
|
|
119
|
+
declare function convertArrayToString<T extends Primitive>(array: Maybe<T[]>, options?: ArrayOfPrimitivesToStringOptions): string;
|
|
120
|
+
/**
|
|
121
|
+
* * A generic debounce function that delays the execution of a callback.
|
|
122
|
+
*
|
|
123
|
+
* @param callback - The function to debounce.
|
|
124
|
+
* @param delay - The delay in milliseconds. Default is `300ms`.
|
|
125
|
+
* @returns A debounced version of the callback function.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* const debouncedSearch = debounceAction((query: string) => {
|
|
129
|
+
* console.log(`Searching for: ${query}`);
|
|
130
|
+
* }, 300);
|
|
131
|
+
*
|
|
132
|
+
* debouncedSearch('laptop'); // Executes after 300ms of inactivity.
|
|
133
|
+
*/
|
|
134
|
+
declare function debounceAction<T extends VoidFn>(callback: T, delay?: number): DelayedFn<T>;
|
|
135
|
+
/**
|
|
136
|
+
* * A generic throttle function that ensures a callback is executed at most once per specified interval.
|
|
137
|
+
*
|
|
138
|
+
* @param callback - The function to throttle.
|
|
139
|
+
* @param delay - The delay in milliseconds. Default is `150ms`.
|
|
140
|
+
* @returns A throttled version of the callback function.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* const throttledResize = throttleAction(() => {
|
|
144
|
+
* console.log('Resized');
|
|
145
|
+
* }, 300);
|
|
146
|
+
*
|
|
147
|
+
* window.addEventListener('resize', throttledResize);
|
|
148
|
+
*/
|
|
149
|
+
declare function throttleAction<T extends VoidFn>(callback: T, delay?: number): DelayedFn<T>;
|
|
150
|
+
/**
|
|
151
|
+
* * Retrieves the names of all instance methods defined directly on a class prototype.
|
|
152
|
+
*
|
|
153
|
+
* @param cls - The class constructor (not an instance).
|
|
154
|
+
* @returns A sorted array of instance method names.
|
|
155
|
+
*/
|
|
156
|
+
declare function getInstanceMethodNames(cls: Constructor): string[];
|
|
157
|
+
/**
|
|
158
|
+
* * Retrieves the names of all static methods defined directly on a class constructor.
|
|
159
|
+
*
|
|
160
|
+
* @param cls - The class constructor (not an instance).
|
|
161
|
+
* @returns A sorted array of static method names.
|
|
162
|
+
*/
|
|
163
|
+
declare function getStaticMethodNames(cls: Constructor): string[];
|
|
164
|
+
/**
|
|
165
|
+
* * Counts the number of instance methods defined directly on a class prototype.
|
|
166
|
+
*
|
|
167
|
+
* @param cls - The class constructor (not an instance).
|
|
168
|
+
* @returns The number of instance methods defined on the class prototype.
|
|
169
|
+
*/
|
|
170
|
+
declare function countInstanceMethods(cls: Constructor): number;
|
|
171
|
+
/**
|
|
172
|
+
* * Counts the number of static methods defined directly on a class constructor.
|
|
173
|
+
*
|
|
174
|
+
* @param cls - The class constructor (not an instance).
|
|
175
|
+
* @returns The number of static methods defined on the class constructor.
|
|
176
|
+
*/
|
|
177
|
+
declare function countStaticMethods(cls: Constructor): number;
|
|
178
|
+
/**
|
|
179
|
+
* * Retrieves the names of all instance getters defined directly on a class prototype.
|
|
180
|
+
*
|
|
181
|
+
* @param cls - The class constructor (not an instance).
|
|
182
|
+
* @returns A sorted array of instance getter names.
|
|
183
|
+
*/
|
|
184
|
+
declare function getInstanceGetterNames(cls: Constructor): string[];
|
|
185
|
+
/**
|
|
186
|
+
* * Retrieves the names of all static getters defined directly on a class constructor.
|
|
187
|
+
*
|
|
188
|
+
* @param cls - The class constructor (not an instance).
|
|
189
|
+
* @returns A sorted array of static getter names.
|
|
190
|
+
*/
|
|
191
|
+
declare function getStaticGetterNames(cls: Constructor): string[];
|
|
192
|
+
/**
|
|
193
|
+
* * Gathers detailed information about the instance and static methods of a class.
|
|
194
|
+
*
|
|
195
|
+
* @param cls - The class constructor (not an instance).
|
|
196
|
+
* @returns An object containing names and counts of instance and static methods.
|
|
197
|
+
*/
|
|
198
|
+
declare function getClassDetails(cls: Constructor): ClassDetails;
|
|
199
|
+
/**
|
|
200
|
+
* * Create a deterministic JSON string representation of any value.
|
|
201
|
+
* - The output format matches standard JSON but with guaranteed sorted keys.
|
|
202
|
+
*
|
|
203
|
+
* @remarks
|
|
204
|
+
* - This function guarantees **stable, repeatable output** by:
|
|
205
|
+
* - Sorting all object keys alphabetically.
|
|
206
|
+
* - Recursively stabilizing nested objects and arrays.
|
|
207
|
+
* - Converting all `undefined` values into `null` so the output remains valid JSON.
|
|
208
|
+
* - Converting date-like objects (`Date`, `Chronos`, `Moment.js`, `Day.js`, `Luxon`, `JS-Joda`, `Temporal`) **in the same way that {@link JSON.stringify} would serialize them**, ensuring predictable and JSON-compliant output.
|
|
209
|
+
* - Falling back to native JSON serialization for primitives.
|
|
210
|
+
*
|
|
211
|
+
* - **Useful for:**
|
|
212
|
+
* - Hash generation (e.g., signatures, cache keys)
|
|
213
|
+
* - Deep equality checks
|
|
214
|
+
* - Producing predictable output across environments
|
|
215
|
+
*
|
|
216
|
+
* @param obj - The value to stringify into a deterministic JSON string.
|
|
217
|
+
* @returns A stable, deterministic string representation of the input.
|
|
218
|
+
*/
|
|
219
|
+
declare function stableStringify(obj: unknown): string;
|
|
220
|
+
/**
|
|
221
|
+
* * Remove trailing or leading garbage characters **after/before JSON object or array**.
|
|
222
|
+
* @param str String to sanitize/strip.
|
|
223
|
+
* @returns Sanitized/stripped JSON string.
|
|
224
|
+
*/
|
|
225
|
+
declare function stripJsonEdgeGarbage(str: string): string;
|
|
226
|
+
/**
|
|
227
|
+
* * Parses any valid JSON string, optionally converting stringified primitives inside (nested) arrays or objects.
|
|
228
|
+
*
|
|
229
|
+
* @typeParam T - Expected return type (default is unknown).
|
|
230
|
+
* @param value - The JSON string to parse.
|
|
231
|
+
* @param parsePrimitives - Whether to convert stringified primitives (default: `true`).
|
|
232
|
+
* @returns The parsed JSON value typed as `T`, or the original parsed value with optional primitive conversion.
|
|
233
|
+
* - Returns `{}` if parsing fails, such as when the input is malformed or invalid JSON or passing single quoted string.
|
|
234
|
+
*
|
|
235
|
+
* - *Unlike {@link https://toolbox-x.nazmul-nhb.dev/docs/utils/object/parse-json-to-object parseJsonToObject}, which ensures the root value is an object,
|
|
236
|
+
* this function returns any valid JSON structure such as arrays, strings, numbers, or objects.*
|
|
237
|
+
*
|
|
238
|
+
* This is useful when you're not sure of the root structure of the JSON, or when you expect something other than an object.
|
|
239
|
+
*
|
|
240
|
+
* @see {@link https://toolbox-x.nazmul-nhb.dev/docs/utils/object/parse-json-to-object parseJsonToObject} for strict object-only parsing.
|
|
241
|
+
*/
|
|
242
|
+
declare const parseJSON: <T = unknown>(value: string, parsePrimitives?: boolean) => T;
|
|
243
|
+
/**
|
|
244
|
+
* * Recursively parses primitive values inside objects and arrays.
|
|
245
|
+
*
|
|
246
|
+
* @typeParam T - Expected return type after parsing (default is unknown).
|
|
247
|
+
* @param input - Any input value to parse recursively.
|
|
248
|
+
* @returns Input with primitives (strings like "true", "123") converted, typed as `T`.
|
|
249
|
+
*/
|
|
250
|
+
declare function deepParsePrimitives<T = unknown>(input: unknown): T;
|
|
251
|
+
/**
|
|
252
|
+
* * Defines a method on any prototype — including built-in prototypes — in a safe, idempotent manner.
|
|
253
|
+
* - The method is non-enumerable by default and will not overwrite an existing method unless explicitly allowed.
|
|
254
|
+
*
|
|
255
|
+
* @param proto The target prototype object (e.g., String.prototype).
|
|
256
|
+
* @param name The method name to define on the prototype.
|
|
257
|
+
* @param impl The function implementation for the method.
|
|
258
|
+
* @param options Optional property-descriptor settings and overwrite rules.
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* // Safely augment prototype methods by extending the global interface:
|
|
262
|
+
* declare global {
|
|
263
|
+
* interface String {
|
|
264
|
+
* toBang(): string;
|
|
265
|
+
* }
|
|
266
|
+
* }
|
|
267
|
+
*
|
|
268
|
+
* // Define a custom method on String.prototype
|
|
269
|
+
* definePrototypeMethod(String.prototype, 'toBang', function (this: String) {
|
|
270
|
+
* return this.toString().concat('!');
|
|
271
|
+
* // or
|
|
272
|
+
* // return this.concat('!');
|
|
273
|
+
* });
|
|
274
|
+
*
|
|
275
|
+
* "Hi".toBang(); // "Hi!"
|
|
276
|
+
*
|
|
277
|
+
* // Attempting to redefine without overwrite option is ignored
|
|
278
|
+
* definePrototypeMethod(String.prototype, 'toBang', () => 'x'); // ignored
|
|
279
|
+
*
|
|
280
|
+
* // Overwrite intentionally using the overwrite option
|
|
281
|
+
* definePrototypeMethod(
|
|
282
|
+
* String.prototype,
|
|
283
|
+
* 'toBang',
|
|
284
|
+
* function (this: String) { return this.concat('!!!'); },
|
|
285
|
+
* { overwrite: true }
|
|
286
|
+
* );
|
|
287
|
+
*
|
|
288
|
+
* "Hi".toBang(); // "Hi!!!"
|
|
289
|
+
*/
|
|
290
|
+
declare function definePrototypeMethod<Proto extends object, Name extends keyof Proto, Args extends unknown[], Return>(proto: Proto, name: Name, impl: (...args: Args) => Return, options?: ProtoMethodOptions): void;
|
|
291
|
+
//#endregion
|
|
292
|
+
export { shuffleArray as C, isInvalidOrEmptyArray as S, findPrimeNumbers as _, deepParsePrimitives as a, flattenArray as b, getInstanceGetterNames as c, getStaticMethodNames as d, isDeepEqual as f, throttleAction as g, stripJsonEdgeGarbage as h, debounceAction as i, getInstanceMethodNames as l, stableStringify as m, countInstanceMethods as n, definePrototypeMethod as o, parseJSON as p, countStaticMethods as r, getClassDetails as s, convertArrayToString as t, getStaticGetterNames as u, isPrime as v, getLastArrayElement as x, filterArrayOfObjects as y };
|