@postxl/utils 1.0.1 → 1.2.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 (114) hide show
  1. package/dist/index.browser.d.ts +2 -0
  2. package/dist/index.browser.js +3 -0
  3. package/dist/index.d.ts +22 -25
  4. package/dist/index.js +36 -41
  5. package/dist/index.js.map +1 -1
  6. package/dist/zod-excel.decoders-CiKlp4ZC.js +1375 -0
  7. package/dist/zod-excel.decoders-CiKlp4ZC.js.map +1 -0
  8. package/dist/zod-excel.decoders-CtmUu_Yj.d.ts +775 -0
  9. package/package.json +25 -16
  10. package/dist/DefaultMap.d.ts +0 -12
  11. package/dist/DefaultMap.d.ts.map +0 -1
  12. package/dist/DefaultMap.js +0 -26
  13. package/dist/DefaultMap.js.map +0 -1
  14. package/dist/NestedMap.d.ts +0 -17
  15. package/dist/NestedMap.d.ts.map +0 -1
  16. package/dist/NestedMap.js +0 -72
  17. package/dist/NestedMap.js.map +0 -1
  18. package/dist/TypedMapping.d.ts +0 -27
  19. package/dist/TypedMapping.d.ts.map +0 -1
  20. package/dist/TypedMapping.js +0 -33
  21. package/dist/TypedMapping.js.map +0 -1
  22. package/dist/array.d.ts +0 -7
  23. package/dist/array.d.ts.map +0 -1
  24. package/dist/array.js +0 -21
  25. package/dist/array.js.map +0 -1
  26. package/dist/async.d.ts +0 -4
  27. package/dist/async.d.ts.map +0 -1
  28. package/dist/async.js +0 -41
  29. package/dist/async.js.map +0 -1
  30. package/dist/buffer.d.ts +0 -5
  31. package/dist/buffer.d.ts.map +0 -1
  32. package/dist/buffer.js +0 -16
  33. package/dist/buffer.js.map +0 -1
  34. package/dist/check-port.d.ts +0 -10
  35. package/dist/check-port.d.ts.map +0 -1
  36. package/dist/check-port.js +0 -40
  37. package/dist/check-port.js.map +0 -1
  38. package/dist/datetime.d.ts +0 -23
  39. package/dist/datetime.d.ts.map +0 -1
  40. package/dist/datetime.js +0 -37
  41. package/dist/datetime.js.map +0 -1
  42. package/dist/dictionary.d.ts +0 -9
  43. package/dist/dictionary.d.ts.map +0 -1
  44. package/dist/dictionary.js +0 -45
  45. package/dist/dictionary.js.map +0 -1
  46. package/dist/format.d.ts +0 -2
  47. package/dist/format.d.ts.map +0 -1
  48. package/dist/format.js +0 -7
  49. package/dist/format.js.map +0 -1
  50. package/dist/group-by.d.ts +0 -9
  51. package/dist/group-by.d.ts.map +0 -1
  52. package/dist/group-by.js +0 -66
  53. package/dist/group-by.js.map +0 -1
  54. package/dist/index.d.ts.map +0 -1
  55. package/dist/is-object.d.ts +0 -13
  56. package/dist/is-object.d.ts.map +0 -1
  57. package/dist/is-object.js +0 -25
  58. package/dist/is-object.js.map +0 -1
  59. package/dist/map.d.ts +0 -23
  60. package/dist/map.d.ts.map +0 -1
  61. package/dist/map.js +0 -76
  62. package/dist/map.js.map +0 -1
  63. package/dist/omit.d.ts +0 -5
  64. package/dist/omit.d.ts.map +0 -1
  65. package/dist/omit.js +0 -11
  66. package/dist/omit.js.map +0 -1
  67. package/dist/pagination.d.ts +0 -7
  68. package/dist/pagination.d.ts.map +0 -1
  69. package/dist/pagination.js +0 -14
  70. package/dist/pagination.js.map +0 -1
  71. package/dist/random.d.ts +0 -11
  72. package/dist/random.d.ts.map +0 -1
  73. package/dist/random.js +0 -56
  74. package/dist/random.js.map +0 -1
  75. package/dist/remove-secrets.d.ts +0 -12
  76. package/dist/remove-secrets.d.ts.map +0 -1
  77. package/dist/remove-secrets.js +0 -62
  78. package/dist/remove-secrets.js.map +0 -1
  79. package/dist/remove-undefined.d.ts +0 -10
  80. package/dist/remove-undefined.d.ts.map +0 -1
  81. package/dist/remove-undefined.js +0 -22
  82. package/dist/remove-undefined.js.map +0 -1
  83. package/dist/result.d.ts +0 -35
  84. package/dist/result.d.ts.map +0 -1
  85. package/dist/result.js +0 -120
  86. package/dist/result.js.map +0 -1
  87. package/dist/sort.d.ts +0 -18
  88. package/dist/sort.d.ts.map +0 -1
  89. package/dist/sort.js +0 -64
  90. package/dist/sort.js.map +0 -1
  91. package/dist/string-colors.d.ts +0 -45
  92. package/dist/string-colors.d.ts.map +0 -1
  93. package/dist/string-colors.js +0 -73
  94. package/dist/string-colors.js.map +0 -1
  95. package/dist/string.d.ts +0 -162
  96. package/dist/string.d.ts.map +0 -1
  97. package/dist/string.js +0 -434
  98. package/dist/string.js.map +0 -1
  99. package/dist/types.d.ts +0 -98
  100. package/dist/types.d.ts.map +0 -1
  101. package/dist/types.js +0 -57
  102. package/dist/types.js.map +0 -1
  103. package/dist/uniq.d.ts +0 -2
  104. package/dist/uniq.d.ts.map +0 -1
  105. package/dist/uniq.js +0 -16
  106. package/dist/uniq.js.map +0 -1
  107. package/dist/zod-excel.decoders.d.ts +0 -162
  108. package/dist/zod-excel.decoders.d.ts.map +0 -1
  109. package/dist/zod-excel.decoders.js +0 -361
  110. package/dist/zod-excel.decoders.js.map +0 -1
  111. package/dist/zod.d.ts +0 -30
  112. package/dist/zod.d.ts.map +0 -1
  113. package/dist/zod.js +0 -56
  114. package/dist/zod.js.map +0 -1
@@ -0,0 +1,775 @@
1
+ import z$1, { z } from "zod";
2
+
3
+ //#region src/DefaultMap.d.ts
4
+ /**
5
+ * A map extension that returns a default value if the key is not found.
6
+ */
7
+ /**
8
+ * A map extension that returns a default value if the key is not found.
9
+ */
10
+ declare class DefaultMap<Key, Value> extends Map<Key, Value> {
11
+ private readonly _default;
12
+ /**
13
+ * A function that returns the default value for the map.
14
+ */
15
+ constructor(_default: () => Value);
16
+ get(key: Key): Value;
17
+ }
18
+
19
+ //#endregion
20
+ //#region src/NestedMap.d.ts
21
+ declare class NestedMap<Key1, Key2, Item> {
22
+ private readonly getKey1;
23
+ private readonly getKey2;
24
+ private readonly _map;
25
+ constructor(getKey1: (item: Item) => Key1, getKey2: (item: Item) => Key2, items?: Item[]);
26
+ get(key1: Key1, key2: Key2): Item | undefined;
27
+ private getKeys;
28
+ set(item: Item): void;
29
+ delete(item: Item): void;
30
+ clear(): void;
31
+ get size(): number;
32
+ get keys(): Iterable<Key1>;
33
+ get values(): Iterable<Item>;
34
+ get entries(): Iterable<[Key1, Key2, Item]>;
35
+ get [Symbol.iterator](): Iterable<[Key1, Key2, Item]>;
36
+ }
37
+
38
+ //#endregion
39
+ //#region src/TypedMapping.d.ts
40
+ type IdentifiersBase = Record<string, string>;
41
+ type Mapping<T> = Map<T, T>;
42
+ /**
43
+ * A map of typed mappings.
44
+ */
45
+ declare class TypedMapping<Identifiers extends IdentifiersBase> {
46
+ private mappings;
47
+ constructor(mappings?: { [Model in keyof Identifiers]?: Mapping<Identifiers[Model]> });
48
+ /**
49
+ * Creates a new mapping from the original id to the new id.
50
+ */
51
+ set<Model extends keyof Identifiers>({
52
+ model,
53
+ id
54
+ }: {
55
+ model: Model;
56
+ id: Identifiers[Model];
57
+ }, newId: Identifiers[Model]): this;
58
+ /**
59
+ * Returns the id if there exists a mapping, otherwise returns the original id.
60
+ */
61
+ get<Model extends keyof Identifiers>({
62
+ model,
63
+ id
64
+ }: {
65
+ model: Model;
66
+ id: Identifiers[Model];
67
+ }): Identifiers[Model];
68
+ }
69
+
70
+ //#endregion
71
+ //#region src/array.d.ts
72
+ /**
73
+ * Adds a value to a sorted array and keeps the array sorted.
74
+ *
75
+ * O(n)
76
+ */
77
+ declare function addAndSort<T>(arr: T[], value: T, predicate: (t: T) => number): T[];
78
+
79
+ //#endregion
80
+ //#region src/async.d.ts
81
+ type AsyncMapFn<T, R> = (item: T, index: number) => Promise<R>;
82
+ declare function mapLimit<T, R>(arr: T[], iterator: AsyncMapFn<T, R>, limit?: number): Promise<(R | undefined)[]>;
83
+
84
+ //#endregion
85
+ //#region src/buffer.d.ts
86
+ /**
87
+ * Compares two string or buffer values for equality.
88
+ */
89
+ declare function equals(a: string | Buffer, b: string | Buffer): boolean;
90
+
91
+ //#endregion
92
+ //#region src/datetime.d.ts
93
+ /**
94
+ * returns the default time stamp in format YYMMDD HHMM
95
+ */
96
+ declare function timeStamp(): string;
97
+ /**
98
+ * Checks if a value is a valid Date object.
99
+ * Returns true only for Date instances that are not Invalid Date.
100
+ * This function is isomorphic and works in both Node.js and browser environments.
101
+ *
102
+ * @param value - The value to check
103
+ * @returns true if the value is a valid Date object, false otherwise
104
+ *
105
+ * @example
106
+ * isDate(new Date()) // true
107
+ * isDate(new Date('2023-01-01')) // true
108
+ * isDate(new Date('invalid')) // false (Invalid Date)
109
+ * isDate('2023-01-01') // false
110
+ * isDate(1234567890) // false
111
+ * isDate(null) // false
112
+ * isDate(undefined) // false
113
+ */
114
+ declare function isDate(value: unknown): value is Date;
115
+
116
+ //#endregion
117
+ //#region src/dictionary.d.ts
118
+ type Dictionary<Value, Key extends string = string> = Record<Key, Value>;
119
+ declare function toDict<Value, Key extends string = string>(data: Value[], keyFn: (item: Value) => Key): Dictionary<Value, Key>;
120
+ declare function idToDict<T extends {
121
+ id: string | number;
122
+ }>(data: T[]): Dictionary<T>;
123
+ declare function mapDict<S, T>(dict: Dictionary<S>, predicate: (item: S) => T): Dictionary<T>;
124
+ declare function filterDict<T>(dict: Dictionary<T>, predicate: (item: T) => boolean): Dictionary<T>;
125
+ declare function dictGetAndAssert<Key extends string, Value>(dict: Dictionary<Value>, key: Key): NonNullable<Value>;
126
+
127
+ //#endregion
128
+ //#region src/format.d.ts
129
+ declare function format(n: number, locale?: string): string;
130
+
131
+ //#endregion
132
+ //#region src/group-by.d.ts
133
+ declare const groupBy: <T, U extends string | number>(predicate: (x: T) => U, items: T[]) => Partial<Record<U, T[]>>;
134
+ declare const groupByCurried: <T, U extends string | number>(predicate: (x: T) => U) => ((items: T[]) => Partial<Record<U, T[]>>);
135
+ declare const groupByToDict: <Id extends string | number, WithId extends {
136
+ id: Id;
137
+ }, GroupId extends string | number>(predicate: (x: WithId) => GroupId, items: WithId[]) => Partial<Record<GroupId, Record<Id, WithId>>>;
138
+ declare const groupByToMap: <T extends {
139
+ id: ItemID;
140
+ }, ItemID extends string | number, GroupID extends string | number>(getGroupId: (x: T) => GroupID, items: T[]) => Map<GroupID, Map<ItemID, T>>;
141
+
142
+ //#endregion
143
+ //#region src/map.d.ts
144
+ declare function mapMap<Key, ValueFrom, ValueTo>(map: Map<Key, ValueFrom>, predicate: (item: ValueFrom, key: Key) => ValueTo): Map<Key, ValueTo>;
145
+ declare function mapMapValues<Key, ValueFrom, ValueTo>(map: Map<Key, ValueFrom>, predicate: (item: ValueFrom, key: Key) => ValueTo): ValueTo[];
146
+ /**
147
+ *
148
+ */
149
+ declare function mapMapKeyValues<KeyFrom, KeyTo, ValueFrom, ValueTo>(map: Map<KeyFrom, ValueFrom>, keyPredicate: (key: KeyFrom, value: ValueFrom) => KeyTo, valuePredicate: (item: ValueFrom, key: KeyFrom) => ValueTo): Map<KeyTo, ValueTo>;
150
+ /**
151
+ * Maps keys of a map.
152
+ */
153
+ declare function mapMapKeys<KeyFrom, KeyTo, Value>(map: Map<KeyFrom, Value>, keyPredicate: (key: KeyFrom, value: Value) => KeyTo): Map<KeyTo, Value>;
154
+ /**
155
+ * Filters values from a map.
156
+ */
157
+ declare function filterMap<Key, Value>(map: Map<Key, Value>, predicate: (item: Value, key: Key) => boolean): Map<Key, Value>;
158
+ /**
159
+ * Gets a value from a map and asserts that it exists.
160
+ */
161
+ declare function mapGetAndAssert<Key, Value>(map: Map<Key, Value>, key: Key): Value;
162
+ /**
163
+ * Converts a map to a dictionary.
164
+ */
165
+ declare function mapToDict<Key extends string | number, Value>(map: Map<Key, Value>): Record<Key, Value>;
166
+
167
+ //#endregion
168
+ //#region src/omit.d.ts
169
+ /**
170
+ * Omits a key from an object
171
+ */
172
+ declare function omit<T extends Record<string, unknown>>(obj: T, key: string): Omit<T, typeof key>;
173
+
174
+ //#endregion
175
+ //#region src/pagination.d.ts
176
+ type Page<Item> = {
177
+ total: number;
178
+ offset: number;
179
+ items: Item[];
180
+ };
181
+ declare const slice: <Item>(items: Item[], skip?: number, take?: number) => Page<Item>;
182
+
183
+ //#endregion
184
+ //#region src/random.d.ts
185
+ /**
186
+ * Returns a random integer between 0 (inclusive) and max (exclusive).
187
+ *
188
+ * Isomorphic implementation for Node.js, Deno, Bun, and browser environments.
189
+ * Uses Web Crypto API which is available in all modern JavaScript runtimes.
190
+ */
191
+ declare function randomInt(max: number): number;
192
+ /**
193
+ * Returns a randomly generated alphanumeric string.
194
+ */
195
+ declare function generateRandomAlphanumericString(length: number): string;
196
+
197
+ //#endregion
198
+ //#region src/remove-secrets.d.ts
199
+ /**
200
+ * Removes secrets from the given configuration object.
201
+ *
202
+ * Recursively checks all properties of the object for keys that end with
203
+ * `key`, `secret`, `password`, `token` and replaces them with '***'.
204
+ *
205
+ * Also checks for keys the end with `connection` or `connectionString` and
206
+ * replaces the connection string with the same string but with the password
207
+ * replaced with '***'.
208
+ */
209
+ declare function removeSecrets<T extends Record<string, unknown>>(config: T): T;
210
+
211
+ //#endregion
212
+ //#region src/remove-undefined.d.ts
213
+ /**
214
+ * Removes all undefined properties from an object.
215
+ *
216
+ * NOTE: This is useful when using the `Partial<T>` type modifier in combination with the spread operator to prevent
217
+ * overriding with undefined values.
218
+ */
219
+ declare function removeUndefinedProperties<T extends Record<string, unknown>>(obj: T): { [K in keyof T]: T[K] extends undefined ? never : T[K] };
220
+
221
+ //#endregion
222
+ //#region src/result.d.ts
223
+ type SerializedResult<A, E> = {
224
+ tag: 'ok';
225
+ value: A;
226
+ } | {
227
+ tag: 'err';
228
+ err: E;
229
+ };
230
+ declare class Result<A, E> {
231
+ #private;
232
+ static ok<A, E>(value: A): Result<A, E>;
233
+ static err<A, E>(value: E): Result<A, E>;
234
+ static fromThrowable<A, E>(f: () => A, handleError: (error: Error) => E): Result<A, E>;
235
+ static fromObject<A, E>(result: SerializedResult<A, E>): Result<A, E>;
236
+ static fromPromise<A, E>(promise: () => Promise<A>, handleError: (error: Error) => E): Promise<Result<A, E>>;
237
+ private constructor();
238
+ private constructor();
239
+ isOk(): this is Result<A, never>;
240
+ isErr(): this is Result<never, E>;
241
+ map<B>(f: (a: A) => B): Result<B, E>;
242
+ mapErr<X>(f: (e: E) => X): Result<A, X>;
243
+ andThen<B>(f: (a: A) => Result<B, E>): Result<B, E>;
244
+ withDefault(fallback: A): A;
245
+ unwrap(): A;
246
+ unwrapErr(): E;
247
+ toJSON(): SerializedResult<A, E>;
248
+ }
249
+ declare const ok: typeof Result.ok;
250
+ declare const err: typeof Result.err;
251
+ type TypedError<T extends string> = {
252
+ type: T;
253
+ message: string;
254
+ error: Error;
255
+ };
256
+
257
+ //#endregion
258
+ //#region src/sort.d.ts
259
+ type CompareFn<T> = (a: T, b: T) => number;
260
+ type Direction = 'asc' | 'desc';
261
+ declare const sort: <Item>(items: Item[], dir?: Direction, compareFn?: CompareFn<Item>) => Item[];
262
+ /**
263
+ * Compare fields of an object.
264
+ */
265
+ declare const compareFields: <T>(key: keyof T) => CompareFn<T>;
266
+ type Getter<T> = (data: T) => unknown;
267
+ declare const compare: <T>(getter: Getter<T>) => CompareFn<T>;
268
+ declare const keyGetter: <T>(key: keyof T) => Getter<T>;
269
+ declare const compareValues: CompareFn<unknown>;
270
+ declare const compareDates: CompareFn<Date>;
271
+ declare const compareStrings: CompareFn<string>;
272
+ declare const compareNumbers: CompareFn<number>;
273
+ declare const compareBooleans: CompareFn<boolean>;
274
+ declare const booleanCode: (bool: boolean) => number;
275
+ declare const setDirection: <Item>(items: Item[], dir: Direction) => Item[];
276
+
277
+ //#endregion
278
+ //#region src/string-colors.d.ts
279
+ /**
280
+ * A function that returns a string with a specific color.
281
+ */
282
+ type ColorFn = (input: string) => string;
283
+ /**
284
+ * Colors a string in red color (using ANSI escape codes).
285
+ */
286
+ declare function red(input: string): string;
287
+ /**
288
+ * Colors a string in green color (using ANSI escape codes).
289
+ */
290
+ declare function green(input: string): string;
291
+ /**
292
+ * Colors a string in yellow color (using ANSI escape codes).
293
+ */
294
+ declare function yellow(input: string): string;
295
+ /**
296
+ * Colors a string in blue color (using ANSI escape codes).
297
+ */
298
+ declare function blue(input: string): string;
299
+ /**
300
+ * Colors a string in cyan color (using ANSI escape codes).
301
+ */
302
+ declare function cyan(input: string): string;
303
+ /**
304
+ * Colors a string in gray color (using ANSI escape codes).
305
+ */
306
+ declare function gray(input: string): string;
307
+ /**
308
+ * Colors a string in bold color (using ANSI escape codes).
309
+ */
310
+ declare function bold(input: string): string;
311
+ /**
312
+ * Colors a string in underline color (using ANSI escape codes).
313
+ */
314
+ declare function underline(input: string): string;
315
+ /**
316
+ * Colors a string in italic color (using ANSI escape codes).
317
+ */
318
+ declare function italic(input: string): string;
319
+ /**
320
+ * Inverts the color of a string (using ANSI escape codes).
321
+ */
322
+ declare function inverse(input: string): string;
323
+
324
+ //#endregion
325
+ //#region src/string.d.ts
326
+ declare function upperFirst(s: string): string;
327
+ declare function lowerFirst(s: string): string;
328
+ /**
329
+ * Returns a pluralized version of the given string based on the count.
330
+ */
331
+ declare function pluralize(s: string, count?: number): string;
332
+ /**
333
+ * Returns true if the given string is already pluralized.
334
+ */
335
+ declare function isPlural(s: string): boolean;
336
+ /**
337
+ * Type modifier that converts all keys of an object to capitalized versions.
338
+ */
339
+ type CapitalizedKeys<T extends Record<string, unknown>> = { [K in keyof T as CapitalizeFirstLetter<string & K>]: T[K] };
340
+ /**
341
+ * Type modifier that converts the first letter of a string to a capital letter.
342
+ */
343
+ type CapitalizeFirstLetter<S extends string> = `${Capitalize<Extract<S, string>>}`;
344
+ /**
345
+ * Converts all keys of an object to capitalized versions in a type-safe way.
346
+ */
347
+ declare function capitalizeKeys<T extends Record<string, unknown>>(obj: T): CapitalizedKeys<T>;
348
+ /**
349
+ * Type modifier that converts all keys of an object to uncapitalized versions.
350
+ */
351
+ type UncapitalizedKeys<T extends Record<string, unknown>> = { [K in keyof T as UncapitalizeFirstLetter<string & K>]: T[K] };
352
+ /**
353
+ * Type modifier that converts the first letter of a string to an uncapitalized letter.
354
+ */
355
+ type UncapitalizeFirstLetter<S extends string> = `${Uncapitalize<Extract<S, string>>}`;
356
+ /**
357
+ * Converts all keys of an object to uncapitalized versions in a type-safe way.
358
+ */
359
+ declare function uncapitalizeKeys<T extends Record<string, unknown>>(obj: T): UncapitalizedKeys<T>;
360
+ /**
361
+ * Returns the same string with a lowercase first letter.
362
+ */
363
+ declare function uncapitalize(str: string): string;
364
+ /**
365
+ * Returns the same string with an uppercase first letter.
366
+ */
367
+ declare function capitalize(str: string): string;
368
+ /**
369
+ * Returns the camelCase version of the given string.
370
+ *
371
+ * Camel case examples:
372
+ * `toCamelCase('hello world')` -> 'helloWorld',
373
+ * `toCamelCase('hello_world')` -> 'helloWorld',
374
+ * `toCamelCase('helloWorld')` -> 'helloWorld'
375
+ * `toCamelCase('HelloWorld')` -> 'helloWorld'
376
+ * `toCamelCase('hello_world')` -> 'helloWorld'
377
+ */
378
+ declare function toCamelCase(str: string): string;
379
+ /**
380
+ * Validates if a string is in camelCase format
381
+ */
382
+ declare function isCamelCase(str: string): boolean;
383
+ /**
384
+ * Returns the PascalCase version of the given string.
385
+ *
386
+ * Examples:
387
+ * `toPascalCase('hello world')` -> 'HelloWorld'
388
+ * `toPascalCase('hello_world')` -> 'HelloWorld'
389
+ * `toPascalCase('helloWorld')` -> 'HelloWorld'
390
+ * `toPascalCase('Hello-World')` -> 'HelloWorld'
391
+ * `toPascalCase('HELLO_WORLD')` -> 'HelloWorld'
392
+ */
393
+ declare function toPascalCase(str: string): string;
394
+ /**
395
+ * Validates if a string is in PascalCase format
396
+ */
397
+ declare function isPascalCase(str: string): boolean;
398
+ /**
399
+ * Returns the snake_case version of the given string.
400
+ *
401
+ * Examples:
402
+ * `toSnakeCase('hello world')` -> 'hello_world'
403
+ * `toSnakeCase('helloWorld')` -> 'hello_world'
404
+ * `toSnakeCase('HelloWorld')` -> 'hello_world'
405
+ * `toSnakeCase('HELLO_WORLD')` -> 'hello_world'
406
+ */
407
+ declare function toSnakeCase(str: string): string;
408
+ /**
409
+ * Validates if a string is in snake_case format
410
+ */
411
+ declare function isSnakeCase(str: string): boolean;
412
+ /**
413
+ * Returns the kebab-case version of the given string.
414
+ *
415
+ * Examples:
416
+ * `toKebabCase('hello world')` -> 'hello-world'
417
+ * `toKebabCase('helloWorld')` -> 'hello-world'
418
+ * `toKebabCase('HelloWorld')` -> 'hello-world'
419
+ * `toKebabCase('HELLO_WORLD')` -> 'hello-world'
420
+ */
421
+ declare function toKebabCase(str: string): string;
422
+ /**
423
+ * Validates if a string is in kebab-case format
424
+ */
425
+ declare function isKebabCase(str: string): boolean;
426
+ /**
427
+ * Converts each line of a string to a commented line
428
+ */
429
+ declare function commentLines(lines: string): string;
430
+ declare function toHumanReadable(input: string): string;
431
+ /**
432
+ * Sanitizes a string to be a valid Excel ListObject (table) column name.
433
+ * - Removes illegal characters: [ ] : ? * / \
434
+ * - Trims leading/trailing spaces
435
+ * - Replaces multiple spaces with a single space
436
+ * - If the result is empty, returns a default name
437
+ */
438
+ declare function toExcelColumnName(input: string, defaultName?: string): string;
439
+ /**
440
+ * Sanitizes a string to be a valid Excel ListObject (table) name.
441
+ * - Must start with a letter, underscore, or backslash
442
+ * - Only letters, numbers, and underscores allowed (no spaces or punctuation)
443
+ * - Cannot be a cell reference (e.g., "A1")
444
+ * - Max 255 characters
445
+ * - If invalid or empty, returns a default name
446
+ */
447
+ declare function toExcelTableName(input: string, defaultName?: string): string;
448
+ type Conjugated = {
449
+ camelCase: string;
450
+ camelCasePlural: string;
451
+ capitalized: string;
452
+ capitalizedPlural: string;
453
+ kebabCase: string;
454
+ kebabCasePlural: string;
455
+ PascalCase: string;
456
+ PascalCasePlural: string;
457
+ pluralized: string;
458
+ snake_case_plural: string;
459
+ snake_case: string;
460
+ uncapitalized: string;
461
+ uncapitalizedPlural: string;
462
+ };
463
+ /**
464
+ * Provide all relevant conjugation of a name
465
+ */
466
+ declare function conjugateNames(name: string): Conjugated;
467
+ declare function slugify(str: string): string;
468
+ declare function isSlug(str: string): boolean;
469
+ /**
470
+ * Ensures that a string is unique within a list of existing values by appending a sequential number if necessary.
471
+ *
472
+ * If the base string is not in the list, it is returned as is.
473
+ * If it is, the function looks for existing strings in the format "base (n)" where n is a number,
474
+ * and returns the next available sequential string.
475
+ *
476
+ * @param value - The base string to ensure uniqueness for.
477
+ * @param existingValues - An array of existing strings to check against.
478
+ * @param maxChecks - Maximum number of checks to be performed. An error is thrown if this limit is exceeded. Default is 100
479
+ * @returns A unique string based on the base string.
480
+ */
481
+ declare const ensureUnique: (value: string, existingValues: string[], maxChecks?: number) => string;
482
+
483
+ //#endregion
484
+ //#region src/types.d.ts
485
+ type Without<T, U> = Partial<Record<Exclude<keyof T, keyof U>, never>>;
486
+ type XOR<T, U> = T | U extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;
487
+ type Exact<T, I> = T extends I ? (Exclude<keyof T, keyof I> extends never ? T : never) : never;
488
+ type UncapitalizeObjectKeys<T> = { [key in keyof T as Uncapitalize<key & string>]: T[key] };
489
+ type Prettify<T> = { [K in keyof T]: T[K] };
490
+ /**
491
+ * Distributive Pick - does not collapse unions into a "shared type" only to
492
+ * run Pick on it. Instead, it "picks" from each union item separately.
493
+ *
494
+ * See https://github.com/klimashkin/css-modules-theme/pull/8
495
+ *
496
+ * Example:
497
+ * Pick<{ type: "pick" } | { type: "omit" }, "type">
498
+ * produces { type: "pick" | "omit" }
499
+ *
500
+ * UnionPick<{ type: "pick" } | { type: "omit" }, "type">
501
+ * produces { type: "pick" } | { type: "omit" }
502
+ */
503
+ type UnionPick<T, K extends keyof T> = T extends unknown ? Pick<T, K> : never;
504
+ /**
505
+ * Like UnionPick, but for Omit
506
+ */
507
+ type UnionOmit<T, K extends keyof T> = T extends unknown ? Omit<T, K> : never;
508
+ /**
509
+ * Makes a type check that is only valid when all cases of a switch
510
+ * statement have been covered.
511
+ */
512
+ declare class ExhaustiveSwitchCheck extends Error {
513
+ constructor(val: never);
514
+ }
515
+ /**
516
+ * A type that represents an array that is guaranteed to have at least one element.
517
+ */
518
+ type NonEmptyArray<T> = [T, ...T[]];
519
+ /**
520
+ * Converts a nested object to a nested object where all properties are optional.
521
+ */
522
+ type DeepPartial<T> = T extends object ? { [P in keyof T]?: DeepPartial<T[P]> } : T;
523
+ /**
524
+ * Changes properties of an object type to optional.
525
+ *
526
+ * Example:
527
+ * type Foo = { a: string, b: number, c: boolean }
528
+ * type Bar = Optional<Foo, 'a' | 'b'>
529
+ * // Bar is { a?: string, b?: number, c: boolean }
530
+ */
531
+ type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
532
+ /**
533
+ * Allows inline type assertions.
534
+ *
535
+ * Example:
536
+ * ```
537
+ * type Original = { a: number }
538
+ * type WithExtra = Original & { b: string }
539
+ *
540
+ * function addExtra(obj: Original): asserts obj is WithExtra {
541
+ * assertType(obj)
542
+ * obj.b = 'new value' // ✅ No TypeScript error!
543
+ * }
544
+ * ```
545
+ */
546
+ declare function assertType<T>(value: unknown): asserts value is T;
547
+ /**
548
+ * Applies a type assertion to an entire array and hence asserts the array.
549
+ *
550
+ * Type assertions are especially useful when you want to modify and object in place - a function
551
+ * with a type assertion lets TypeScript know that the object was modified.
552
+ *
553
+ * Example:
554
+ * ```
555
+ * type Original = { a: number }
556
+ * type WithExtra = Original & { b: string }
557
+ *
558
+ * function addExtra(obj: Original): asserts obj is WithExtra {
559
+ * obj.b = 'new value'
560
+ * }
561
+ *
562
+ * const myObj: Original[] = [{ a: 1 }]
563
+ * console.log(myObj[0].b) // ❌ TypeScript error!
564
+ * assertArray(myObj, addExtra)
565
+ * console.log(myObj[0].b) // ✅ No TypeScript error!
566
+ * ```
567
+ */
568
+ declare function assertArray<I, O extends I>(obj: I[], fn: (i: I) => asserts i is O): asserts obj is O[];
569
+ /**
570
+ * Converts any branded string type to its underlying string type.
571
+ */
572
+ type Debrand<T> = T extends string & infer _U ? string : T extends object ? { [K in keyof T]: Debrand<T[K]> } : T;
573
+
574
+ //#endregion
575
+ //#region src/uniq.d.ts
576
+ declare function uniq<T>(items: T[], predicate: (item: T) => number): T[];
577
+
578
+ //#endregion
579
+ //#region src/zod.d.ts
580
+ type Transformer<Input, Output> = (value: Input, ctx: z.RefinementCtx) => Output | z.ZodNever;
581
+ type ReturnTypeOfLast<T extends any[]> = T extends [...any, infer L] ? L extends ((...args: any) => any) ? ReturnType<L> : never : never;
582
+ /**
583
+ * Pipes a list of Zod transformers together in a type-safe way. Returns early if any of the transformers returns `z.NEVER`.
584
+ */
585
+ declare function pipeZodTransformers<Initial, Fns extends [Transformer<any, any>, ...Transformer<any, any>[]]>(initialValue: Initial, ctx: z.RefinementCtx, fns: Fns): ReturnTypeOfLast<Fns>;
586
+ /**
587
+ * Returns a Zod error callback that returns the given message for union errors.
588
+ *
589
+ * This is useful for generating meaningful error messages for unions, e.g.
590
+ * ```
591
+ * z.union(
592
+ * [z.constant('foo'), z.constant('bar')],
593
+ * unionErrorMessage('Value must be either "foo" or "bar"!')
594
+ * )
595
+ * ```
596
+ *
597
+ * In addition to a static message, you can also pass a function that takes the
598
+ * invalid data as input and returns a string. Example:
599
+ * ```
600
+ * z.union(
601
+ * [z.constant('foo'), z.constant('bar')],
602
+ * unionErrorMessage((data) => `Value must be either "foo" or "bar" - received ${JSON.stringify(data)} instead!`)
603
+ * )
604
+ * ```
605
+ */
606
+ declare function unionErrorMessage(param: string | ((data: unknown) => string)): {
607
+ error: (issue: any) => string;
608
+ };
609
+
610
+ //#endregion
611
+ //#region src/zod-excel.decoders.d.ts
612
+ /**
613
+ * A decoder that transforms Excel strings to JS strings, also handling numbers and boolean. Will not parse any other type!
614
+ *
615
+ * Background: In Excel, entering a number in a cell will automatically convert it to a number -
616
+ * and xlPort will return it as a number. However, often we want to treat it as a string - this decoder
617
+ * hence accepts both strings and numbers, and converts numbers to strings.
618
+ *
619
+ * It'll perform casting based on the following rules:
620
+ * - If the value is a number, it'll be converted to a string
621
+ * - If the value is a string, it'll be returned as-is
622
+ * - If the value is boolean, it'll return 'true' or 'false'
623
+ *
624
+ * Any other type will throw an error!
625
+ */
626
+ declare const excelStringStrictDecoder: z$1.ZodPipe<z$1.ZodUnion<readonly [z$1.ZodString, z$1.ZodNumber, z$1.ZodBoolean]>, z$1.ZodTransform<string, string | number | boolean>>;
627
+ /**
628
+ * A decoder that transforms Excel strings to JS strings, also handling numbers and any other potential type
629
+ *
630
+ * Background: In Excel, entering a number in a cell will automatically convert it to a number -
631
+ * and xlPort will return it as a number. However, often we want to treat it as a string - this decoder
632
+ * hence accepts both strings and numbers, and converts numbers to strings.
633
+ *
634
+ * It'll perform casting based on the following rules:
635
+ * - If the value is a number, it'll be converted to a string
636
+ * - If the value is a string, it'll be returned as-is
637
+ * - If the value is boolean, it'll return 'true' or 'false'
638
+ * - If the value is null or undefined, it'll return an empty string
639
+ * - If the value is any other type, it'll return an empty string
640
+ *
641
+ * Null handling: Null values/blank cells will be converted to a blank string.
642
+ */
643
+ declare const excelStringDecoder: z$1.ZodPipe<z$1.ZodTransform<string, unknown>, z$1.ZodString>;
644
+ /**
645
+ * A decoder that transforms Excel strings to JS strings, also handling numbers and null
646
+ *
647
+ * Background: In Excel, entering a number in a cell will automatically convert it to a number -
648
+ * and xlPort will return it as a number. However, often we want to treat it as a string - this decoder
649
+ * hence accepts both strings and numbers, and converts numbers to strings.
650
+ *
651
+ * It'll perform casting based on the following rules:
652
+ * - If the value is a number, it'll be converted to a string
653
+ * - If the value is a string, it'll be returned as-is - except blank strings, which will be converted to null
654
+ * - If the value is boolean, it'll return 'true' or 'false'
655
+ * - If the value is null or undefined, it'll return null
656
+ * - If the value is any other type, it'll return null
657
+ *
658
+ * Null handling: Blank strings will be converted to null. This is to reflect that in Excel a formula
659
+ * cannot return null. As a workaround, one often returns a blank string to represent null.
660
+ */
661
+ declare const excelStringNullableDecoder: z$1.ZodPipe<z$1.ZodTransform<string | null, unknown>, z$1.ZodNullable<z$1.ZodString>>;
662
+ /**
663
+ * A decoder that transforms Excel numbers to JS numbers, also handling strings and boolean. Will not parse any other type!
664
+ *
665
+ * It'll perform casting based on the following rules:
666
+ * - If the value is a number, it'll be returned as-is
667
+ * - If the value is a string, it'll try to parse it to a number. Blank strings will be converted to 0. Non-numeric strings will throw an error.
668
+ * - If the value is boolean, it'll return 1 or 0
669
+ * - If the value is any other type, it'll throw an error
670
+ *
671
+ */
672
+ declare const excelNumberStrictDecoder: z$1.ZodPipe<z$1.ZodUnion<readonly [z$1.ZodString, z$1.ZodNumber, z$1.ZodBoolean]>, z$1.ZodTransform<number, string | number | boolean>>;
673
+ /**
674
+ * A decoder that transforms Excel numbers to JS numbers, also handling strings, boolean and other types.
675
+ *
676
+ * It'll perform casting based on the following rules:
677
+ * - If the value is a number, it'll be returned as-is
678
+ * - If the value is a string, it'll try to parse it to a number. Blank strings and non-numerical strings will be converted to 0.
679
+ * - If the value is boolean, it'll return 1 or 0
680
+ * - If the value is any other type, it'll return 0
681
+ *
682
+ * Null handling: Null values/blank cells will be converted to blank strings.
683
+ */
684
+ declare const excelNumberDecoder: z$1.ZodPipe<z$1.ZodTransform<number, unknown>, z$1.ZodNumber>;
685
+ /**
686
+ * A decoder that transforms Excel numbers to JS numbers, also handling strings, boolean and other types.
687
+
688
+ * It'll perform casting based on the following rules:
689
+ * - If the value is a number, it'll be returned as-is
690
+ * - If the value is a string, it'll try to parse it to a number. Non-numerical and blank strings will be converted to null
691
+ * - If the value is boolean, it'll return 1 or 0
692
+ * - If the value is any other type, it'll return null
693
+ *
694
+ * Null handling: Blank strings will be converted to null. This is to reflect that in Excel a formula
695
+ * cannot return null. As a workaround, one often returns a blank string to represent null.
696
+ */
697
+ declare const excelNumberNullableDecoder: z$1.ZodPipe<z$1.ZodTransform<number | null, any>, z$1.ZodNullable<z$1.ZodNumber>>;
698
+ /**
699
+ * A decoder that transforms Excel numbers to JS integers, also handling strings and boolean. Other types will throw an error.
700
+ *
701
+ * If the number is not an integer, an error will be thrown.
702
+ */
703
+ declare const excelIntStrictDecoder: z$1.ZodPipe<z$1.ZodPipe<z$1.ZodUnion<readonly [z$1.ZodString, z$1.ZodNumber, z$1.ZodBoolean]>, z$1.ZodTransform<number, string | number | boolean>>, z$1.ZodTransform<number, number>>;
704
+ /**
705
+ * A decoder that transforms Excel numbers to JS integers, also handling strings and boolean. Other types will be converted to 0.
706
+ *
707
+ * If the number is not an integer, an error will be thrown.
708
+ */
709
+ declare const excelIntDecoder: z$1.ZodPipe<z$1.ZodPipe<z$1.ZodTransform<number, unknown>, z$1.ZodNumber>, z$1.ZodTransform<number, number>>;
710
+ /**
711
+ * A decoder that transforms Excel numbers to JS integers, also handling strings and boolean. Other types will be converted to null.
712
+ *
713
+ * If the number is not an integer, an error will be thrown.
714
+ */
715
+ declare const excelIntNullableDecoder: z$1.ZodPipe<z$1.ZodPipe<z$1.ZodTransform<number | null, any>, z$1.ZodNullable<z$1.ZodNumber>>, z$1.ZodTransform<number | null, number | null>>;
716
+ /**
717
+ * A decoder that transforms Excel numbers to JS BigInts, also handling strings and boolean. Other types will throw an error.
718
+ *
719
+ * If the number is not a (big) integer, an error will be thrown.
720
+ */
721
+ declare const excelBigIntStrictDecoder: z$1.ZodPipe<z$1.ZodPipe<z$1.ZodUnion<readonly [z$1.ZodString, z$1.ZodNumber, z$1.ZodBoolean]>, z$1.ZodTransform<number, string | number | boolean>>, z$1.ZodTransform<bigint, number>>;
722
+ /**
723
+ * A decoder that transforms Excel numbers to JS BigInts, also handling strings and boolean. Other types will be converted to 0.
724
+ *
725
+ * If the number is not a (big) integer, an error will be thrown.
726
+ */
727
+ declare const excelBigIntDecoder: z$1.ZodPipe<z$1.ZodPipe<z$1.ZodTransform<number, unknown>, z$1.ZodNumber>, z$1.ZodTransform<bigint, number>>;
728
+ /**
729
+ * A decoder that transforms Excel numbers to JS BigInts, also handling strings and boolean. Other types will be converted to null.
730
+ *
731
+ * If the number is not a (big) integer, an error will be thrown.
732
+ */
733
+ declare const excelBigIntNullableDecoder: z$1.ZodPipe<z$1.ZodPipe<z$1.ZodTransform<number | null, any>, z$1.ZodNullable<z$1.ZodNumber>>, z$1.ZodTransform<bigint | null, number | null>>;
734
+ /**
735
+ * A decoder that transforms Excel booleans to JS booleans, also handling numbers and strings.
736
+ *
737
+ * It'll perform casting based on the following rules:
738
+ * - If the value is a number, it'll return true if it's not 0
739
+ * - If the value is a string, it'll return true if it's 'true' or '1', false if it's 'false' or '0', and throw an error otherwise
740
+ * - If the value is boolean, it'll return it as-is
741
+ * - If the value is any other type, it'll throw an error
742
+ */
743
+ declare const excelBooleanStrictDecoder: z$1.ZodPipe<z$1.ZodUnion<readonly [z$1.ZodBoolean, z$1.ZodNumber, z$1.ZodString]>, z$1.ZodTransform<boolean, string | number | boolean>>;
744
+ /**
745
+ * A decoder that transforms Excel booleans to JS booleans, also handling numbers and strings.
746
+ *
747
+ * It'll perform casting based on the following rules:
748
+ * - If the value is a number, it'll return true if it's not 0
749
+ * - If the value is a string, it'll return true if it's 'true' or '1', false otherwise
750
+ * - If the value is boolean, it'll return it as-is
751
+ * - If the value is any other type, it'll return false
752
+ */
753
+ declare const excelBooleanDecoder: z$1.ZodPipe<z$1.ZodTransform<boolean, unknown>, z$1.ZodBoolean>;
754
+ /**
755
+ * A decoder that transforms Excel booleans to JS booleans, also handling numbers and strings.
756
+ *
757
+ * It'll perform casting based on the following rules:
758
+ * - If the value is a number, it'll return true if it's not 0
759
+ * - If the value is a string, it'll return true if it's 'true' or '1', false if it's 'false' or '0', and null otherwise
760
+ * - If the value is boolean, it'll return it as-is
761
+ * - If the value is any other type, it'll return null
762
+ */
763
+ declare const excelBooleanNullableDecoder: z$1.ZodPipe<z$1.ZodTransform<boolean | null, any>, z$1.ZodNullable<z$1.ZodBoolean>>;
764
+ /**
765
+ * A decoder that transforms Excel dates to JS Dates
766
+ */
767
+ declare const excelDateDecoder: z$1.ZodPipe<z$1.ZodUnion<readonly [z$1.ZodDate, z$1.ZodNumber, z$1.ZodString]>, z$1.ZodTransform<Date, string | number | Date>>;
768
+ /**
769
+ * A decoder that transforms nullable Excel dates to JS Dates
770
+ */
771
+ declare const excelDateNullableDecoder: z$1.ZodPipe<z$1.ZodTransform<Date | null, unknown>, z$1.ZodNullable<z$1.ZodDate>>;
772
+
773
+ //#endregion
774
+ export { CapitalizedKeys, ColorFn, CompareFn, Conjugated, Debrand, DeepPartial, DefaultMap as DefaultMap$1, Dictionary, Direction, Exact, ExhaustiveSwitchCheck as ExhaustiveSwitchCheck$1, Getter, NestedMap as NestedMap$1, NonEmptyArray, Optional, Page, Prettify, Result as Result$1, SerializedResult, Transformer, TypedError, TypedMapping as TypedMapping$1, UncapitalizeObjectKeys, UncapitalizedKeys, UnionOmit, UnionPick, XOR, addAndSort as addAndSort$1, assertArray as assertArray$1, assertType as assertType$1, blue as blue$1, bold as bold$1, booleanCode as booleanCode$1, capitalize as capitalize$1, capitalizeKeys as capitalizeKeys$1, commentLines as commentLines$1, compare as compare$1, compareBooleans as compareBooleans$1, compareDates as compareDates$1, compareFields as compareFields$1, compareNumbers as compareNumbers$1, compareStrings as compareStrings$1, compareValues as compareValues$1, conjugateNames as conjugateNames$1, cyan as cyan$1, dictGetAndAssert as dictGetAndAssert$1, ensureUnique as ensureUnique$1, equals as equals$1, err as err$1, excelBigIntDecoder as excelBigIntDecoder$1, excelBigIntNullableDecoder as excelBigIntNullableDecoder$1, excelBigIntStrictDecoder as excelBigIntStrictDecoder$1, excelBooleanDecoder as excelBooleanDecoder$1, excelBooleanNullableDecoder as excelBooleanNullableDecoder$1, excelBooleanStrictDecoder as excelBooleanStrictDecoder$1, excelDateDecoder as excelDateDecoder$1, excelDateNullableDecoder as excelDateNullableDecoder$1, excelIntDecoder as excelIntDecoder$1, excelIntNullableDecoder as excelIntNullableDecoder$1, excelIntStrictDecoder as excelIntStrictDecoder$1, excelNumberDecoder as excelNumberDecoder$1, excelNumberNullableDecoder as excelNumberNullableDecoder$1, excelNumberStrictDecoder as excelNumberStrictDecoder$1, excelStringDecoder as excelStringDecoder$1, excelStringNullableDecoder as excelStringNullableDecoder$1, excelStringStrictDecoder as excelStringStrictDecoder$1, filterDict as filterDict$1, filterMap as filterMap$1, format as format$1, generateRandomAlphanumericString as generateRandomAlphanumericString$1, gray as gray$1, green as green$1, groupBy as groupBy$1, groupByCurried as groupByCurried$1, groupByToDict as groupByToDict$1, groupByToMap as groupByToMap$1, idToDict as idToDict$1, inverse as inverse$1, isCamelCase as isCamelCase$1, isDate as isDate$1, isKebabCase as isKebabCase$1, isPascalCase as isPascalCase$1, isPlural as isPlural$1, isSlug as isSlug$1, isSnakeCase as isSnakeCase$1, italic as italic$1, keyGetter as keyGetter$1, lowerFirst as lowerFirst$1, mapDict as mapDict$1, mapGetAndAssert as mapGetAndAssert$1, mapLimit as mapLimit$1, mapMap as mapMap$1, mapMapKeyValues as mapMapKeyValues$1, mapMapKeys as mapMapKeys$1, mapMapValues as mapMapValues$1, mapToDict as mapToDict$1, ok as ok$1, omit as omit$1, pipeZodTransformers as pipeZodTransformers$1, pluralize as pluralize$1, randomInt as randomInt$1, red as red$1, removeSecrets as removeSecrets$1, removeUndefinedProperties as removeUndefinedProperties$1, setDirection as setDirection$1, slice as slice$1, slugify as slugify$1, sort as sort$1, timeStamp as timeStamp$1, toCamelCase as toCamelCase$1, toDict as toDict$1, toExcelColumnName as toExcelColumnName$1, toExcelTableName as toExcelTableName$1, toHumanReadable as toHumanReadable$1, toKebabCase as toKebabCase$1, toPascalCase as toPascalCase$1, toSnakeCase as toSnakeCase$1, uncapitalize as uncapitalize$1, uncapitalizeKeys as uncapitalizeKeys$1, underline as underline$1, unionErrorMessage as unionErrorMessage$1, uniq as uniq$1, upperFirst as upperFirst$1, yellow as yellow$1 };
775
+ //# sourceMappingURL=zod-excel.decoders-CtmUu_Yj.d.ts.map