@turndown/library 0.1.24 → 0.1.28

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 (75) hide show
  1. package/dist/index.cjs +1355 -0
  2. package/dist/index.d.cts +2820 -0
  3. package/dist/index.d.ts +2820 -2
  4. package/dist/index.js +1190 -2
  5. package/package.json +3 -2
  6. package/dist/helpers/date/index.d.ts +0 -113
  7. package/dist/helpers/date/index.js +0 -171
  8. package/dist/helpers/index.d.ts +0 -4
  9. package/dist/helpers/index.js +0 -3
  10. package/dist/helpers/object/index.d.ts +0 -298
  11. package/dist/helpers/object/index.js +0 -540
  12. package/dist/helpers/string/index.d.ts +0 -258
  13. package/dist/helpers/string/index.js +0 -496
  14. package/dist/types/api/index.d.ts +0 -71
  15. package/dist/types/api/index.js +0 -54
  16. package/dist/types/auth/index.d.ts +0 -107
  17. package/dist/types/auth/index.js +0 -8
  18. package/dist/types/auth/routes.d.ts +0 -160
  19. package/dist/types/auth/routes.js +0 -1
  20. package/dist/types/base/index.d.ts +0 -200
  21. package/dist/types/base/index.js +0 -177
  22. package/dist/types/base/paging.types.d.ts +0 -47
  23. package/dist/types/base/paging.types.js +0 -1
  24. package/dist/types/checklist-template/index.d.ts +0 -48
  25. package/dist/types/checklist-template/index.js +0 -1
  26. package/dist/types/checklist-template/routes.d.ts +0 -85
  27. package/dist/types/checklist-template/routes.js +0 -1
  28. package/dist/types/company/index.d.ts +0 -22
  29. package/dist/types/company/index.js +0 -7
  30. package/dist/types/company/routes.d.ts +0 -100
  31. package/dist/types/company/routes.js +0 -1
  32. package/dist/types/damage-report/index.d.ts +0 -148
  33. package/dist/types/damage-report/index.js +0 -29
  34. package/dist/types/damage-report/routes.d.ts +0 -112
  35. package/dist/types/damage-report/routes.js +0 -1
  36. package/dist/types/errors/index.d.ts +0 -66
  37. package/dist/types/errors/index.js +0 -41
  38. package/dist/types/health/index.d.ts +0 -20
  39. package/dist/types/health/index.js +0 -1
  40. package/dist/types/health/routes.d.ts +0 -10
  41. package/dist/types/health/routes.js +0 -1
  42. package/dist/types/image/index.d.ts +0 -35
  43. package/dist/types/image/index.js +0 -12
  44. package/dist/types/image/routes.d.ts +0 -32
  45. package/dist/types/image/routes.js +0 -1
  46. package/dist/types/index.d.ts +0 -22
  47. package/dist/types/index.js +0 -22
  48. package/dist/types/inventory/index.d.ts +0 -124
  49. package/dist/types/inventory/index.js +0 -30
  50. package/dist/types/inventory/routes.d.ts +0 -109
  51. package/dist/types/inventory/routes.js +0 -1
  52. package/dist/types/job/index.d.ts +0 -7
  53. package/dist/types/job/index.js +0 -1
  54. package/dist/types/property/index.d.ts +0 -113
  55. package/dist/types/property/index.js +0 -25
  56. package/dist/types/property/routes.d.ts +0 -54
  57. package/dist/types/property/routes.js +0 -1
  58. package/dist/types/room/index.d.ts +0 -28
  59. package/dist/types/room/index.js +0 -17
  60. package/dist/types/room/routes.d.ts +0 -35
  61. package/dist/types/room/routes.js +0 -1
  62. package/dist/types/room-checklist/index.d.ts +0 -43
  63. package/dist/types/room-checklist/index.js +0 -1
  64. package/dist/types/room-checklist/routes.d.ts +0 -78
  65. package/dist/types/room-checklist/routes.js +0 -1
  66. package/dist/types/subscription/index.d.ts +0 -32
  67. package/dist/types/subscription/index.js +0 -16
  68. package/dist/types/user/index.d.ts +0 -59
  69. package/dist/types/user/index.js +0 -20
  70. package/dist/types/user/routes.d.ts +0 -46
  71. package/dist/types/user/routes.js +0 -1
  72. package/dist/types/work-session/index.d.ts +0 -97
  73. package/dist/types/work-session/index.js +0 -18
  74. package/dist/types/work-session/routes.d.ts +0 -89
  75. package/dist/types/work-session/routes.js +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turndown/library",
3
- "version": "0.1.24",
3
+ "version": "0.1.28",
4
4
  "description": "Shared TypeScript library for the Turndown suite.",
5
5
  "keywords": [
6
6
  "types",
@@ -32,7 +32,7 @@
32
32
  ],
33
33
  "scripts": {
34
34
  "clean": "rimraf dist",
35
- "build": "npm run clean && tsc -p .",
35
+ "build": "tsup src/index.ts --format esm,cjs --dts --clean",
36
36
  "dev": "tsc -w -p .",
37
37
  "format": "prettier --write .",
38
38
  "test": "jest",
@@ -45,6 +45,7 @@
45
45
  "jest": "^30.4.2",
46
46
  "rimraf": "^6.0.1",
47
47
  "ts-jest": "^29.4.9",
48
+ "tsup": "^8.5.1",
48
49
  "typescript": "^5.9.3"
49
50
  },
50
51
  "dependencies": {
@@ -1,113 +0,0 @@
1
- export type TDateInput = Date | string | number | null | undefined;
2
- export type TDateFormat = "MM/DD/YYYY" | "MM/DD/YY HH:mm A" | string;
3
- /**
4
- * Format a date using a dayjs format string.
5
- *
6
- * @param {TDateInput} date - Date-like value to format.
7
- * @param {TDateFormat} format - dayjs format string.
8
- * @returns {string} Formatted date or `--` for missing/invalid input.
9
- */
10
- export declare const formatDate: (date?: TDateInput, format?: TDateFormat) => string;
11
- /**
12
- * Return a human-readable relative time string.
13
- *
14
- * @param {TDateInput} date - Date-like value to compare against now.
15
- * @returns {string} Relative time or `--` for missing/invalid input.
16
- */
17
- export declare const timeAgo: (date: TDateInput) => string;
18
- /**
19
- * Add days to a date.
20
- *
21
- * @param {TDateInput} date - Source date.
22
- * @param {number} days - Number of days to add.
23
- * @returns {Date} Updated date.
24
- */
25
- export declare const addDays: (date: TDateInput, days: number) => Date;
26
- /**
27
- * Subtract days from a date.
28
- *
29
- * @param {TDateInput} date - Source date.
30
- * @param {number} days - Number of days to subtract.
31
- * @returns {Date} Updated date.
32
- */
33
- export declare const subtractDays: (date: TDateInput, days: number) => Date;
34
- /**
35
- * Return the absolute number of whole day boundaries between two dates.
36
- *
37
- * @param {TDateInput} dateA - First date.
38
- * @param {TDateInput} dateB - Second date.
39
- * @returns {number} Absolute difference in days, or 0 for invalid input.
40
- */
41
- export declare const daysBetween: (dateA: TDateInput, dateB: TDateInput) => number;
42
- /**
43
- * Check whether a date is today.
44
- *
45
- * @param {TDateInput} date - Date-like value.
46
- * @returns {boolean} True when the date is today.
47
- */
48
- export declare const isToday: (date: TDateInput) => boolean;
49
- /**
50
- * Check whether a date is in the past.
51
- *
52
- * @param {TDateInput} date - Date-like value.
53
- * @returns {boolean} True when the date is before now.
54
- */
55
- export declare const isPast: (date: TDateInput) => boolean;
56
- /**
57
- * Check whether a date is in the future.
58
- *
59
- * @param {TDateInput} date - Date-like value.
60
- * @returns {boolean} True when the date is after now.
61
- */
62
- export declare const isFuture: (date: TDateInput) => boolean;
63
- /**
64
- * Return the start of the day for a date.
65
- *
66
- * @param {TDateInput} date - Source date.
67
- * @returns {Date} Date set to 00:00:00.000.
68
- */
69
- export declare const startOfDay: (date: TDateInput) => Date;
70
- /**
71
- * Return the end of the day for a date.
72
- *
73
- * @param {TDateInput} date - Source date.
74
- * @returns {Date} Date set to 23:59:59.999.
75
- */
76
- export declare const endOfDay: (date: TDateInput) => Date;
77
- /**
78
- * Return the ISO week start date, Monday at 00:00:00.000.
79
- *
80
- * @param {TDateInput} date - Source date.
81
- * @returns {Date} Start of ISO week.
82
- */
83
- export declare const startOfWeek: (date: TDateInput) => Date;
84
- /**
85
- * Return the ISO week end date, Sunday at 23:59:59.999.
86
- *
87
- * @param {TDateInput} date - Source date.
88
- * @returns {Date} End of ISO week.
89
- */
90
- export declare const endOfWeek: (date: TDateInput) => Date;
91
- /**
92
- * Return all seven dates in the ISO week containing the provided date.
93
- *
94
- * @param {TDateInput} date - Source date.
95
- * @returns {Date[]} Monday-through-Sunday dates at the start of each day.
96
- */
97
- export declare const getWeekDays: (date: TDateInput) => Date[];
98
- /**
99
- * Add weeks to a date.
100
- *
101
- * @param {TDateInput} date - Source date.
102
- * @param {number} weeks - Number of weeks to add.
103
- * @returns {Date} Updated date.
104
- */
105
- export declare const addWeeks: (date: TDateInput, weeks: number) => Date;
106
- /**
107
- * Subtract weeks from a date.
108
- *
109
- * @param {TDateInput} date - Source date.
110
- * @param {number} weeks - Number of weeks to subtract.
111
- * @returns {Date} Updated date.
112
- */
113
- export declare const subtractWeeks: (date: TDateInput, weeks: number) => Date;
@@ -1,171 +0,0 @@
1
- import dayjs from "dayjs";
2
- import isoWeek from "dayjs/plugin/isoWeek";
3
- import relativeTime from "dayjs/plugin/relativeTime";
4
- dayjs.extend(relativeTime);
5
- dayjs.extend(isoWeek);
6
- const defaultDateFallback = "--";
7
- const isValidDateInput = (date) => {
8
- return date !== null && date !== undefined && dayjs(date).isValid();
9
- };
10
- /**
11
- * Format a date using a dayjs format string.
12
- *
13
- * @param {TDateInput} date - Date-like value to format.
14
- * @param {TDateFormat} format - dayjs format string.
15
- * @returns {string} Formatted date or `--` for missing/invalid input.
16
- */
17
- export const formatDate = (date, format = "MM/DD/YYYY") => {
18
- if (!isValidDateInput(date)) {
19
- return defaultDateFallback;
20
- }
21
- return dayjs(date).format(format);
22
- };
23
- /**
24
- * Return a human-readable relative time string.
25
- *
26
- * @param {TDateInput} date - Date-like value to compare against now.
27
- * @returns {string} Relative time or `--` for missing/invalid input.
28
- */
29
- export const timeAgo = (date) => {
30
- if (!isValidDateInput(date)) {
31
- return defaultDateFallback;
32
- }
33
- return dayjs(date).fromNow();
34
- };
35
- /**
36
- * Add days to a date.
37
- *
38
- * @param {TDateInput} date - Source date.
39
- * @param {number} days - Number of days to add.
40
- * @returns {Date} Updated date.
41
- */
42
- export const addDays = (date, days) => {
43
- return dayjs(date).add(days, "day").toDate();
44
- };
45
- /**
46
- * Subtract days from a date.
47
- *
48
- * @param {TDateInput} date - Source date.
49
- * @param {number} days - Number of days to subtract.
50
- * @returns {Date} Updated date.
51
- */
52
- export const subtractDays = (date, days) => {
53
- return dayjs(date).subtract(days, "day").toDate();
54
- };
55
- /**
56
- * Return the absolute number of whole day boundaries between two dates.
57
- *
58
- * @param {TDateInput} dateA - First date.
59
- * @param {TDateInput} dateB - Second date.
60
- * @returns {number} Absolute difference in days, or 0 for invalid input.
61
- */
62
- export const daysBetween = (dateA, dateB) => {
63
- if (!isValidDateInput(dateA) || !isValidDateInput(dateB)) {
64
- return 0;
65
- }
66
- return Math.abs(dayjs(dateA).diff(dayjs(dateB), "day"));
67
- };
68
- /**
69
- * Check whether a date is today.
70
- *
71
- * @param {TDateInput} date - Date-like value.
72
- * @returns {boolean} True when the date is today.
73
- */
74
- export const isToday = (date) => {
75
- if (!isValidDateInput(date)) {
76
- return false;
77
- }
78
- return dayjs(date).isSame(dayjs(), "day");
79
- };
80
- /**
81
- * Check whether a date is in the past.
82
- *
83
- * @param {TDateInput} date - Date-like value.
84
- * @returns {boolean} True when the date is before now.
85
- */
86
- export const isPast = (date) => {
87
- if (!isValidDateInput(date)) {
88
- return false;
89
- }
90
- return dayjs(date).isBefore(dayjs());
91
- };
92
- /**
93
- * Check whether a date is in the future.
94
- *
95
- * @param {TDateInput} date - Date-like value.
96
- * @returns {boolean} True when the date is after now.
97
- */
98
- export const isFuture = (date) => {
99
- if (!isValidDateInput(date)) {
100
- return false;
101
- }
102
- return dayjs(date).isAfter(dayjs());
103
- };
104
- /**
105
- * Return the start of the day for a date.
106
- *
107
- * @param {TDateInput} date - Source date.
108
- * @returns {Date} Date set to 00:00:00.000.
109
- */
110
- export const startOfDay = (date) => {
111
- return dayjs(date).startOf("day").toDate();
112
- };
113
- /**
114
- * Return the end of the day for a date.
115
- *
116
- * @param {TDateInput} date - Source date.
117
- * @returns {Date} Date set to 23:59:59.999.
118
- */
119
- export const endOfDay = (date) => {
120
- return dayjs(date).endOf("day").toDate();
121
- };
122
- /**
123
- * Return the ISO week start date, Monday at 00:00:00.000.
124
- *
125
- * @param {TDateInput} date - Source date.
126
- * @returns {Date} Start of ISO week.
127
- */
128
- export const startOfWeek = (date) => {
129
- return dayjs(date).startOf("isoWeek").toDate();
130
- };
131
- /**
132
- * Return the ISO week end date, Sunday at 23:59:59.999.
133
- *
134
- * @param {TDateInput} date - Source date.
135
- * @returns {Date} End of ISO week.
136
- */
137
- export const endOfWeek = (date) => {
138
- return dayjs(date).endOf("isoWeek").toDate();
139
- };
140
- /**
141
- * Return all seven dates in the ISO week containing the provided date.
142
- *
143
- * @param {TDateInput} date - Source date.
144
- * @returns {Date[]} Monday-through-Sunday dates at the start of each day.
145
- */
146
- export const getWeekDays = (date) => {
147
- const weekStart = dayjs(date).startOf("isoWeek");
148
- return Array.from({ length: 7 }, (_value, index) => {
149
- return weekStart.add(index, "day").startOf("day").toDate();
150
- });
151
- };
152
- /**
153
- * Add weeks to a date.
154
- *
155
- * @param {TDateInput} date - Source date.
156
- * @param {number} weeks - Number of weeks to add.
157
- * @returns {Date} Updated date.
158
- */
159
- export const addWeeks = (date, weeks) => {
160
- return dayjs(date).add(weeks, "week").toDate();
161
- };
162
- /**
163
- * Subtract weeks from a date.
164
- *
165
- * @param {TDateInput} date - Source date.
166
- * @param {number} weeks - Number of weeks to subtract.
167
- * @returns {Date} Updated date.
168
- */
169
- export const subtractWeeks = (date, weeks) => {
170
- return dayjs(date).subtract(weeks, "week").toDate();
171
- };
@@ -1,4 +0,0 @@
1
- export * from "./date";
2
- export * from "./object";
3
- export { camelCase, capitalize, charCount, containsAll, containsAny, escapeRegex, extractNumbers, formatAddress, fromBase64, highlight, isEmail, isEmpty, isNumeric, isPalindrome, isUrl, kebabCase, kebabToSpaces, longestWord, lowerCase, normalCase, normalizeSpaces, padEnd, padStart, pascalCase, pluralize, removeDuplicates, removeSpecialChars, removeWhitespace, repeat, repeatChar, reverse, sentenceCase, slug, snakeCase, snakeCaseToSpaces, splitMultiple, stringSimilarity, stripHtml, titleCase, toBase64, toCamelCase, toKebabCase, toNumber, toPascalCase, toSnakeCase, truncate, upperCase, wordCount, } from "./string";
4
- export type { IAddress } from "./string";
@@ -1,3 +0,0 @@
1
- export * from "./date";
2
- export * from "./object";
3
- export { camelCase, capitalize, charCount, containsAll, containsAny, escapeRegex, extractNumbers, formatAddress, fromBase64, highlight, isEmail, isEmpty, isNumeric, isPalindrome, isUrl, kebabCase, kebabToSpaces, longestWord, lowerCase, normalCase, normalizeSpaces, padEnd, padStart, pascalCase, pluralize, removeDuplicates, removeSpecialChars, removeWhitespace, repeat, repeatChar, reverse, sentenceCase, slug, snakeCase, snakeCaseToSpaces, splitMultiple, stringSimilarity, stripHtml, titleCase, toBase64, toCamelCase, toKebabCase, toNumber, toPascalCase, toSnakeCase, truncate, upperCase, wordCount, } from "./string";
@@ -1,298 +0,0 @@
1
- import type { IFilterCondition, ISortCondition } from "../../types/base/paging.types";
2
- type TRecord = Record<string, unknown>;
3
- type TSortableValue = string | number | bigint | boolean | Date | null | undefined;
4
- type TReplaceNulls<TValue> = TValue extends null ? "" : TValue extends (infer TItem)[] ? TReplaceNulls<TItem>[] : TValue extends Date ? TValue : TValue extends object ? {
5
- [TKey in keyof TValue]: TReplaceNulls<TValue[TKey]>;
6
- } : TValue;
7
- /**
8
- * Safely parse a JSON string into a typed value.
9
- *
10
- * When a fallback value is provided, the function always returns that generic
11
- * type. Without a fallback value, parse failures return an empty object.
12
- *
13
- * @typeParam TParsed - Expected parsed value type.
14
- * @param {string | null | undefined} jsonString - JSON string to parse.
15
- * @param {TParsed} [fallbackValue] - Value returned when parsing fails.
16
- * @returns {TParsed | Record<string, unknown>} Parsed value or fallback.
17
- * @example
18
- * parseJSON<{ a: number }>('{"a":1}', { a: 0 }) // => { a: 1 }
19
- * parseJSON('not json') // => {}
20
- */
21
- export declare function parseJSON<TParsed>(jsonString: string | null | undefined, fallbackValue: TParsed): TParsed;
22
- export declare function parseJSON(jsonString: string | null | undefined): Record<string, unknown>;
23
- /**
24
- * Stringify a value to JSON while skipping circular references.
25
- *
26
- * Uses an internal cache to omit repeated object references that would
27
- * normally cause `JSON.stringify` to throw.
28
- *
29
- * @param {unknown} value - Value to stringify.
30
- * @returns {string | undefined} JSON string with circulars omitted.
31
- * @example
32
- * const value: Record<string, unknown> = {}; value.self = value;
33
- * JSONStringify(value) // => "{}"
34
- */
35
- export declare const JSONStringify: (value: unknown) => string | undefined;
36
- /**
37
- * Deep-remove `undefined` properties while preserving Dates and arrays.
38
- *
39
- * Object properties with `undefined` values are removed. Array items are
40
- * preserved so array indexes do not shift.
41
- *
42
- * @typeParam TValue - Input value type.
43
- * @param {TValue} value - Input value.
44
- * @returns {TValue} Cleaned clone with `undefined` object properties removed.
45
- */
46
- export declare const removeUndefined: <TValue>(value: TValue) => TValue;
47
- /**
48
- * Test whether a location object's `pathname` equals a key.
49
- *
50
- * @param {{ pathname?: string } | null | undefined} location - Object expected
51
- * to have a `pathname`.
52
- * @param {string} key - Path to compare.
53
- * @returns {boolean}
54
- * @example
55
- * validPath({ pathname: "/home" }, "/home") // true
56
- */
57
- export declare const validPath: (location: {
58
- pathname?: string;
59
- } | null | undefined, key: string) => boolean;
60
- /**
61
- * Return the first element if the input is an array; otherwise return the value itself.
62
- *
63
- * @typeParam T - Element type.
64
- * @param {T | T[]} input - A single value or an array.
65
- * @returns {T} First element or the input value.
66
- * @example
67
- * returnObject([1,2,3]) // 1
68
- * returnObject(5) // 5
69
- */
70
- export declare const returnObject: <T>(input: T | T[]) => T;
71
- /**
72
- * Filter out items from `array1` whose `id` appears in `array2`.
73
- *
74
- * @typeParam T - Object type with an `id` field.
75
- * @param {T[]} [array1] - Source array.
76
- * @param {T[]} [array2] - Items whose `id`s should be excluded.
77
- * @returns {T[]} Filtered array (or `[]` on invalid input).
78
- */
79
- export declare const filterArrayById: <T extends {
80
- id: number | string;
81
- }>(array1?: T[], array2?: T[]) => T[];
82
- /**
83
- * Sort an array of objects by a given property (ascending).
84
- *
85
- * Mutates the original array (uses `Array.prototype.sort`).
86
- *
87
- * @typeParam T - Object type.
88
- * @typeParam TKey - Sortable property key.
89
- * @param {T[]} array - Array to sort.
90
- * @param {TKey} property - Property name to sort by.
91
- * @returns {T[]} The same array instance, sorted (or empty array if input invalid).
92
- */
93
- export declare const sortArrayByProperty: <TKey extends PropertyKey, T extends Record<TKey, TSortableValue>>(array: T[], property: TKey) => T[];
94
- /**
95
- * Recursively replace `null` values with empty strings.
96
- *
97
- * Works on primitives, arrays, Dates, and plain objects.
98
- *
99
- * @typeParam TValue - Input value type.
100
- * @param {TValue} value - Input value.
101
- * @returns {TReplaceNulls<TValue>} Value with all `null` replaced by `""`.
102
- */
103
- export declare const replaceNulls: <TValue>(value: TValue) => TReplaceNulls<TValue>;
104
- /**
105
- * Recursively remove object keys that contain a dot (`.`).
106
- *
107
- * @typeParam TValue - Input value type.
108
- * @param {TValue} value - Input object or array.
109
- * @returns {TValue} New value with dotted keys removed at all levels.
110
- */
111
- export declare const removeFormProperties: <TValue>(value: TValue) => TValue;
112
- /**
113
- * Recursively convert string booleans `"true"`/`"false"` to actual booleans.
114
- *
115
- * Leaves all other values unchanged.
116
- *
117
- * @typeParam TValue - Input value type.
118
- * @param {TValue} value - Input object or array.
119
- * @returns {TValue} New value with boolean-like strings converted.
120
- */
121
- export declare const convertStringBooleans: <TValue>(value: TValue) => TValue;
122
- /**
123
- * Convenience helper to clean form-like data:
124
- * - Removes `undefined` properties
125
- * - Converts string booleans to booleans
126
- * - Removes keys containing a dot (`.`)
127
- *
128
- * @typeParam TObject - Form data object type.
129
- * @param {TObject} objectToClean - Input data.
130
- * @returns {Partial<TObject>} Cleaned clone.
131
- */
132
- export declare const cleanFormData: <TObject extends TRecord>(objectToClean: TObject) => Partial<TObject>;
133
- /**
134
- * Return a default pagination object, allowing optional sort and filters.
135
- *
136
- * @param {ISortCondition[]} [sort] - Optional sort conditions.
137
- * @param {IFilterCondition[]} [filters] - Optional filter conditions.
138
- * @returns {{ page: number; size: number; sort: ISortCondition[]; filters: IFilterCondition[] }}
139
- * @example
140
- * resetPagination() // => { page:1, size:25, sort:[], filters:[] }
141
- */
142
- export declare const resetPagination: (sort?: ISortCondition[], filters?: IFilterCondition[]) => {
143
- page: number;
144
- size: number;
145
- sort: ISortCondition[];
146
- filters: IFilterCondition[];
147
- };
148
- /**
149
- * Format a string of digits into a U.S. phone number.
150
- *
151
- * Strips non-numeric characters and formats 10 digits as `(XXX) XXX-XXXX`.
152
- * Strips a leading US country code when 11 digits are provided.
153
- * If a value cannot be formatted, returns the original value as a string.
154
- *
155
- * @param {string | number} value - Phone number digits (string or number).
156
- * @returns {string} Formatted phone number, or original input if invalid length.
157
- * @example
158
- * formatPhoneNumber("1234567890") // "(123) 456-7890"
159
- * formatPhoneNumber(9876543210) // "(987) 654-3210"
160
- * formatPhoneNumber("555") // "555"
161
- */
162
- export declare const formatPhoneNumber: (value: string | number) => string;
163
- /**
164
- * Format a number with thousands separators (commas).
165
- *
166
- * @param {number} value - Number to format.
167
- * @returns {string} String with commas.
168
- * @example
169
- * formatNumber(1234567) // "1,234,567"
170
- */
171
- export declare const formatNumber: (value: number) => string;
172
- /**
173
- * Remove comma separators from a number-like value.
174
- *
175
- * @param {number | string} value - Number-like value.
176
- * @returns {string} Value without comma separators.
177
- */
178
- export declare const parseNumber: (value: number | string) => string;
179
- /**
180
- * Delete a property from an object if it exists (no-op if it doesn't).
181
- *
182
- * @typeParam TObject - Object type.
183
- * @param {TObject} objectToUpdate - Target object (mutated).
184
- * @param {keyof TObject | string} propertyName - Property to delete.
185
- * @returns {void}
186
- */
187
- export declare const deletePropertyIfExists: <TObject extends TRecord>(objectToUpdate: TObject, propertyName: keyof TObject | string) => void;
188
- /**
189
- * Split an array into chunks of a given size.
190
- *
191
- * @typeParam T - Element type.
192
- * @param {T[]} array - Source array.
193
- * @param {number} chunkSize - Size of each chunk.
194
- * @returns {T[][]} Array of chunks (last one may be smaller).
195
- * @example
196
- * chunkArray([1,2,3,4,5], 2) // [[1,2],[3,4],[5]]
197
- */
198
- export declare const chunkArray: <T>(array: T[], chunkSize: number) => T[][];
199
- /**
200
- * Return a shallow clone of `objectToOmitFrom` without the listed properties.
201
- *
202
- * @typeParam TObject - Source object type.
203
- * @typeParam TKey - Keys to omit.
204
- * @param {TObject} objectToOmitFrom - Source object.
205
- * @param {readonly TKey[]} propsToOmit - Property names to omit.
206
- * @returns {Omit<TObject, TKey>} New object without omitted props.
207
- * @example
208
- * omitProperties({a:1,b:2}, ["b"]) // { a:1 }
209
- */
210
- export declare const omitProperties: <TObject extends TRecord, TKey extends keyof TObject>(objectToOmitFrom: TObject, propsToOmit: readonly TKey[]) => Omit<TObject, TKey>;
211
- /**
212
- * Safe `hasOwnProperty` check.
213
- *
214
- * @param {unknown} value - Value to test.
215
- * @param {PropertyKey} key - Property name.
216
- * @returns {boolean}
217
- */
218
- export declare const hasProperty: <TKey extends PropertyKey>(value: unknown, key: TKey) => value is Record<TKey, unknown>;
219
- /**
220
- * Safe `hasOwnProperty` alias from the reference utilities.
221
- *
222
- * @param {unknown} value - Value to test.
223
- * @param {PropertyKey} key - Property name.
224
- * @returns {boolean}
225
- */
226
- export declare const hasOwnProp: <TKey extends PropertyKey>(value: unknown, key: TKey) => value is Record<TKey, unknown>;
227
- /**
228
- * Determine if an object has at least one own enumerable property.
229
- *
230
- * @param {unknown} value - Object to test.
231
- * @returns {boolean} `true` if there is at least one key.
232
- */
233
- export declare const hasProperties: (value: unknown) => boolean;
234
- /**
235
- * Get the first own enumerable property value from an object.
236
- *
237
- * @typeParam TObject - Source object type.
238
- * @param {TObject | null | undefined} value - Source object.
239
- * @returns {TObject[keyof TObject] | null} First value, or null for empty/non-object input.
240
- */
241
- export declare const getFirstPropertyValue: <TObject extends TRecord>(value: TObject | null | undefined) => TObject[keyof TObject] | null;
242
- /**
243
- * Get a nested value from an object using dot notation.
244
- *
245
- * @param {unknown} value - Source object.
246
- * @param {string} path - Dot-delimited path.
247
- * @returns {unknown} Nested value, or undefined when the path cannot be resolved.
248
- * @example
249
- * getNestedValue({ user: { name: "John" } }, "user.name") // "John"
250
- */
251
- export declare const getNestedValue: (value: unknown, path: string) => unknown;
252
- /**
253
- * Set a nested value on an object using dot notation.
254
- *
255
- * Mutates and returns the provided object. Unsafe path segments are ignored to
256
- * prevent prototype pollution.
257
- *
258
- * @typeParam TObject - Target object type.
259
- * @param {TObject} objectToUpdate - Target object.
260
- * @param {string} path - Dot-delimited path.
261
- * @param {unknown} value - Value to set.
262
- * @returns {TObject} The mutated target object.
263
- * @example
264
- * setNestedValue({}, "user.name", "John") // { user: { name: "John" } }
265
- */
266
- export declare const setNestedValue: <TObject extends TRecord>(objectToUpdate: TObject, path: string, value: unknown) => TObject;
267
- /**
268
- * Deep clone a value while preserving Dates and circular references.
269
- *
270
- * @typeParam TValue - Input value type.
271
- * @param {TValue} value - Value to clone.
272
- * @returns {TValue} Deep clone of the input.
273
- */
274
- export declare const deepClone: <TValue>(value: TValue) => TValue;
275
- /**
276
- * Flatten a nested object into dot notation.
277
- *
278
- * Arrays and Dates are treated as leaf values.
279
- *
280
- * @param {TRecord} value - Source object.
281
- * @param {string} [prefix] - Internal prefix for recursion.
282
- * @returns {TRecord} Flattened object.
283
- * @example
284
- * flatten({ user: { name: "John" } }) // { "user.name": "John" }
285
- */
286
- export declare const flatten: (value: TRecord, prefix?: string) => TRecord;
287
- /**
288
- * Convert a dot-notation object into a nested object.
289
- *
290
- * Unsafe path segments are ignored to prevent prototype pollution.
291
- *
292
- * @param {TRecord} value - Dot-notation source object.
293
- * @returns {TRecord} Nested object.
294
- * @example
295
- * unflatten({ "user.name": "John" }) // { user: { name: "John" } }
296
- */
297
- export declare const unflatten: (value: TRecord) => TRecord;
298
- export {};