@postxl/utils 0.1.8

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 (57) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +3 -0
  3. package/dist/DefaultMap.d.ts +11 -0
  4. package/dist/DefaultMap.js +26 -0
  5. package/dist/NestedMap.d.ts +16 -0
  6. package/dist/NestedMap.js +73 -0
  7. package/dist/TypedMapping.d.ts +26 -0
  8. package/dist/TypedMapping.js +33 -0
  9. package/dist/array.d.ts +6 -0
  10. package/dist/array.js +20 -0
  11. package/dist/async.d.ts +3 -0
  12. package/dist/async.js +40 -0
  13. package/dist/buffer.d.ts +4 -0
  14. package/dist/buffer.js +15 -0
  15. package/dist/check-port.d.ts +4 -0
  16. package/dist/check-port.js +27 -0
  17. package/dist/datetime.d.ts +4 -0
  18. package/dist/datetime.js +15 -0
  19. package/dist/dictionary.d.ts +8 -0
  20. package/dist/dictionary.js +44 -0
  21. package/dist/format.d.ts +1 -0
  22. package/dist/format.js +6 -0
  23. package/dist/group-by.d.ts +8 -0
  24. package/dist/group-by.js +65 -0
  25. package/dist/index.d.ts +25 -0
  26. package/dist/index.js +41 -0
  27. package/dist/is-object.d.ts +12 -0
  28. package/dist/is-object.js +24 -0
  29. package/dist/map.d.ts +22 -0
  30. package/dist/map.js +75 -0
  31. package/dist/omit.d.ts +4 -0
  32. package/dist/omit.js +10 -0
  33. package/dist/pagination.d.ts +6 -0
  34. package/dist/pagination.js +13 -0
  35. package/dist/random.d.ts +4 -0
  36. package/dist/random.js +16 -0
  37. package/dist/remove-secrets.d.ts +11 -0
  38. package/dist/remove-secrets.js +61 -0
  39. package/dist/remove-undefined.d.ts +9 -0
  40. package/dist/remove-undefined.js +21 -0
  41. package/dist/result.d.ts +24 -0
  42. package/dist/result.js +49 -0
  43. package/dist/sort.d.ts +17 -0
  44. package/dist/sort.js +63 -0
  45. package/dist/string-colors.d.ts +44 -0
  46. package/dist/string-colors.js +72 -0
  47. package/dist/string.d.ts +115 -0
  48. package/dist/string.js +322 -0
  49. package/dist/types.d.ts +78 -0
  50. package/dist/types.js +38 -0
  51. package/dist/uniq.d.ts +1 -0
  52. package/dist/uniq.js +15 -0
  53. package/dist/zod-excel.decoders.d.ts +151 -0
  54. package/dist/zod-excel.decoders.js +397 -0
  55. package/dist/zod.d.ts +8 -0
  56. package/dist/zod.js +17 -0
  57. package/package.json +33 -0
package/dist/map.js ADDED
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapMap = mapMap;
4
+ exports.mapMapValues = mapMapValues;
5
+ exports.mapMapKeyValues = mapMapKeyValues;
6
+ exports.mapMapKeys = mapMapKeys;
7
+ exports.filterMap = filterMap;
8
+ exports.mapGetAndAssert = mapGetAndAssert;
9
+ exports.mapToDict = mapToDict;
10
+ function mapMap(map, predicate) {
11
+ const result = new Map();
12
+ for (const [key, value] of map.entries()) {
13
+ result.set(key, predicate(value, key));
14
+ }
15
+ return result;
16
+ }
17
+ function mapMapValues(map, predicate) {
18
+ const result = [];
19
+ for (const [key, value] of map.entries()) {
20
+ result.push(predicate(value, key));
21
+ }
22
+ return result;
23
+ }
24
+ /**
25
+ *
26
+ */
27
+ function mapMapKeyValues(map, keyPredicate, valuePredicate) {
28
+ const result = new Map();
29
+ for (const [key, value] of map.entries()) {
30
+ result.set(keyPredicate(key, value), valuePredicate(value, key));
31
+ }
32
+ return result;
33
+ }
34
+ /**
35
+ * Maps keys of a map.
36
+ */
37
+ function mapMapKeys(map, keyPredicate) {
38
+ const result = new Map();
39
+ for (const [key, value] of map.entries()) {
40
+ result.set(keyPredicate(key, value), value);
41
+ }
42
+ return result;
43
+ }
44
+ /**
45
+ * Filters values from a map.
46
+ */
47
+ function filterMap(map, predicate) {
48
+ const result = new Map();
49
+ for (const [key, value] of map.entries()) {
50
+ if (predicate(value, key)) {
51
+ result.set(key, value);
52
+ }
53
+ }
54
+ return result;
55
+ }
56
+ /**
57
+ * Gets a value from a map and asserts that it exists.
58
+ */
59
+ function mapGetAndAssert(map, key) {
60
+ const value = map.get(key);
61
+ if (!value) {
62
+ throw new Error(`Key ${JSON.stringify(key)} not found`);
63
+ }
64
+ return value;
65
+ }
66
+ /**
67
+ * Converts a map to a dictionary.
68
+ */
69
+ function mapToDict(map) {
70
+ const result = {};
71
+ for (const [key, value] of map.entries()) {
72
+ result[key] = value;
73
+ }
74
+ return result;
75
+ }
package/dist/omit.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Omits a key from an object
3
+ */
4
+ export declare function omit<T extends Record<string, unknown>>(obj: T, key: string): Omit<T, typeof key>;
package/dist/omit.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.omit = omit;
4
+ /**
5
+ * Omits a key from an object
6
+ */
7
+ function omit(obj, key) {
8
+ const { [key]: _, ...rest } = obj;
9
+ return rest;
10
+ }
@@ -0,0 +1,6 @@
1
+ export type Page<Item> = {
2
+ total: number;
3
+ offset: number;
4
+ items: Item[];
5
+ };
6
+ export declare const slice: <Item>(items: Item[], skip?: number, take?: number) => Page<Item>;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.slice = void 0;
4
+ const slice = (items, skip, take) => {
5
+ const start = skip ?? 0;
6
+ const end = take ? start + take : undefined;
7
+ return {
8
+ total: items.length,
9
+ offset: start,
10
+ items: items.slice(start, end),
11
+ };
12
+ };
13
+ exports.slice = slice;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Returns a randomly generated alphanumeric string.
3
+ */
4
+ export declare const generateRandomAlphanumericString: (length: number) => string;
package/dist/random.js ADDED
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateRandomAlphanumericString = void 0;
4
+ const crypto_1 = require("crypto");
5
+ const CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
6
+ /**
7
+ * Returns a randomly generated alphanumeric string.
8
+ */
9
+ const generateRandomAlphanumericString = (length) => {
10
+ let result = '';
11
+ for (let i = 0; i < length; i++) {
12
+ result += CHARS[(0, crypto_1.randomInt)(CHARS.length)];
13
+ }
14
+ return result;
15
+ };
16
+ exports.generateRandomAlphanumericString = generateRandomAlphanumericString;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Removes secrets from the given configuration object.
3
+ *
4
+ * Recursively checks all properties of the object for keys that end with
5
+ * `key`, `secret`, `password`, `token` and replaces them with '***'.
6
+ *
7
+ * Also checks for keys the end with `connection` or `connectionString` and
8
+ * replaces the connection string with the same string but with the password
9
+ * replaced with '***'.
10
+ */
11
+ export declare function removeSecrets<T extends Record<string, unknown>>(config: T): T;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeSecrets = removeSecrets;
4
+ const is_object_1 = require("./is-object");
5
+ /**
6
+ * Removes secrets from the given configuration object.
7
+ *
8
+ * Recursively checks all properties of the object for keys that end with
9
+ * `key`, `secret`, `password`, `token` and replaces them with '***'.
10
+ *
11
+ * Also checks for keys the end with `connection` or `connectionString` and
12
+ * replaces the connection string with the same string but with the password
13
+ * replaced with '***'.
14
+ */
15
+ function removeSecrets(config) {
16
+ const newConfig = {};
17
+ for (const [key, value] of Object.entries(config)) {
18
+ newConfig[key] = processValue(key, value);
19
+ }
20
+ return newConfig;
21
+ }
22
+ function processValue(key, value) {
23
+ if (typeof value === 'string') {
24
+ return processString(key, value);
25
+ }
26
+ else if (Array.isArray(value)) {
27
+ return value.map((item) => removeSecrets(item));
28
+ }
29
+ else if (typeof value === 'object' && (0, is_object_1.isPlainObject)(value)) {
30
+ return removeSecrets(value);
31
+ }
32
+ return value;
33
+ }
34
+ function processString(key, value) {
35
+ if (key.endsWith('key') || key.endsWith('secret') || key.endsWith('password') || key.endsWith('token')) {
36
+ return hidePassword(value);
37
+ }
38
+ else if (key.endsWith('connection') || key.endsWith('connectionString')) {
39
+ return hidePasswordInConnectionString(value);
40
+ }
41
+ else {
42
+ return value;
43
+ }
44
+ }
45
+ function hidePasswordInConnectionString(connection) {
46
+ return (connection
47
+ // e.g. postgresql://user:password@host
48
+ .replace(/^(.*):\/\/(.*):(.*)@(.*)$/, '$1://$2:***@$4') //NOSONAR - this is only used to parse environment variables, so no risk of external DOS attacks
49
+ // e.g. user:password@host
50
+ .replace(/^(.*):(.*)@(.*)$/, '$1:***@$3') //NOSONAR - this is only used to parse environment variables, so no risk of external DOS attacks
51
+ );
52
+ }
53
+ function hidePassword(password) {
54
+ if (password === '') {
55
+ return 'nothing provided!';
56
+ }
57
+ if (password === 'secret') {
58
+ return 'default provided!';
59
+ }
60
+ return '***';
61
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Removes all undefined properties from an object.
3
+ *
4
+ * NOTE: This is useful when using the `Partial<T>` type modifier in combination with the spread operator to prevent
5
+ * overriding with undefined values.
6
+ */
7
+ export declare function removeUndefinedProperties<T extends Record<string, unknown>>(obj: T): {
8
+ [K in keyof T]: T[K] extends undefined ? never : T[K];
9
+ };
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeUndefinedProperties = removeUndefinedProperties;
4
+ /**
5
+ * Removes all undefined properties from an object.
6
+ *
7
+ * NOTE: This is useful when using the `Partial<T>` type modifier in combination with the spread operator to prevent
8
+ * overriding with undefined values.
9
+ */
10
+ function removeUndefinedProperties(obj) {
11
+ const newObj = {};
12
+ for (const key in obj) {
13
+ const value = obj[key];
14
+ if (value !== undefined) {
15
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
16
+ // @ts-expect-error
17
+ newObj[key] = value;
18
+ }
19
+ }
20
+ return newObj;
21
+ }
@@ -0,0 +1,24 @@
1
+ export declare const OK = "OK";
2
+ export declare const ERR = "ERR";
3
+ export type Ok<Value> = {
4
+ type: typeof OK;
5
+ value: Value;
6
+ };
7
+ export type Err<ErrorType> = {
8
+ type: typeof ERR;
9
+ error: ErrorType;
10
+ };
11
+ export type Result<Value, ErrorType = TypedError<'genericError'>> = Ok<Value> | Err<ErrorType>;
12
+ export declare const ok: <Value, ErrorType>(value: Value) => Result<Value, ErrorType>;
13
+ export declare const err: <Value, ErrorType>(error: ErrorType) => Result<Value, ErrorType>;
14
+ export declare const result: <Value, ErrorType>(getValue: () => Promise<Value>, errHandler: (e: Error) => ErrorType) => Promise<Result<Value, ErrorType>>;
15
+ export declare const isOk: <Value, ErrorType>(r: Result<Value, ErrorType>) => r is Ok<Value>;
16
+ export declare const isErr: <Value, ErrorType>(r: Result<Value, ErrorType>) => r is Err<ErrorType>;
17
+ export declare const unwrap: <Value, ErrorType>(r: Result<Value, ErrorType>) => Value;
18
+ export declare const withDefault: <Value, ErrorType>(r: Result<Value, ErrorType>, defaultValue: Value) => Value;
19
+ export declare const map: <FROMValue, TOValue, Error>(func: (t: FROMValue) => TOValue, r: Result<FROMValue, Error>) => Result<TOValue, Error>;
20
+ export type TypedError<T extends string> = {
21
+ type: T;
22
+ message: string;
23
+ error: Error;
24
+ };
package/dist/result.js ADDED
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.map = exports.withDefault = exports.unwrap = exports.isErr = exports.isOk = exports.result = exports.err = exports.ok = exports.ERR = exports.OK = void 0;
4
+ exports.OK = 'OK';
5
+ exports.ERR = 'ERR';
6
+ const ok = (value) => ({
7
+ type: exports.OK,
8
+ value,
9
+ });
10
+ exports.ok = ok;
11
+ const err = (error) => ({
12
+ type: exports.ERR,
13
+ error,
14
+ });
15
+ exports.err = err;
16
+ const result = async (getValue, errHandler) => {
17
+ try {
18
+ return (0, exports.ok)(await getValue());
19
+ }
20
+ catch (e) {
21
+ return (0, exports.err)(errHandler(e));
22
+ }
23
+ };
24
+ exports.result = result;
25
+ const isOk = (r) => r.type === exports.OK;
26
+ exports.isOk = isOk;
27
+ const isErr = (r) => r.type === exports.ERR;
28
+ exports.isErr = isErr;
29
+ const unwrap = (r) => {
30
+ if ((0, exports.isErr)(r)) {
31
+ throw new Error(typeof r.error === 'string' ? r.error : JSON.stringify(r.error));
32
+ }
33
+ return r.value;
34
+ };
35
+ exports.unwrap = unwrap;
36
+ const withDefault = (r, defaultValue) => {
37
+ if ((0, exports.isErr)(r)) {
38
+ return defaultValue;
39
+ }
40
+ return r.value;
41
+ };
42
+ exports.withDefault = withDefault;
43
+ const map = (func, r) => {
44
+ if (r.type === exports.ERR) {
45
+ return r;
46
+ }
47
+ return (0, exports.ok)(func(r.value));
48
+ };
49
+ exports.map = map;
package/dist/sort.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ export type CompareFn<T> = (a: T, b: T) => number;
2
+ export type Direction = 'asc' | 'desc';
3
+ export declare const sort: <Item>(items: Item[], dir?: Direction, compareFn?: CompareFn<Item>) => Item[];
4
+ /**
5
+ * Compare fields of an object.
6
+ */
7
+ export declare const compareFields: <T>(key: keyof T) => CompareFn<T>;
8
+ export type Getter<T> = (data: T) => unknown;
9
+ export declare const compare: <T>(getter: Getter<T>) => CompareFn<T>;
10
+ export declare const keyGetter: <T>(key: keyof T) => Getter<T>;
11
+ export declare const compareValues: CompareFn<unknown>;
12
+ export declare const compareDates: CompareFn<Date>;
13
+ export declare const compareStrings: CompareFn<string>;
14
+ export declare const compareNumbers: CompareFn<number>;
15
+ export declare const compareBooleans: CompareFn<boolean>;
16
+ export declare const booleanCode: (bool: boolean) => number;
17
+ export declare const setDirection: <Item>(items: Item[], dir: Direction) => Item[];
package/dist/sort.js ADDED
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setDirection = exports.booleanCode = exports.compareBooleans = exports.compareNumbers = exports.compareStrings = exports.compareDates = exports.compareValues = exports.keyGetter = exports.compare = exports.compareFields = exports.sort = void 0;
4
+ const sort = (items, dir = 'asc', compareFn = exports.compareValues) => (0, exports.setDirection)(items.toSorted(compareFn), dir);
5
+ exports.sort = sort;
6
+ /**
7
+ * Compare fields of an object.
8
+ */
9
+ const compareFields = (key) => {
10
+ return (a, b) => (0, exports.compareValues)(a[key], b[key]);
11
+ };
12
+ exports.compareFields = compareFields;
13
+ const compare = (getter) => {
14
+ return (a, b) => (0, exports.compareValues)(getter(a), getter(b));
15
+ };
16
+ exports.compare = compare;
17
+ const keyGetter = (key) => {
18
+ return (data) => data[key];
19
+ };
20
+ exports.keyGetter = keyGetter;
21
+ const compareValues = (a, b) => {
22
+ switch (true) {
23
+ // In case one item is undefined or null and the other is not, we place the non-null item first.
24
+ case (a === undefined || a === null) && b !== undefined && b !== null:
25
+ return 1;
26
+ case (b === undefined || b === null) && a !== undefined && a !== null:
27
+ return -1;
28
+ case (a === undefined || a === null) && (b === undefined || b === null):
29
+ return 0;
30
+ case a instanceof Date && b instanceof Date:
31
+ return (0, exports.compareDates)(a, b);
32
+ case typeof a === 'string' && typeof b === 'string':
33
+ return (0, exports.compareStrings)(a, b);
34
+ case typeof a === 'number' && typeof b === 'number':
35
+ return (0, exports.compareNumbers)(a, b);
36
+ case typeof a === 'boolean' && typeof b === 'boolean':
37
+ return (0, exports.compareBooleans)(a, b);
38
+ default:
39
+ return 0;
40
+ }
41
+ };
42
+ exports.compareValues = compareValues;
43
+ const compareDates = (a, b) => (0, exports.compareStrings)(a.toISOString(), b.toISOString());
44
+ exports.compareDates = compareDates;
45
+ const compareStrings = (a, b) => {
46
+ const aLower = a.trim().toLowerCase();
47
+ const bLower = b.trim().toLowerCase();
48
+ if (aLower === bLower) {
49
+ return 0;
50
+ }
51
+ return aLower > bLower ? 1 : -1;
52
+ };
53
+ exports.compareStrings = compareStrings;
54
+ const compareNumbers = (a, b) => a - b;
55
+ exports.compareNumbers = compareNumbers;
56
+ const compareBooleans = (a, b) => (0, exports.booleanCode)(a) - (0, exports.booleanCode)(b);
57
+ exports.compareBooleans = compareBooleans;
58
+ const booleanCode = (bool) => (bool ? 1 : 0);
59
+ exports.booleanCode = booleanCode;
60
+ const setDirection = (items, dir) => {
61
+ return dir === 'desc' ? items.toReversed() : items;
62
+ };
63
+ exports.setDirection = setDirection;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * A function that returns a string with a specific color.
3
+ */
4
+ export type ColorFn = (input: string) => string;
5
+ /**
6
+ * Colors a string in red color (using ANSI escape codes).
7
+ */
8
+ export declare function red(input: string): string;
9
+ /**
10
+ * Colors a string in green color (using ANSI escape codes).
11
+ */
12
+ export declare function green(input: string): string;
13
+ /**
14
+ * Colors a string in yellow color (using ANSI escape codes).
15
+ */
16
+ export declare function yellow(input: string): string;
17
+ /**
18
+ * Colors a string in blue color (using ANSI escape codes).
19
+ */
20
+ export declare function blue(input: string): string;
21
+ /**
22
+ * Colors a string in cyan color (using ANSI escape codes).
23
+ */
24
+ export declare function cyan(input: string): string;
25
+ /**
26
+ * Colors a string in gray color (using ANSI escape codes).
27
+ */
28
+ export declare function gray(input: string): string;
29
+ /**
30
+ * Colors a string in bold color (using ANSI escape codes).
31
+ */
32
+ export declare function bold(input: string): string;
33
+ /**
34
+ * Colors a string in underline color (using ANSI escape codes).
35
+ */
36
+ export declare function underline(input: string): string;
37
+ /**
38
+ * Colors a string in italic color (using ANSI escape codes).
39
+ */
40
+ export declare function italic(input: string): string;
41
+ /**
42
+ * Inverts the color of a string (using ANSI escape codes).
43
+ */
44
+ export declare function inverse(input: string): string;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.red = red;
4
+ exports.green = green;
5
+ exports.yellow = yellow;
6
+ exports.blue = blue;
7
+ exports.cyan = cyan;
8
+ exports.gray = gray;
9
+ exports.bold = bold;
10
+ exports.underline = underline;
11
+ exports.italic = italic;
12
+ exports.inverse = inverse;
13
+ /**
14
+ * Colors a string in red color (using ANSI escape codes).
15
+ */
16
+ function red(input) {
17
+ return `\u001b[31m${input}\u001b[39m`;
18
+ }
19
+ /**
20
+ * Colors a string in green color (using ANSI escape codes).
21
+ */
22
+ function green(input) {
23
+ return `\u001b[32m${input}\u001b[39m`;
24
+ }
25
+ /**
26
+ * Colors a string in yellow color (using ANSI escape codes).
27
+ */
28
+ function yellow(input) {
29
+ return `\u001b[33m${input}\u001b[39m`;
30
+ }
31
+ /**
32
+ * Colors a string in blue color (using ANSI escape codes).
33
+ */
34
+ function blue(input) {
35
+ return `\u001b[34m${input}\u001b[39m`;
36
+ }
37
+ /**
38
+ * Colors a string in cyan color (using ANSI escape codes).
39
+ */
40
+ function cyan(input) {
41
+ return `\u001b[36m${input}\u001b[39m`;
42
+ }
43
+ /**
44
+ * Colors a string in gray color (using ANSI escape codes).
45
+ */
46
+ function gray(input) {
47
+ return `\u001b[90m${input}\u001b[39m`;
48
+ }
49
+ /**
50
+ * Colors a string in bold color (using ANSI escape codes).
51
+ */
52
+ function bold(input) {
53
+ return `\u001b[1m${input}\u001b[22m`;
54
+ }
55
+ /**
56
+ * Colors a string in underline color (using ANSI escape codes).
57
+ */
58
+ function underline(input) {
59
+ return `\u001b[4m${input}\u001b[24m`;
60
+ }
61
+ /**
62
+ * Colors a string in italic color (using ANSI escape codes).
63
+ */
64
+ function italic(input) {
65
+ return `\u001b[3m${input}\u001b[23m`;
66
+ }
67
+ /**
68
+ * Inverts the color of a string (using ANSI escape codes).
69
+ */
70
+ function inverse(input) {
71
+ return `\u001b[7m${input}\u001b[27m`;
72
+ }
@@ -0,0 +1,115 @@
1
+ export declare function upperFirst(s: string): string;
2
+ export declare function lowerFirst(s: string): string;
3
+ /**
4
+ * Returns a pluralized version of the given string based on the count.
5
+ */
6
+ export declare function pluralize(s: string, count?: number): string;
7
+ /**
8
+ * Returns true if the given string is already pluralized.
9
+ */
10
+ export declare function isPlural(s: string): boolean;
11
+ /**
12
+ * Type modifier that converts all keys of an object to capitalized versions.
13
+ */
14
+ export type CapitalizedKeys<T extends Record<string, unknown>> = {
15
+ [K in keyof T as CapitalizeFirstLetter<string & K>]: T[K];
16
+ };
17
+ /**
18
+ * Type modifier that converts the first letter of a string to a capital letter.
19
+ */
20
+ type CapitalizeFirstLetter<S extends string> = `${Capitalize<Extract<S, string>>}`;
21
+ /**
22
+ * Converts all keys of an object to capitalized versions in a type-safe way.
23
+ */
24
+ export declare function capitalizeKeys<T extends Record<string, unknown>>(obj: T): CapitalizedKeys<T>;
25
+ /**
26
+ * Type modifier that converts all keys of an object to uncapitalized versions.
27
+ */
28
+ export type UncapitalizedKeys<T extends Record<string, unknown>> = {
29
+ [K in keyof T as UncapitalizeFirstLetter<string & K>]: T[K];
30
+ };
31
+ /**
32
+ * Type modifier that converts the first letter of a string to an uncapitalized letter.
33
+ */
34
+ type UncapitalizeFirstLetter<S extends string> = `${Uncapitalize<Extract<S, string>>}`;
35
+ /**
36
+ * Converts all keys of an object to uncapitalized versions in a type-safe way.
37
+ */
38
+ export declare function uncapitalizeKeys<T extends Record<string, unknown>>(obj: T): UncapitalizedKeys<T>;
39
+ /**
40
+ * Returns the same string with a lowercase first letter.
41
+ */
42
+ export declare function uncapitalize(str: string): string;
43
+ /**
44
+ * Returns the same string with an uppercase first letter.
45
+ */
46
+ export declare function capitalize(str: string): string;
47
+ /**
48
+ * Returns the camelCase version of the given string.
49
+ *
50
+ * Camel case examples:
51
+ * `toCamelCase('hello world')` -> 'helloWorld',
52
+ * `toCamelCase('hello_world')` -> 'helloWorld',
53
+ * `toCamelCase('helloWorld')` -> 'helloWorld'
54
+ * `toCamelCase('HelloWorld')` -> 'helloWorld'
55
+ * `toCamelCase('hello_world')` -> 'helloWorld'
56
+ */
57
+ export declare function toCamelCase(str: string): string;
58
+ /**
59
+ * Validates if a string is in camelCase format
60
+ */
61
+ export declare function isCamelCase(str: string): boolean;
62
+ /**
63
+ * Returns the PascalCase version of the given string.
64
+ *
65
+ * Examples:
66
+ * `toPascalCase('hello world')` -> 'HelloWorld'
67
+ * `toPascalCase('hello_world')` -> 'HelloWorld'
68
+ * `toPascalCase('helloWorld')` -> 'HelloWorld'
69
+ * `toPascalCase('Hello-World')` -> 'HelloWorld'
70
+ * `toPascalCase('HELLO_WORLD')` -> 'HelloWorld'
71
+ */
72
+ export declare function toPascalCase(str: string): string;
73
+ /**
74
+ * Validates if a string is in PascalCase format
75
+ */
76
+ export declare function isPascalCase(str: string): boolean;
77
+ /**
78
+ * Returns the snake_case version of the given string.
79
+ *
80
+ * Examples:
81
+ * `toSnakeCase('hello world')` -> 'hello_world'
82
+ * `toSnakeCase('helloWorld')` -> 'hello_world'
83
+ * `toSnakeCase('HelloWorld')` -> 'hello_world'
84
+ * `toSnakeCase('HELLO_WORLD')` -> 'hello_world'
85
+ */
86
+ export declare function toSnakeCase(str: string): string;
87
+ /**
88
+ * Validates if a string is in snake_case format
89
+ */
90
+ export declare function isSnakeCase(str: string): boolean;
91
+ /**
92
+ * Converts each line of a string to a commented line
93
+ */
94
+ export declare function commentLines(lines: string): string;
95
+ export declare function toHumanReadable(input: string): string;
96
+ export type Conjugated = {
97
+ PascalCase: string;
98
+ PascalCasePlural: string;
99
+ camelCase: string;
100
+ camelCasePlural: string;
101
+ snake_case: string;
102
+ snake_case_plural: string;
103
+ pluralized: string;
104
+ uncapitalizedPlural: string;
105
+ uncapitalized: string;
106
+ capitalized: string;
107
+ capitalizedPlural: string;
108
+ };
109
+ /**
110
+ * Provide all relevant conjugation of a name
111
+ */
112
+ export declare function conjugateNames(name: string): Conjugated;
113
+ export declare function slugify(str: string): string;
114
+ export declare function isSlug(str: string): boolean;
115
+ export {};