@turndown/library 0.1.64 → 0.1.66
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/README.md +41 -1
- package/dist/{index.cjs → helpers/index.cjs} +30 -1116
- package/dist/helpers/index.cjs.map +1 -0
- package/dist/helpers/index.d.cts +675 -0
- package/dist/helpers/index.d.ts +675 -0
- package/dist/{index.mjs → helpers/index.mjs} +17 -926
- package/dist/helpers/index.mjs.map +1 -0
- package/dist/index-CzB45yLv.d.cts +334 -0
- package/dist/index-CzB45yLv.d.ts +334 -0
- package/dist/types/index.cjs +947 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/{index.d.cts → types/index.d.cts} +19 -1141
- package/dist/{index.d.ts → types/index.d.ts} +19 -1141
- package/dist/types/index.mjs +924 -0
- package/dist/types/index.mjs.map +1 -0
- package/dist/types/validation/index.cjs +195 -0
- package/dist/types/validation/index.cjs.map +1 -0
- package/dist/types/validation/index.d.cts +51 -0
- package/dist/types/validation/index.d.ts +51 -0
- package/dist/types/validation/index.mjs +174 -0
- package/dist/types/validation/index.mjs.map +1 -0
- package/package.json +30 -10
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1,675 @@
|
|
|
1
|
+
import { o as ISortCondition, e as IFilterCondition, D as TFilterConditionValue, X as TUSStateCode } from '../index-CzB45yLv.js';
|
|
2
|
+
|
|
3
|
+
type TDateInput = Date | string | number | null | undefined;
|
|
4
|
+
type TDateFormat = "MM/DD/YYYY" | "MM/DD/YY HH:mm A" | string;
|
|
5
|
+
/**
|
|
6
|
+
* Format a date using a dayjs format string.
|
|
7
|
+
*
|
|
8
|
+
* @param {TDateInput} date - Date-like value to format.
|
|
9
|
+
* @param {TDateFormat} format - dayjs format string.
|
|
10
|
+
* @returns {string} Formatted date or `--` for missing/invalid input.
|
|
11
|
+
*/
|
|
12
|
+
declare const formatDate: (date?: TDateInput, format?: TDateFormat) => string;
|
|
13
|
+
/**
|
|
14
|
+
* Return a human-readable relative time string.
|
|
15
|
+
*
|
|
16
|
+
* @param {TDateInput} date - Date-like value to compare against now.
|
|
17
|
+
* @returns {string} Relative time or `--` for missing/invalid input.
|
|
18
|
+
*/
|
|
19
|
+
declare const timeAgo: (date: TDateInput) => string;
|
|
20
|
+
/**
|
|
21
|
+
* Add days to a date.
|
|
22
|
+
*
|
|
23
|
+
* @param {TDateInput} date - Source date.
|
|
24
|
+
* @param {number} days - Number of days to add.
|
|
25
|
+
* @returns {Date} Updated date.
|
|
26
|
+
*/
|
|
27
|
+
declare const addDays: (date: TDateInput, days: number) => Date;
|
|
28
|
+
/**
|
|
29
|
+
* Subtract days from a date.
|
|
30
|
+
*
|
|
31
|
+
* @param {TDateInput} date - Source date.
|
|
32
|
+
* @param {number} days - Number of days to subtract.
|
|
33
|
+
* @returns {Date} Updated date.
|
|
34
|
+
*/
|
|
35
|
+
declare const subtractDays: (date: TDateInput, days: number) => Date;
|
|
36
|
+
/**
|
|
37
|
+
* Return the absolute number of whole day boundaries between two dates.
|
|
38
|
+
*
|
|
39
|
+
* @param {TDateInput} dateA - First date.
|
|
40
|
+
* @param {TDateInput} dateB - Second date.
|
|
41
|
+
* @returns {number} Absolute difference in days, or 0 for invalid input.
|
|
42
|
+
*/
|
|
43
|
+
declare const daysBetween: (dateA: TDateInput, dateB: TDateInput) => number;
|
|
44
|
+
/**
|
|
45
|
+
* Check whether a date is today.
|
|
46
|
+
*
|
|
47
|
+
* @param {TDateInput} date - Date-like value.
|
|
48
|
+
* @returns {boolean} True when the date is today.
|
|
49
|
+
*/
|
|
50
|
+
declare const isToday: (date: TDateInput) => boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Check whether a date is in the past.
|
|
53
|
+
*
|
|
54
|
+
* @param {TDateInput} date - Date-like value.
|
|
55
|
+
* @returns {boolean} True when the date is before now.
|
|
56
|
+
*/
|
|
57
|
+
declare const isPast: (date: TDateInput) => boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Check whether a date is in the future.
|
|
60
|
+
*
|
|
61
|
+
* @param {TDateInput} date - Date-like value.
|
|
62
|
+
* @returns {boolean} True when the date is after now.
|
|
63
|
+
*/
|
|
64
|
+
declare const isFuture: (date: TDateInput) => boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Return the start of the day for a date.
|
|
67
|
+
*
|
|
68
|
+
* @param {TDateInput} date - Source date.
|
|
69
|
+
* @returns {Date} Date set to 00:00:00.000.
|
|
70
|
+
*/
|
|
71
|
+
declare const startOfDay: (date: TDateInput) => Date;
|
|
72
|
+
/**
|
|
73
|
+
* Return the end of the day for a date.
|
|
74
|
+
*
|
|
75
|
+
* @param {TDateInput} date - Source date.
|
|
76
|
+
* @returns {Date} Date set to 23:59:59.999.
|
|
77
|
+
*/
|
|
78
|
+
declare const endOfDay: (date: TDateInput) => Date;
|
|
79
|
+
/**
|
|
80
|
+
* Return the ISO week start date, Monday at 00:00:00.000.
|
|
81
|
+
*
|
|
82
|
+
* @param {TDateInput} date - Source date.
|
|
83
|
+
* @returns {Date} Start of ISO week.
|
|
84
|
+
*/
|
|
85
|
+
declare const startOfWeek: (date: TDateInput) => Date;
|
|
86
|
+
/**
|
|
87
|
+
* Return the ISO week end date, Sunday at 23:59:59.999.
|
|
88
|
+
*
|
|
89
|
+
* @param {TDateInput} date - Source date.
|
|
90
|
+
* @returns {Date} End of ISO week.
|
|
91
|
+
*/
|
|
92
|
+
declare const endOfWeek: (date: TDateInput) => Date;
|
|
93
|
+
/**
|
|
94
|
+
* Return all seven dates in the ISO week containing the provided date.
|
|
95
|
+
*
|
|
96
|
+
* @param {TDateInput} date - Source date.
|
|
97
|
+
* @returns {Date[]} Monday-through-Sunday dates at the start of each day.
|
|
98
|
+
*/
|
|
99
|
+
declare const getWeekDays: (date: TDateInput) => Date[];
|
|
100
|
+
/**
|
|
101
|
+
* Add weeks to a date.
|
|
102
|
+
*
|
|
103
|
+
* @param {TDateInput} date - Source date.
|
|
104
|
+
* @param {number} weeks - Number of weeks to add.
|
|
105
|
+
* @returns {Date} Updated date.
|
|
106
|
+
*/
|
|
107
|
+
declare const addWeeks: (date: TDateInput, weeks: number) => Date;
|
|
108
|
+
/**
|
|
109
|
+
* Subtract weeks from a date.
|
|
110
|
+
*
|
|
111
|
+
* @param {TDateInput} date - Source date.
|
|
112
|
+
* @param {number} weeks - Number of weeks to subtract.
|
|
113
|
+
* @returns {Date} Updated date.
|
|
114
|
+
*/
|
|
115
|
+
declare const subtractWeeks: (date: TDateInput, weeks: number) => Date;
|
|
116
|
+
|
|
117
|
+
type TRecord = Record<string, unknown>;
|
|
118
|
+
type TSortableValue = string | number | bigint | boolean | Date | null | undefined;
|
|
119
|
+
type TReplaceNulls<TValue> = TValue extends null ? "" : TValue extends (infer TItem)[] ? TReplaceNulls<TItem>[] : TValue extends Date ? TValue : TValue extends object ? {
|
|
120
|
+
[TKey in keyof TValue]: TReplaceNulls<TValue[TKey]>;
|
|
121
|
+
} : TValue;
|
|
122
|
+
/**
|
|
123
|
+
* Safely parse a JSON string into a typed value.
|
|
124
|
+
*
|
|
125
|
+
* When a fallback value is provided, the function always returns that generic
|
|
126
|
+
* type. Without a fallback value, parse failures return an empty object.
|
|
127
|
+
*
|
|
128
|
+
* @typeParam TParsed - Expected parsed value type.
|
|
129
|
+
* @param {string | null | undefined} jsonString - JSON string to parse.
|
|
130
|
+
* @param {TParsed} [fallbackValue] - Value returned when parsing fails.
|
|
131
|
+
* @returns {TParsed | Record<string, unknown>} Parsed value or fallback.
|
|
132
|
+
* @example
|
|
133
|
+
* parseJSON<{ a: number }>('{"a":1}', { a: 0 }) // => { a: 1 }
|
|
134
|
+
* parseJSON('not json') // => {}
|
|
135
|
+
*/
|
|
136
|
+
declare function parseJSON<TParsed>(jsonString: string | null | undefined, fallbackValue: TParsed): TParsed;
|
|
137
|
+
declare function parseJSON(jsonString: string | null | undefined): Record<string, unknown>;
|
|
138
|
+
/**
|
|
139
|
+
* Stringify a value to JSON while skipping circular references.
|
|
140
|
+
*
|
|
141
|
+
* Uses an internal cache to omit repeated object references that would
|
|
142
|
+
* normally cause `JSON.stringify` to throw.
|
|
143
|
+
*
|
|
144
|
+
* @param {unknown} value - Value to stringify.
|
|
145
|
+
* @returns {string | undefined} JSON string with circulars omitted.
|
|
146
|
+
* @example
|
|
147
|
+
* const value: Record<string, unknown> = {}; value.self = value;
|
|
148
|
+
* JSONStringify(value) // => "{}"
|
|
149
|
+
*/
|
|
150
|
+
declare const JSONStringify: (value: unknown) => string | undefined;
|
|
151
|
+
/**
|
|
152
|
+
* Deep-remove `undefined` properties while preserving Dates and arrays.
|
|
153
|
+
*
|
|
154
|
+
* Object properties with `undefined` values are removed. Array items are
|
|
155
|
+
* preserved so array indexes do not shift.
|
|
156
|
+
*
|
|
157
|
+
* @typeParam TValue - Input value type.
|
|
158
|
+
* @param {TValue} value - Input value.
|
|
159
|
+
* @returns {TValue} Cleaned clone with `undefined` object properties removed.
|
|
160
|
+
*/
|
|
161
|
+
declare const removeUndefined: <TValue>(value: TValue) => TValue;
|
|
162
|
+
/**
|
|
163
|
+
* Test whether a location object's `pathname` equals a key.
|
|
164
|
+
*
|
|
165
|
+
* @param {{ pathname?: string } | null | undefined} location - Object expected
|
|
166
|
+
* to have a `pathname`.
|
|
167
|
+
* @param {string} key - Path to compare.
|
|
168
|
+
* @returns {boolean}
|
|
169
|
+
* @example
|
|
170
|
+
* validPath({ pathname: "/home" }, "/home") // true
|
|
171
|
+
*/
|
|
172
|
+
declare const validPath: (location: {
|
|
173
|
+
pathname?: string;
|
|
174
|
+
} | null | undefined, key: string) => boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Return the first element if the input is an array; otherwise return the value itself.
|
|
177
|
+
*
|
|
178
|
+
* @typeParam T - Element type.
|
|
179
|
+
* @param {T | T[]} input - A single value or an array.
|
|
180
|
+
* @returns {T} First element or the input value.
|
|
181
|
+
* @example
|
|
182
|
+
* returnObject([1,2,3]) // 1
|
|
183
|
+
* returnObject(5) // 5
|
|
184
|
+
*/
|
|
185
|
+
declare const returnObject: <T>(input: T | T[]) => T;
|
|
186
|
+
/**
|
|
187
|
+
* Filter out items from `array1` whose `id` appears in `array2`.
|
|
188
|
+
*
|
|
189
|
+
* @typeParam T - Object type with an `id` field.
|
|
190
|
+
* @param {T[]} [array1] - Source array.
|
|
191
|
+
* @param {T[]} [array2] - Items whose `id`s should be excluded.
|
|
192
|
+
* @returns {T[]} Filtered array (or `[]` on invalid input).
|
|
193
|
+
*/
|
|
194
|
+
declare const filterArrayById: <T extends {
|
|
195
|
+
id: number | string;
|
|
196
|
+
}>(array1?: T[], array2?: T[]) => T[];
|
|
197
|
+
/**
|
|
198
|
+
* Sort an array of objects by a given property (ascending).
|
|
199
|
+
*
|
|
200
|
+
* Mutates the original array (uses `Array.prototype.sort`).
|
|
201
|
+
*
|
|
202
|
+
* @typeParam T - Object type.
|
|
203
|
+
* @typeParam TKey - Sortable property key.
|
|
204
|
+
* @param {T[]} array - Array to sort.
|
|
205
|
+
* @param {TKey} property - Property name to sort by.
|
|
206
|
+
* @returns {T[]} The same array instance, sorted (or empty array if input invalid).
|
|
207
|
+
*/
|
|
208
|
+
declare const sortArrayByProperty: <TKey extends PropertyKey, T extends Record<TKey, TSortableValue>>(array: T[], property: TKey) => T[];
|
|
209
|
+
/**
|
|
210
|
+
* Recursively replace `null` values with empty strings.
|
|
211
|
+
*
|
|
212
|
+
* Works on primitives, arrays, Dates, and plain objects.
|
|
213
|
+
*
|
|
214
|
+
* @typeParam TValue - Input value type.
|
|
215
|
+
* @param {TValue} value - Input value.
|
|
216
|
+
* @returns {TReplaceNulls<TValue>} Value with all `null` replaced by `""`.
|
|
217
|
+
*/
|
|
218
|
+
declare const replaceNulls: <TValue>(value: TValue) => TReplaceNulls<TValue>;
|
|
219
|
+
/**
|
|
220
|
+
* Recursively remove object keys that contain a dot (`.`).
|
|
221
|
+
*
|
|
222
|
+
* @typeParam TValue - Input value type.
|
|
223
|
+
* @param {TValue} value - Input object or array.
|
|
224
|
+
* @returns {TValue} New value with dotted keys removed at all levels.
|
|
225
|
+
*/
|
|
226
|
+
declare const removeFormProperties: <TValue>(value: TValue) => TValue;
|
|
227
|
+
/**
|
|
228
|
+
* Recursively convert string booleans `"true"`/`"false"` to actual booleans.
|
|
229
|
+
*
|
|
230
|
+
* Leaves all other values unchanged.
|
|
231
|
+
*
|
|
232
|
+
* @typeParam TValue - Input value type.
|
|
233
|
+
* @param {TValue} value - Input object or array.
|
|
234
|
+
* @returns {TValue} New value with boolean-like strings converted.
|
|
235
|
+
*/
|
|
236
|
+
declare const convertStringBooleans: <TValue>(value: TValue) => TValue;
|
|
237
|
+
/**
|
|
238
|
+
* Convenience helper to clean form-like data:
|
|
239
|
+
* - Removes `undefined` properties
|
|
240
|
+
* - Converts string booleans to booleans
|
|
241
|
+
* - Removes keys containing a dot (`.`)
|
|
242
|
+
*
|
|
243
|
+
* @typeParam TObject - Form data object type.
|
|
244
|
+
* @param {TObject} objectToClean - Input data.
|
|
245
|
+
* @returns {Partial<TObject>} Cleaned clone.
|
|
246
|
+
*/
|
|
247
|
+
declare const cleanFormData: <TObject extends TRecord>(objectToClean: TObject) => Partial<TObject>;
|
|
248
|
+
/**
|
|
249
|
+
* Return a default pagination object, allowing optional sort and filters.
|
|
250
|
+
*
|
|
251
|
+
* @param {ISortCondition[]} [sort] - Optional sort conditions.
|
|
252
|
+
* @param {IFilterCondition[]} [filters] - Optional filter conditions.
|
|
253
|
+
* @returns {{ page: number; size: number; sort: ISortCondition[]; filters: IFilterCondition[] }}
|
|
254
|
+
* @example
|
|
255
|
+
* resetPagination() // => { page:1, size:25, sort:[], filters:[] }
|
|
256
|
+
*/
|
|
257
|
+
declare const resetPagination: (sort?: ISortCondition[], filters?: IFilterCondition[]) => {
|
|
258
|
+
page: number;
|
|
259
|
+
size: number;
|
|
260
|
+
sort: ISortCondition[];
|
|
261
|
+
filters: TFilterConditionValue[];
|
|
262
|
+
};
|
|
263
|
+
/**
|
|
264
|
+
* Format a string of digits into a U.S. phone number.
|
|
265
|
+
*
|
|
266
|
+
* Strips non-numeric characters and formats 10 digits as `(XXX) XXX-XXXX`.
|
|
267
|
+
* Strips a leading US country code when 11 digits are provided.
|
|
268
|
+
* If a value cannot be formatted, returns the original value as a string.
|
|
269
|
+
*
|
|
270
|
+
* @param {string | number} value - Phone number digits (string or number).
|
|
271
|
+
* @returns {string} Formatted phone number, or original input if invalid length.
|
|
272
|
+
* @example
|
|
273
|
+
* formatPhoneNumber("1234567890") // "(123) 456-7890"
|
|
274
|
+
* formatPhoneNumber(9876543210) // "(987) 654-3210"
|
|
275
|
+
* formatPhoneNumber("555") // "555"
|
|
276
|
+
*/
|
|
277
|
+
declare const formatPhoneNumber: (value: string | number) => string;
|
|
278
|
+
/**
|
|
279
|
+
* Remove comma separators from a number-like value.
|
|
280
|
+
*
|
|
281
|
+
* @param {number | string} value - Number-like value.
|
|
282
|
+
* @returns {string} Value without comma separators.
|
|
283
|
+
*/
|
|
284
|
+
declare const parseNumber: (value: number | string) => string;
|
|
285
|
+
/**
|
|
286
|
+
* Delete a property from an object if it exists (no-op if it doesn't).
|
|
287
|
+
*
|
|
288
|
+
* @typeParam TObject - Object type.
|
|
289
|
+
* @param {TObject} objectToUpdate - Target object (mutated).
|
|
290
|
+
* @param {keyof TObject | string} propertyName - Property to delete.
|
|
291
|
+
* @returns {void}
|
|
292
|
+
*/
|
|
293
|
+
declare const deletePropertyIfExists: <TObject extends TRecord>(objectToUpdate: TObject, propertyName: keyof TObject | string) => void;
|
|
294
|
+
/**
|
|
295
|
+
* Split an array into chunks of a given size.
|
|
296
|
+
*
|
|
297
|
+
* @typeParam T - Element type.
|
|
298
|
+
* @param {T[]} array - Source array.
|
|
299
|
+
* @param {number} chunkSize - Size of each chunk.
|
|
300
|
+
* @returns {T[][]} Array of chunks (last one may be smaller).
|
|
301
|
+
* @example
|
|
302
|
+
* chunkArray([1,2,3,4,5], 2) // [[1,2],[3,4],[5]]
|
|
303
|
+
*/
|
|
304
|
+
declare const chunkArray: <T>(array: T[], chunkSize: number) => T[][];
|
|
305
|
+
/**
|
|
306
|
+
* Return a shallow clone of `objectToOmitFrom` without the listed properties.
|
|
307
|
+
*
|
|
308
|
+
* @typeParam TObject - Source object type.
|
|
309
|
+
* @typeParam TKey - Keys to omit.
|
|
310
|
+
* @param {TObject} objectToOmitFrom - Source object.
|
|
311
|
+
* @param {readonly TKey[]} propsToOmit - Property names to omit.
|
|
312
|
+
* @returns {Omit<TObject, TKey>} New object without omitted props.
|
|
313
|
+
* @example
|
|
314
|
+
* omitProperties({a:1,b:2}, ["b"]) // { a:1 }
|
|
315
|
+
*/
|
|
316
|
+
declare const omitProperties: <TObject extends TRecord, TKey extends keyof TObject>(objectToOmitFrom: TObject, propsToOmit: readonly TKey[]) => Omit<TObject, TKey>;
|
|
317
|
+
/**
|
|
318
|
+
* Safe `hasOwnProperty` check.
|
|
319
|
+
*
|
|
320
|
+
* @param {unknown} value - Value to test.
|
|
321
|
+
* @param {PropertyKey} key - Property name.
|
|
322
|
+
* @returns {boolean}
|
|
323
|
+
*/
|
|
324
|
+
declare const hasProperty: <TKey extends PropertyKey>(value: unknown, key: TKey) => value is Record<TKey, unknown>;
|
|
325
|
+
/**
|
|
326
|
+
* Safe `hasOwnProperty` alias from the reference utilities.
|
|
327
|
+
*
|
|
328
|
+
* @param {unknown} value - Value to test.
|
|
329
|
+
* @param {PropertyKey} key - Property name.
|
|
330
|
+
* @returns {boolean}
|
|
331
|
+
*/
|
|
332
|
+
declare const hasOwnProp: <TKey extends PropertyKey>(value: unknown, key: TKey) => value is Record<TKey, unknown>;
|
|
333
|
+
/**
|
|
334
|
+
* Determine if an object has at least one own enumerable property.
|
|
335
|
+
*
|
|
336
|
+
* @param {unknown} value - Object to test.
|
|
337
|
+
* @returns {boolean} `true` if there is at least one key.
|
|
338
|
+
*/
|
|
339
|
+
declare const hasProperties: (value: unknown) => boolean;
|
|
340
|
+
/**
|
|
341
|
+
* Get the first own enumerable property value from an object.
|
|
342
|
+
*
|
|
343
|
+
* @typeParam TObject - Source object type.
|
|
344
|
+
* @param {TObject | null | undefined} value - Source object.
|
|
345
|
+
* @returns {TObject[keyof TObject] | null} First value, or null for empty/non-object input.
|
|
346
|
+
*/
|
|
347
|
+
declare const getFirstPropertyValue: <TObject extends TRecord>(value: TObject | null | undefined) => TObject[keyof TObject] | null;
|
|
348
|
+
/**
|
|
349
|
+
* Get a nested value from an object using dot notation.
|
|
350
|
+
*
|
|
351
|
+
* @param {unknown} value - Source object.
|
|
352
|
+
* @param {string} path - Dot-delimited path.
|
|
353
|
+
* @returns {unknown} Nested value, or undefined when the path cannot be resolved.
|
|
354
|
+
* @example
|
|
355
|
+
* getNestedValue({ user: { name: "John" } }, "user.name") // "John"
|
|
356
|
+
*/
|
|
357
|
+
declare const getNestedValue: (value: unknown, path: string) => unknown;
|
|
358
|
+
/**
|
|
359
|
+
* Set a nested value on an object using dot notation.
|
|
360
|
+
*
|
|
361
|
+
* Mutates and returns the provided object. Unsafe path segments are ignored to
|
|
362
|
+
* prevent prototype pollution.
|
|
363
|
+
*
|
|
364
|
+
* @typeParam TObject - Target object type.
|
|
365
|
+
* @param {TObject} objectToUpdate - Target object.
|
|
366
|
+
* @param {string} path - Dot-delimited path.
|
|
367
|
+
* @param {unknown} value - Value to set.
|
|
368
|
+
* @returns {TObject} The mutated target object.
|
|
369
|
+
* @example
|
|
370
|
+
* setNestedValue({}, "user.name", "John") // { user: { name: "John" } }
|
|
371
|
+
*/
|
|
372
|
+
declare const setNestedValue: <TObject extends TRecord>(objectToUpdate: TObject, path: string, value: unknown) => TObject;
|
|
373
|
+
/**
|
|
374
|
+
* Deep clone a value while preserving Dates and circular references.
|
|
375
|
+
*
|
|
376
|
+
* @typeParam TValue - Input value type.
|
|
377
|
+
* @param {TValue} value - Value to clone.
|
|
378
|
+
* @returns {TValue} Deep clone of the input.
|
|
379
|
+
*/
|
|
380
|
+
declare const deepClone: <TValue>(value: TValue) => TValue;
|
|
381
|
+
/**
|
|
382
|
+
* Flatten a nested object into dot notation.
|
|
383
|
+
*
|
|
384
|
+
* Arrays and Dates are treated as leaf values.
|
|
385
|
+
*
|
|
386
|
+
* @param {TRecord} value - Source object.
|
|
387
|
+
* @param {string} [prefix] - Internal prefix for recursion.
|
|
388
|
+
* @returns {TRecord} Flattened object.
|
|
389
|
+
* @example
|
|
390
|
+
* flatten({ user: { name: "John" } }) // { "user.name": "John" }
|
|
391
|
+
*/
|
|
392
|
+
declare const flatten: (value: TRecord, prefix?: string) => TRecord;
|
|
393
|
+
/**
|
|
394
|
+
* Convert a dot-notation object into a nested object.
|
|
395
|
+
*
|
|
396
|
+
* Unsafe path segments are ignored to prevent prototype pollution.
|
|
397
|
+
*
|
|
398
|
+
* @param {TRecord} value - Dot-notation source object.
|
|
399
|
+
* @returns {TRecord} Nested object.
|
|
400
|
+
* @example
|
|
401
|
+
* unflatten({ "user.name": "John" }) // { user: { name: "John" } }
|
|
402
|
+
*/
|
|
403
|
+
declare const unflatten: (value: TRecord) => TRecord;
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* String utilities for common text manipulation tasks.
|
|
407
|
+
*/
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Adds commas to a number for thousands separators.
|
|
411
|
+
*
|
|
412
|
+
* @example formatNumber(1000) => '1,000'
|
|
413
|
+
* @example formatNumber('1234567') => '1,234,567'
|
|
414
|
+
* @example formatNumber(1234567.89) => '1,234,567.89'
|
|
415
|
+
*/
|
|
416
|
+
declare const formatNumber: (value: string | number) => string;
|
|
417
|
+
declare const normalCase: (str?: string) => string;
|
|
418
|
+
declare const sentenceCase: (str?: string) => string;
|
|
419
|
+
declare const upperCase: (str?: string) => string;
|
|
420
|
+
declare const lowerCase: (str?: string) => string;
|
|
421
|
+
/**
|
|
422
|
+
* Converts a string to camelCase.
|
|
423
|
+
*
|
|
424
|
+
* @example toCamelCase('hello-world') => 'helloWorld'
|
|
425
|
+
* @example toCamelCase('hello_world') => 'helloWorld'
|
|
426
|
+
*/
|
|
427
|
+
declare const toCamelCase: (str: string) => string;
|
|
428
|
+
declare const camelCase: (str: string) => string;
|
|
429
|
+
/**
|
|
430
|
+
* Converts a string to kebab-case.
|
|
431
|
+
*
|
|
432
|
+
* @example toKebabCase('helloWorld') => 'hello-world'
|
|
433
|
+
* @example toKebabCase('Hello_World') => 'hello-world'
|
|
434
|
+
*/
|
|
435
|
+
declare const toKebabCase: (str: string) => string;
|
|
436
|
+
declare const kebabCase: (str: string) => string;
|
|
437
|
+
/**
|
|
438
|
+
* Converts a string to snake_case.
|
|
439
|
+
*
|
|
440
|
+
* @example toSnakeCase('helloWorld') => 'hello_world'
|
|
441
|
+
* @example toSnakeCase('hello-world') => 'hello_world'
|
|
442
|
+
*/
|
|
443
|
+
declare const toSnakeCase: (str: string) => string;
|
|
444
|
+
declare const snakeCase: (str: string) => string;
|
|
445
|
+
/**
|
|
446
|
+
* Converts a string to PascalCase.
|
|
447
|
+
*
|
|
448
|
+
* @example toPascalCase('hello-world') => 'HelloWorld'
|
|
449
|
+
* @example toPascalCase('hello_world') => 'HelloWorld'
|
|
450
|
+
*/
|
|
451
|
+
declare const toPascalCase: (str: string) => string;
|
|
452
|
+
declare const pascalCase: (str: string) => string;
|
|
453
|
+
declare const snakeCaseToSpaces: (str: string) => string;
|
|
454
|
+
declare const kebabToSpaces: (str: string) => string;
|
|
455
|
+
/**
|
|
456
|
+
* Capitalizes the first character of a string.
|
|
457
|
+
*
|
|
458
|
+
* @example capitalize('hello world') => 'Hello world'
|
|
459
|
+
*/
|
|
460
|
+
declare const capitalize: (str: string) => string;
|
|
461
|
+
/**
|
|
462
|
+
* Capitalizes the first letter of each word.
|
|
463
|
+
*
|
|
464
|
+
* @example titleCase('hello world') => 'Hello World'
|
|
465
|
+
*/
|
|
466
|
+
declare const titleCase: (str: string) => string;
|
|
467
|
+
/**
|
|
468
|
+
* Truncates a string to a specified length and adds ellipsis.
|
|
469
|
+
*
|
|
470
|
+
* @example truncate('hello world', 5) => 'he...'
|
|
471
|
+
*/
|
|
472
|
+
declare const truncate: (str: string, length: number, suffix?: string) => string;
|
|
473
|
+
/**
|
|
474
|
+
* Removes all whitespace from a string.
|
|
475
|
+
*
|
|
476
|
+
* @example removeWhitespace('hello world') => 'helloworld'
|
|
477
|
+
*/
|
|
478
|
+
declare const removeWhitespace: (str: string) => string;
|
|
479
|
+
/**
|
|
480
|
+
* Removes all non-alphanumeric characters.
|
|
481
|
+
*
|
|
482
|
+
* @example removeSpecialChars('hello@world#123') => 'helloworld123'
|
|
483
|
+
*/
|
|
484
|
+
declare const removeSpecialChars: (str: string) => string;
|
|
485
|
+
/**
|
|
486
|
+
* Generates a URL-friendly slug from a string.
|
|
487
|
+
*
|
|
488
|
+
* @example slug('Hello World 2024!') => 'hello-world-2024'
|
|
489
|
+
*/
|
|
490
|
+
declare const slug: (str: string) => string;
|
|
491
|
+
/**
|
|
492
|
+
* Validates if a string is a valid email.
|
|
493
|
+
*
|
|
494
|
+
* @example isEmail('user@example.com') => true
|
|
495
|
+
*/
|
|
496
|
+
declare const isEmail: (str: string) => boolean;
|
|
497
|
+
/**
|
|
498
|
+
* Validates if a string is a valid URL.
|
|
499
|
+
*
|
|
500
|
+
* @example isUrl('https://example.com') => true
|
|
501
|
+
*/
|
|
502
|
+
declare const isUrl: (str: string) => boolean;
|
|
503
|
+
/**
|
|
504
|
+
* Validates if a string contains only numbers.
|
|
505
|
+
*
|
|
506
|
+
* @example isNumeric('12345') => true
|
|
507
|
+
* @example isNumeric('123abc') => false
|
|
508
|
+
*/
|
|
509
|
+
declare const isNumeric: (str: string) => boolean;
|
|
510
|
+
/**
|
|
511
|
+
* Checks if a string is empty or contains only whitespace.
|
|
512
|
+
*
|
|
513
|
+
* @example isEmpty(' ') => true
|
|
514
|
+
* @example isEmpty('hello') => false
|
|
515
|
+
*/
|
|
516
|
+
declare const isEmpty: (str: string) => boolean;
|
|
517
|
+
/**
|
|
518
|
+
* Reverses a string.
|
|
519
|
+
*
|
|
520
|
+
* @example reverse('hello') => 'olleh'
|
|
521
|
+
*/
|
|
522
|
+
declare const reverse: (str: string) => string;
|
|
523
|
+
/**
|
|
524
|
+
* Repeats a string a specified number of times.
|
|
525
|
+
*
|
|
526
|
+
* @example repeat('ab', 3) => 'ababab'
|
|
527
|
+
*/
|
|
528
|
+
declare const repeat: (str: string, times: number) => string;
|
|
529
|
+
/**
|
|
530
|
+
* Pads a string to a specified length.
|
|
531
|
+
*
|
|
532
|
+
* @example padStart('5', 3, '0') => '005'
|
|
533
|
+
* @example padEnd('5', 3, '0') => '500'
|
|
534
|
+
*/
|
|
535
|
+
declare const padStart: (str: string, length: number, padChar?: string) => string;
|
|
536
|
+
declare const padEnd: (str: string, length: number, padChar?: string) => string;
|
|
537
|
+
/**
|
|
538
|
+
* Encodes a string to Base64.
|
|
539
|
+
*
|
|
540
|
+
* @example toBase64('hello') => 'aGVsbG8='
|
|
541
|
+
*/
|
|
542
|
+
declare const toBase64: (str: string) => string;
|
|
543
|
+
/**
|
|
544
|
+
* Decodes a Base64 string.
|
|
545
|
+
*
|
|
546
|
+
* @example fromBase64('aGVsbG8=') => 'hello'
|
|
547
|
+
*/
|
|
548
|
+
declare const fromBase64: (str: string) => string;
|
|
549
|
+
/**
|
|
550
|
+
* Counts the number of words in a string.
|
|
551
|
+
*
|
|
552
|
+
* @example wordCount('hello world test') => 3
|
|
553
|
+
*/
|
|
554
|
+
declare const wordCount: (str: string) => number;
|
|
555
|
+
/**
|
|
556
|
+
* Counts the number of characters, excluding whitespace.
|
|
557
|
+
*
|
|
558
|
+
* @example charCount('hello world') => 10
|
|
559
|
+
*/
|
|
560
|
+
declare const charCount: (str: string) => number;
|
|
561
|
+
/**
|
|
562
|
+
* Repeats a character a specified number of times.
|
|
563
|
+
*
|
|
564
|
+
* @example repeatChar('*', 5) => '*****'
|
|
565
|
+
*/
|
|
566
|
+
declare const repeatChar: (char: string, times: number) => string;
|
|
567
|
+
/**
|
|
568
|
+
* Extracts numbers from a string.
|
|
569
|
+
*
|
|
570
|
+
* @example extractNumbers('abc123def456') => '123456'
|
|
571
|
+
*/
|
|
572
|
+
declare const extractNumbers: (str: string) => string;
|
|
573
|
+
/**
|
|
574
|
+
* Removes duplicate consecutive characters.
|
|
575
|
+
*
|
|
576
|
+
* @example removeDuplicates('aabbccdd') => 'abcd'
|
|
577
|
+
*/
|
|
578
|
+
declare const removeDuplicates: (str: string) => string;
|
|
579
|
+
/**
|
|
580
|
+
* Checks if a string is a palindrome.
|
|
581
|
+
*
|
|
582
|
+
* @example isPalindrome('racecar') => true
|
|
583
|
+
* @example isPalindrome('hello') => false
|
|
584
|
+
*/
|
|
585
|
+
declare const isPalindrome: (str: string) => boolean;
|
|
586
|
+
/**
|
|
587
|
+
* Finds the longest word in a string.
|
|
588
|
+
*
|
|
589
|
+
* @example longestWord('the quick brown fox') => 'quick'
|
|
590
|
+
*/
|
|
591
|
+
declare const longestWord: (str: string) => string;
|
|
592
|
+
/**
|
|
593
|
+
* Pluralizes common English words using a simple ruleset.
|
|
594
|
+
*
|
|
595
|
+
* @example pluralize('cat') => 'cats'
|
|
596
|
+
* @example pluralize('box') => 'boxes'
|
|
597
|
+
*/
|
|
598
|
+
declare const pluralize: (word: string) => string;
|
|
599
|
+
/**
|
|
600
|
+
* Highlights a substring within a string by wrapping it with markers.
|
|
601
|
+
*
|
|
602
|
+
* @example highlight('hello world', 'world', '**') => 'hello **world**'
|
|
603
|
+
*/
|
|
604
|
+
declare const highlight: (str: string, substring: string, marker?: string) => string;
|
|
605
|
+
/**
|
|
606
|
+
* Converts a string to a regex-safe string.
|
|
607
|
+
*
|
|
608
|
+
* @example escapeRegex('a.b*c') => 'a\\.b\\*c'
|
|
609
|
+
*/
|
|
610
|
+
declare const escapeRegex: (str: string) => string;
|
|
611
|
+
/**
|
|
612
|
+
* Finds similarity between two strings using Levenshtein distance.
|
|
613
|
+
* Returns a value between 0 and 1, where 1 means identical.
|
|
614
|
+
*
|
|
615
|
+
* @example stringSimilarity('hello', 'hallo') => 0.8
|
|
616
|
+
*/
|
|
617
|
+
declare const stringSimilarity: (str1: string, str2: string) => number;
|
|
618
|
+
/**
|
|
619
|
+
* Strips HTML tags from a string.
|
|
620
|
+
*
|
|
621
|
+
* @example stripHtml('<p>Hello <b>world</b></p>') => 'Hello world'
|
|
622
|
+
*/
|
|
623
|
+
declare const stripHtml: (str: string) => string;
|
|
624
|
+
/**
|
|
625
|
+
* Replaces multiple spaces with a single space.
|
|
626
|
+
*
|
|
627
|
+
* @example normalizeSpaces('hello world') => 'hello world'
|
|
628
|
+
*/
|
|
629
|
+
declare const normalizeSpaces: (str: string) => string;
|
|
630
|
+
/**
|
|
631
|
+
* Converts a string to a number, returning null if not valid.
|
|
632
|
+
*
|
|
633
|
+
* @example toNumber('123') => 123
|
|
634
|
+
* @example toNumber('abc') => null
|
|
635
|
+
*/
|
|
636
|
+
declare const toNumber: (str: string) => number | null;
|
|
637
|
+
/**
|
|
638
|
+
* Splits a string by multiple delimiters.
|
|
639
|
+
*
|
|
640
|
+
* @example splitMultiple('a,b;c:d', ',', ';', ':') => ['a', 'b', 'c', 'd']
|
|
641
|
+
*/
|
|
642
|
+
declare const splitMultiple: (str: string, ...delimiters: string[]) => string[];
|
|
643
|
+
/**
|
|
644
|
+
* Checks if a string contains any of the provided substrings.
|
|
645
|
+
*
|
|
646
|
+
* @example containsAny('hello world', 'foo', 'world') => true
|
|
647
|
+
*/
|
|
648
|
+
declare const containsAny: (str: string, ...substrings: string[]) => boolean;
|
|
649
|
+
/**
|
|
650
|
+
* Checks if a string contains all of the provided substrings.
|
|
651
|
+
*
|
|
652
|
+
* @example containsAll('hello world', 'hello', 'world') => true
|
|
653
|
+
*/
|
|
654
|
+
declare const containsAll: (str: string, ...substrings: string[]) => boolean;
|
|
655
|
+
interface IAddress {
|
|
656
|
+
addressLine1: string;
|
|
657
|
+
addressLine2?: string;
|
|
658
|
+
city: string;
|
|
659
|
+
stateCode: TUSStateCode;
|
|
660
|
+
postalCode: string;
|
|
661
|
+
}
|
|
662
|
+
declare const formatAddress: (address: IAddress) => string;
|
|
663
|
+
|
|
664
|
+
type Success<T> = {
|
|
665
|
+
data: T;
|
|
666
|
+
error: null;
|
|
667
|
+
};
|
|
668
|
+
type Failure<E> = {
|
|
669
|
+
data: null;
|
|
670
|
+
error: E;
|
|
671
|
+
};
|
|
672
|
+
type Result<T, E = unknown> = Success<T> | Failure<E>;
|
|
673
|
+
declare const tryCatch: <T, E = unknown>(callback: () => T | Promise<T>) => Promise<Result<T, E>>;
|
|
674
|
+
|
|
675
|
+
export { type IAddress, JSONStringify, type TDateFormat, type TDateInput, addDays, addWeeks, camelCase, capitalize, charCount, chunkArray, cleanFormData, containsAll, containsAny, convertStringBooleans, daysBetween, deepClone, deletePropertyIfExists, endOfDay, endOfWeek, escapeRegex, extractNumbers, filterArrayById, flatten, formatAddress, formatDate, formatNumber, formatPhoneNumber, fromBase64, getFirstPropertyValue, getNestedValue, getWeekDays, hasOwnProp, hasProperties, hasProperty, highlight, isEmail, isEmpty, isFuture, isNumeric, isPalindrome, isPast, isToday, isUrl, kebabCase, kebabToSpaces, longestWord, lowerCase, normalCase, normalizeSpaces, omitProperties, padEnd, padStart, parseJSON, parseNumber, pascalCase, pluralize, removeDuplicates, removeFormProperties, removeSpecialChars, removeUndefined, removeWhitespace, repeat, repeatChar, replaceNulls, resetPagination, returnObject, reverse, sentenceCase, setNestedValue, slug, snakeCase, snakeCaseToSpaces, sortArrayByProperty, splitMultiple, startOfDay, startOfWeek, stringSimilarity, stripHtml, subtractDays, subtractWeeks, timeAgo, titleCase, toBase64, toCamelCase, toKebabCase, toNumber, toPascalCase, toSnakeCase, truncate, tryCatch, unflatten, upperCase, validPath, wordCount };
|