@codeleap/utils 6.3.0 → 6.8.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.
@@ -0,0 +1,33 @@
1
+ import { FunctionType } from '@codeleap/types';
2
+ type GetterFunction<T> = FunctionType<[T, number], string | number> | keyof T;
3
+ /**
4
+ * Indexes an array into an object keyed by a derived value.
5
+ *
6
+ * `keyAccessor` may be a property name string or a callback that returns a
7
+ * key. When omitted, array indices are used as keys. Duplicate keys silently
8
+ * overwrite earlier entries.
9
+ */
10
+ export declare function objectFromArray<T, Getter extends GetterFunction<T>>(arr: T[], keyAccessor?: Getter): Record<string, T>;
11
+ /**
12
+ * Returns a deduplicated copy of `array` where uniqueness is determined by
13
+ * the value returned from `getProperty`.
14
+ *
15
+ * When duplicates exist, the **last** occurrence wins because `objectFromArray`
16
+ * overwrites earlier entries with the same key.
17
+ */
18
+ export declare function uniqueArrayByProperty<T, G extends GetterFunction<T>>(array: T[], getProperty: G): T[];
19
+ /**
20
+ * Recursively flattens a nested array of arbitrary depth into a single-level array.
21
+ *
22
+ * Unlike `Array.prototype.flat(Infinity)`, this implementation does not rely on
23
+ * native flat support and works identically across all environments.
24
+ */
25
+ export declare function flatten<T extends unknown>(arr: T[]): T[];
26
+ /**
27
+ * Returns an inclusive integer array from `start` to `end`.
28
+ *
29
+ * Both bounds are included: `range(1, 3)` → `[1, 2, 3]`.
30
+ */
31
+ export declare function range(start: number, end: number): number[];
32
+ export {};
33
+ //# sourceMappingURL=array.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../src/array.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE9C,KAAK,cAAc,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC,CAAA;AAE7E;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,SAAS,cAAc,CAAC,CAAC,CAAC,EACjE,GAAG,EAAE,CAAC,EAAE,EACR,WAAW,CAAC,EAAE,MAAM,GACnB,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAiBnB;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,CAAC,SAAS,cAAc,CAAC,CAAC,CAAC,EAClE,KAAK,EAAE,CAAC,EAAE,EACV,WAAW,EAAE,CAAC,OAGf;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE,OAYlD;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,YAG/C"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Produces a full recursive clone of `value` without any external dependencies.
3
+ *
4
+ * Supported types: primitives (returned as-is), plain objects, arrays, `Date`,
5
+ * `Map`, `Set`, and `RegExp`. Class instances with prototype methods beyond
6
+ * these built-ins are cloned as plain objects — prototype chain is not preserved.
7
+ * Circular references will cause a stack overflow.
8
+ */
9
+ export declare function cloneDeep<T = any>(value: T): T;
10
+ //# sourceMappingURL=cloneDeep.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloneDeep.d.ts","sourceRoot":"","sources":["../src/cloneDeep.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CA0C9C"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Parses a 6-digit hex colour string (with or without leading `#`) into its
3
+ * `{ r, g, b }` components.
4
+ *
5
+ * Returns `null` for invalid or short (3-digit) hex values.
6
+ */
7
+ export declare function hexToRgb(hex: string): {
8
+ r: number;
9
+ g: number;
10
+ b: number;
11
+ } | null;
12
+ /**
13
+ * Lightens or darkens `color` by `percent` and optionally applies `opacity`,
14
+ * returning an `rgba(...)` string.
15
+ *
16
+ * - Positive `percent` → lighten; negative → darken (magnitude is used).
17
+ * - `opacity` must be in the `0–1` range (passed directly to tinycolor's `setAlpha`).
18
+ * - Results are memoised in a module-level cache keyed by the serialised parameters,
19
+ * so repeated calls with identical arguments are effectively free.
20
+ */
21
+ export declare function shadeColor(color: string, percent?: number, opacity?: number | null): string;
22
+ //# sourceMappingURL=colors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../src/colors.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM;;;;SASnC;AAID;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,SAAI,EAAE,OAAO,GAAE,MAAM,GAAG,IAAW,UA+BnF"}
package/dist/date.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Date helpers that normalise timezone-sensitive values before formatting.
3
+ *
4
+ * - `removeTimezoneAndFormat(date, format?)` — strips the time component from
5
+ * a `Date` or ISO string, anchors it to noon local time, then formats with
6
+ * dayjs. This prevents off-by-one-day errors that occur when UTC midnight
7
+ * falls on a different calendar day in the user's timezone. Returns `''` for
8
+ * falsy input.
9
+ */
10
+ export declare const dateUtils: {
11
+ removeTimezoneAndFormat: (date: any, format?: string) => string;
12
+ };
13
+ //# sourceMappingURL=date.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../src/date.ts"],"names":[],"mappings":"AAgBA;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS;oCAvBiB,GAAG;CAyBzC,CAAA"}
@@ -0,0 +1,23 @@
1
+ declare function number(min?: number, max?: number): number;
2
+ /**
3
+ * Lightweight in-house fixture-data generator with no external dependencies.
4
+ *
5
+ * Provided methods:
6
+ * - `firstName()` / `lastName()` — random entries from hard-coded name lists.
7
+ * - `name()` — space-joined first + last name.
8
+ * - `animal()` — random animal name.
9
+ * - `number(min?, max?)` — random integer in `[min, max]` (default 0–100).
10
+ *
11
+ * All selections use `Math.random`, so results are not reproducible across calls.
12
+ * Use this instead of heavy faker libraries in tests or seed scripts where the
13
+ * small vocabulary is sufficient.
14
+ */
15
+ export declare const faker: {
16
+ lastName: () => string;
17
+ firstName: () => string;
18
+ animal: () => string;
19
+ number: typeof number;
20
+ name: () => string;
21
+ };
22
+ export {};
23
+ //# sourceMappingURL=faker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"faker.d.ts","sourceRoot":"","sources":["../src/faker.ts"],"names":[],"mappings":"AAuBA,iBAAS,MAAM,CAAC,GAAG,GAAE,MAAU,EAAE,GAAG,GAAE,MAAY,UAEjD;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,KAAK;;;;;;CAMjB,CAAA"}
package/dist/file.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Splits a file system path into its directory, base name, and extension.
3
+ *
4
+ * Both `/` and `\` are treated as separators, so Windows and POSIX paths are
5
+ * handled uniformly. Files without an extension return an empty string for
6
+ * `extension`. The returned `path` is always joined with `/` regardless of the
7
+ * original separator.
8
+ */
9
+ export declare function parseFilePathData(path: string): {
10
+ path: string;
11
+ extension: string;
12
+ name: string;
13
+ };
14
+ //# sourceMappingURL=file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../src/file.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM;;;;EAoB7C"}
@@ -0,0 +1,12 @@
1
+ export * from './array';
2
+ export * from './colors';
3
+ export * from './misc';
4
+ export * from './object';
5
+ export * from './react';
6
+ export * from './file';
7
+ export * from './string';
8
+ export * from './faker';
9
+ export * from './cloneDeep';
10
+ export * from './locale';
11
+ export * from './date';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,QAAQ,CAAA;AACtB,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,QAAQ,CAAA;AACtB,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA;AACxB,cAAc,QAAQ,CAAA"}
@@ -0,0 +1,10 @@
1
+ import { AnyRecord } from '@codeleap/types';
2
+ /**
3
+ * Finds the closest matching key in `languageDictionary` for a given `locale`.
4
+ *
5
+ * Matching uses only the first two characters (the language subtag), so `'en-AU'`
6
+ * will match an `'en-US'` dictionary key. Returns `defaultLocale` when no
7
+ * partial match exists.
8
+ */
9
+ export declare function getSimilarLocale(locale: string, defaultLocale: string, languageDictionary: AnyRecord): string;
10
+ //# sourceMappingURL=locale.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locale.d.ts","sourceRoot":"","sources":["../src/locale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,kBAAkB,EAAE,SAAS,UAS9B"}
package/dist/misc.d.ts ADDED
@@ -0,0 +1,67 @@
1
+ import { StylesOf } from '@codeleap/types';
2
+ /**
3
+ * Converts a remote image URL into a file-upload-compatible object
4
+ * (`{ uri, name, type }`).
5
+ *
6
+ * The `type` is inferred from the URL's file extension. Returns `null` when
7
+ * `imagePath` is falsy, making it safe to pass directly to optional file-input APIs.
8
+ */
9
+ export declare function imagePathToFileObject(imagePath: string | null): {
10
+ uri: string;
11
+ name: string;
12
+ type: string;
13
+ } | null;
14
+ /**
15
+ * Maps the first character of `anyString` to a deterministic colour for use in
16
+ * avatar placeholders.
17
+ *
18
+ * Lookup is case-insensitive. Returns `'#999999'` for empty, undefined, or
19
+ * characters not in the `a–z` range.
20
+ */
21
+ export declare function matchInitialToColor(anyString?: string): string;
22
+ /** Returns a Promise that resolves after `ms` milliseconds. */
23
+ export declare function waitFor(ms: number): Promise<void>;
24
+ type ParseSourceUrlArg = {
25
+ source?: string;
26
+ src?: string;
27
+ };
28
+ /**
29
+ * Resolves a media URL from either a raw string or a `{ source?, src? }` object.
30
+ *
31
+ * - Paths starting with `/media/` are prefixed with `Settings.BaseURL`.
32
+ * - Absolute URLs are returned unchanged.
33
+ * - Empty/missing addresses fall back to a random `picsum.photos` placeholder.
34
+ * - Returns `null` for a falsy `args` argument.
35
+ */
36
+ export declare function parseSourceUrl(args: string, Settings?: any): string;
37
+ export declare function parseSourceUrl(args: ParseSourceUrlArg, Settings?: any): string | null;
38
+ /**
39
+ * Extracts style entries from a variant styles map whose keys begin with `match`,
40
+ * returning them as a new object with the prefix stripped and the first
41
+ * remaining character lowercased.
42
+ *
43
+ * Used internally by component style systems to pull out sub-part styles
44
+ * (e.g. `inputLabel`, `inputWrapper`) into their own namespaced objects.
45
+ */
46
+ export declare function getNestedStylesByKey<T extends StylesOf<any>>(match: string, variantStyles: T): Record<string, unknown>;
47
+ /**
48
+ * Heuristically detects whether the app has been React Fast Refreshed since
49
+ * initial launch.
50
+ *
51
+ * Compares the elapsed time since `Settings.Environment.InitTime` against a
52
+ * 1-second threshold. Fast Refresh typically completes well under 1 second from
53
+ * app start; anything longer suggests a subsequent refresh rather than cold boot.
54
+ * Returns `undefined` and logs a warning when `InitTime` is not set.
55
+ */
56
+ export declare function hasFastRefreshed(Settings: any): any;
57
+ /**
58
+ * Leading-edge throttle keyed by a `ref` identifier rather than by function reference.
59
+ *
60
+ * `func` is called immediately on the first invocation for a given `ref`; subsequent
61
+ * calls with the same `ref` are dropped until `delay` milliseconds have elapsed.
62
+ * Using a string/number `ref` allows multiple independent throttle timers to coexist
63
+ * in a single module without needing to hold separate timer handles.
64
+ */
65
+ export declare function throttle(func: () => void, ref: string | number, delay: number): void;
66
+ export {};
67
+ //# sourceMappingURL=misc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"misc.d.ts","sourceRoot":"","sources":["../src/misc.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAE1C;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;;;;SAc7D;AA+BD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,CAAC,EAAE,MAAM,UAGrD;AAED,+DAA+D;AAC/D,wBAAgB,OAAO,CAAC,EAAE,EAAE,MAAM,iBAMjC;AAED,KAAK,iBAAiB,GAAG;IACvB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,CAAC,EAAE,MAAM,CAAA;CACb,CAAA;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,GAAG,GAAG,MAAM,CAAA;AACpE,wBAAgB,cAAc,CAC5B,IAAI,EAAE,iBAAiB,EACvB,QAAQ,CAAC,EAAE,GAAG,GACb,MAAM,GAAG,IAAI,CAAA;AA0BhB;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,QAAQ,CAAC,GAAG,CAAC,EAAE,KAAK,EAAC,MAAM,EAAE,aAAa,EAAE,CAAC,2BAY3F;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,GAAG,OAU7C;AAID;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,IAAI,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,QAS7E"}
@@ -0,0 +1,115 @@
1
+ import { FunctionType, AppSettings } from '@codeleap/types';
2
+ /**
3
+ * Recursively merges `changes` into `base`, deep-merging nested plain objects.
4
+ *
5
+ * Arrays and `Date` instances are treated as scalar values — they replace rather
6
+ * than merge. If `changes` is not iterable, it is returned as-is.
7
+ */
8
+ export declare function deepMerge(base?: Record<string, any>, changes?: Record<string, any>): any;
9
+ /**
10
+ * Like `Array.prototype.map` but over an object's entries.
11
+ *
12
+ * Returns an array — not a new object — so it is useful when you need to
13
+ * transform key-value pairs into arbitrary values (e.g. JSX elements).
14
+ */
15
+ export declare function mapObject<T>(obj: T, callback: FunctionType<[[keyof T, T[keyof T]]], any>): any[];
16
+ /**
17
+ * Sets a value at an arbitrarily deep dot-separated `path`, mutating `base` in place
18
+ * and returning it.
19
+ *
20
+ * Numeric path segments are coerced to array indices when the current node is an array.
21
+ */
22
+ export declare const deepSet: (base: any | undefined, path: string, value: any) => any;
23
+ /**
24
+ * Reads a value from `obj` at a dot-separated `path`.
25
+ *
26
+ * Returns `undefined` (without throwing) when any intermediate node is absent,
27
+ * because property access on `undefined` propagates silently through the loop.
28
+ */
29
+ export declare const deepGet: (path: string, obj: Record<string, any>) => Record<string, any>;
30
+ /**
31
+ * Returns every dot-separated leaf path in a nested object.
32
+ *
33
+ * Array values are treated as leaves — their indices are not traversed.
34
+ */
35
+ export declare function objectPaths(obj: Record<string, any>): string[];
36
+ /** Returns `true` only for `string`, `number`, and `boolean` — `null`, `undefined`, and objects are excluded. */
37
+ export declare function isValuePrimitive(a: any): boolean;
38
+ /**
39
+ * Inline ternary helper for spread-merging optional style or prop objects.
40
+ *
41
+ * Intended for use inside object spreads where the ternary would otherwise
42
+ * require wrapping: `{ ...optionalObject(flag, trueProps, {}) }`.
43
+ */
44
+ export declare function optionalObject(condition: boolean, ifTrue: any, ifFalse: any): any;
45
+ type TraverseRecArgs = {
46
+ path: string[];
47
+ value: any;
48
+ depth: number;
49
+ key: string;
50
+ type: string;
51
+ primitive: boolean;
52
+ };
53
+ type TraverseCallback = (args?: TraverseRecArgs) => {
54
+ stop?: boolean;
55
+ } | void;
56
+ /**
57
+ * Depth-first walk over a nested object, invoking `callback` at each node.
58
+ *
59
+ * The callback receives metadata about each visited node (`path`, `depth`,
60
+ * `key`, `type`, `primitive`). Primitive leaves fire the callback once; object
61
+ * nodes fire it for each child before recursing into it. Returning `{ stop: true }`
62
+ * from the callback is accepted by the type but **does not halt traversal** —
63
+ * the implementation does not check the return value.
64
+ */
65
+ export declare function traverse(obj: any | undefined, callback: TraverseCallback, args?: TraverseRecArgs): void;
66
+ /**
67
+ * Identity helper that returns its argument unchanged, typed as `AppSettings`.
68
+ *
69
+ * Exists solely to give TypeScript a typed entry point for authoring settings
70
+ * objects so that editors provide autocompletion and type errors at the
71
+ * definition site rather than at the point of use.
72
+ */
73
+ export declare function createSettings<T extends AppSettings>(a: T): T;
74
+ /**
75
+ * Returns `obj.id` if it exists, otherwise `undefined`.
76
+ *
77
+ * Intended as a default `keyExtractor` in list utilities where records are
78
+ * expected to carry an `id` field.
79
+ */
80
+ export declare function extractKey(obj: any): any;
81
+ /**
82
+ * Returns a new object containing only the entries for which `predicate` returns `true`.
83
+ *
84
+ * Only own enumerable keys are visited; prototype-chain properties are skipped.
85
+ */
86
+ export declare function objectPickBy<K extends string = string, P = any>(obj: Record<K, P>, predicate: (valueKey: P, key: K) => boolean): Record<K, P>;
87
+ /**
88
+ * Rebuilds an object by running every entry through `predicate`, which must
89
+ * return a `[newKey, newValue]` tuple.
90
+ *
91
+ * Keys returned by `predicate` need not be unique — later entries silently
92
+ * overwrite earlier ones if they resolve to the same key.
93
+ */
94
+ export declare function transformObject<K extends string = string, T extends string = string>(obj: Record<K, T>, predicate: (value: T, key: K) => [K, T]): Record<string, any>;
95
+ type LowercaseFirst<S extends string> = S extends `${infer F}${infer Rest}` ? `${Lowercase<F>}${Rest}` : S;
96
+ /**
97
+ * Mapped type that extracts keys of `T` starting with `P`, strips the prefix,
98
+ * and lowercases the first character of the remainder.
99
+ *
100
+ * Used to derive the return type of {@link filterObjectByPrefix} at compile time.
101
+ * For example, `FilterByPrefix<{ onPress: () => void }, 'on'>` yields `{ press: () => void }`.
102
+ */
103
+ export type FilterByPrefix<T, P extends string> = {
104
+ [K in Extract<keyof T, `${P}${string}`> as K extends `${P}${infer Rest}` ? LowercaseFirst<Rest> : never]: T[K];
105
+ };
106
+ /**
107
+ * Returns a new object containing only keys that start with `prefix`, with the
108
+ * prefix stripped and the first remaining character lowercased.
109
+ *
110
+ * Useful for splitting a flat props object into logical groups, e.g. separating
111
+ * all `inputXxx` props from a combined component interface.
112
+ */
113
+ export declare function filterObjectByPrefix<T extends Record<string, any>, P extends string>(obj: T, prefix: P): FilterByPrefix<T, P>;
114
+ export {};
115
+ //# sourceMappingURL=object.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAE3D;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAAG,GAAG,CAmBhG;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,CAAC,EACzB,GAAG,EAAE,CAAC,EACN,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,SAIrD;AAED;;;;;GAKG;AACH,eAAO,MAAM,OAAO,GAAI,MAAM,GAAG,YAAK,EAAE,MAAM,MAAM,EAAE,OAAO,GAAG,KAAG,GASlE,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,OAAO,GAAI,MAAM,MAAM,EAAE,KAAK,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,wBAS7D,CAAA;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,EAAE,CAY9D;AAED,iHAAiH;AACjH,wBAAgB,gBAAgB,CAAC,CAAC,EAAC,GAAG,WAErC;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,OAE3E;AAED,KAAK,eAAe,GAAG;IAAC,IAAI,EAAC,MAAM,EAAE,CAAC;IAAC,KAAK,EAAE,GAAG,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAC,CAAA;AAEhH,KAAK,gBAAgB,GAAG,CAAC,IAAI,CAAC,EAAE,eAAe,KAAK;IAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAAA;AAE5E;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,YAAK,EAAE,QAAQ,EAAC,gBAAgB,EAAE,IAAI,CAAC,EAAE,eAAe,QA8CxF;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,WAAW,EAAE,CAAC,EAAC,CAAC,GAAG,CAAC,CAE5D;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAC,GAAG,OAIjC;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,QAAQ,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,KAAK,OAAO,gBAU9H;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAUrK;AACD,KAAK,cAAc,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,GAAG,MAAM,IAAI,EAAE,GAAG,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,CAAC,CAAA;AAE1G;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,IAAI;KAC/C,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,SAAS,GAAG,CAAC,GAAG,MAAM,IAAI,EAAE,GAAG,cAAc,CAAC,IAAI,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;CAC/G,CAAA;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,SAAS,MAAM,EAClF,GAAG,EAAE,CAAC,EACN,MAAM,EAAE,CAAC,GACR,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAUtB"}
@@ -0,0 +1,118 @@
1
+ import equals from 'deep-equal';
2
+ import React from 'react';
3
+ /** Deep structural equality backed by the `deep-equal` package. */
4
+ export declare const deepEqual: typeof equals;
5
+ type ArePropsEqualOptions<MergedObject> = {
6
+ check: (keyof MergedObject)[];
7
+ excludeKeys?: string[];
8
+ };
9
+ /**
10
+ * Checks a specific subset of props for deep equality between two render cycles.
11
+ *
12
+ * `excludeKeys` are deleted from each compared value **in place** before
13
+ * comparison — this mutates the items inside `previous` and `next`.
14
+ * Pass only the keys you want to ignore, and be aware of the side-effect.
15
+ */
16
+ export declare function arePropsEqual<A, B>(previous: A, next: B, options: ArePropsEqualOptions<A & B>): boolean;
17
+ /**
18
+ * Recursively collects a React children tree into a single flat array.
19
+ *
20
+ * Uses `React.Children.toArray` at each level (which assigns stable keys), then
21
+ * follows any `children` prop on the top-level element to continue flattening.
22
+ * Only one level of `props.children` nesting is followed per call — deeply
23
+ * nested component trees (not just wrapper nodes) are not fully unwound.
24
+ */
25
+ export declare const flattenChildren: (children: any, flat?: React.ReactNode[]) => React.ReactNode[];
26
+ /**
27
+ * Flattens a children tree and strips the `children` prop from each element's
28
+ * props, returning a serialisable summary of the tree.
29
+ *
30
+ * Intended for introspection and testing — not for re-rendering, since `ref`
31
+ * and event-handler functions are preserved as-is.
32
+ */
33
+ export declare const simplifyChildren: (children: any) => {
34
+ key: any;
35
+ ref: any;
36
+ type: any;
37
+ props: any;
38
+ }[];
39
+ /**
40
+ * Renders a slot that accepts a component, a props object, or a pre-rendered node.
41
+ *
42
+ * Resolution order:
43
+ * 1. If `ComponentOrProps` is a function → render it as `<ComponentOrProps {...props} />`.
44
+ * 2. If it is `null`, `undefined`, or an empty object → return `null`.
45
+ * 3. If it is already a valid React element → return it as-is.
46
+ * 4. Otherwise treat it as a props object and render `<DefaultComponent {...props} {...ComponentOrProps} />`.
47
+ *
48
+ * This lets call sites pass either a component override, extra props, or nothing,
49
+ * without needing separate conditional rendering logic.
50
+ */
51
+ export declare function getRenderedComponent<P = any>(ComponentOrProps: React.ComponentType<P> | P | React.ReactNode | null | undefined, DefaultComponent: React.ComponentType<P>, props?: P): React.ReactNode;
52
+ /**
53
+ * Memoizes a React functional component to prevent unnecessary re-renders.
54
+ *
55
+ * This function wraps a React functional component using `React.memo`, which provides
56
+ * a mechanism for memoizing the result of rendering the component. By default, it
57
+ * uses a comparison function that always returns `true`, indicating that the component
58
+ * should not re-render, regardless of prop changes. This behavior essentially freezes
59
+ * the component's rendering until explicitly updated.
60
+ *
61
+ * @template P - The type of the component's props.
62
+ * @param ComponentToMemoize - The React functional component to memoize.
63
+ * @returns A memoized version of the input component (`React.NamedExoticComponent`).
64
+ */
65
+ export declare function memoize<P extends object>(ComponentToMemoize: React.FunctionComponent<P>): React.NamedExoticComponent<P>;
66
+ /**
67
+ * Checks whether a specific property in two sets of props is equal.
68
+ *
69
+ * This function compares the value of a given property (`prop`) between two objects
70
+ * (`prevProps` and `nextProps`) using a deep equality check (`equals`).
71
+ *
72
+ * @template P - The type of the props object.
73
+ * @param prop - The key of the property to compare.
74
+ * @param prevProps - The previous props object.
75
+ * @param nextProps - The next props object.
76
+ * @returns `true` if the values of the specified property are deeply equal; otherwise, `false`.
77
+ */
78
+ export declare function memoChecker<P>(prop: keyof P, prevProps: P, nextProps: P): boolean;
79
+ /**
80
+ * Memoizes a React functional component based on specific props.
81
+ *
82
+ * This function wraps a React functional component using `React.memo` with a custom comparison
83
+ * function. The comparison function checks if the specified properties (passed as `check`)
84
+ * remain equal between renders. If all specified properties are equal, the component will not re-render.
85
+ *
86
+ * @template P - The type of the component's props.
87
+ * @param ComponentToMemoize - The React functional component to memoize.
88
+ * @param check - A single property key or an array of property keys to compare for memoization.
89
+ * @returns A memoized version of the input component (`React.NamedExoticComponent`).
90
+ *
91
+ * @example
92
+ * import React from 'react';
93
+ * import { memoBy } from './utils';
94
+ *
95
+ * const MyComponent: React.FC<{ name: string; age: number }> = ({ name, age }) => {
96
+ * console.log('Rendering MyComponent...');
97
+ * return (
98
+ * <div>
99
+ * {name}, {age}
100
+ * </div>
101
+ * );
102
+ * };
103
+ *
104
+ * // Memoize the component based on the `name` prop.
105
+ * const MemoizedByName = memoBy(MyComponent, 'name');
106
+ *
107
+ * // Memoize the component based on both `name` and `age` props.
108
+ * const MemoizedByNameAndAge = memoBy(MyComponent, ['name', 'age']);
109
+ *
110
+ * export { MemoizedByName, MemoizedByNameAndAge };
111
+ *
112
+ * // Usage in a parent component
113
+ * <MemoizedByName name="Alice" age={25} />;
114
+ * <MemoizedByNameAndAge name="Alice" age={25} />;
115
+ */
116
+ export declare function memoBy<P extends object>(ComponentToMemoize: React.FunctionComponent<P>, check: keyof P | Array<keyof P>): React.NamedExoticComponent<P>;
117
+ export {};
118
+ //# sourceMappingURL=react.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,YAAY,CAAA;AAC/B,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,mEAAmE;AACnE,eAAO,MAAM,SAAS,eAAS,CAAA;AAE/B,KAAK,oBAAoB,CAAC,YAAY,IAAI;IACxC,KAAK,EAAE,CAAC,MAAM,YAAY,CAAC,EAAE,CAAA;IAC7B,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;CACvB,CAAA;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,CAAC,EAChC,QAAQ,EAAE,CAAC,EACX,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,oBAAoB,CAAC,CAAC,GAAG,CAAC,CAAC,WAqBrC;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAAI,UAAU,GAAG,EAAE,OAAM,KAAK,CAAC,SAAS,EAAO,KAAG,KAAK,CAAC,SAAS,EAQ5F,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAAI,UAAU,GAAG;;;;;GAgB7C,CAAA;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,GAAG,GAAG,EAC1C,gBAAgB,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,SAAS,GAAG,IAAI,GAAG,SAAS,EACjF,gBAAgB,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,EACxC,KAAK,CAAC,EAAE,CAAC,GACR,KAAK,CAAC,SAAS,CAmBjB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,EAAE,kBAAkB,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAEvH;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,GAAG,OAAO,CAKjF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,EACrC,kBAAkB,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAC9C,KAAK,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,GAC9B,KAAK,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAK/B"}
@@ -0,0 +1,43 @@
1
+ /** Collapses all newline characters in `text` to single spaces. */
2
+ export declare function singleLine(text: string): string;
3
+ /**
4
+ * Round-trips a value through `JSON.stringify` → `JSON.parse`.
5
+ *
6
+ * Strips non-serialisable properties (functions, `undefined`, class instances)
7
+ * and produces a plain-object clone. Throws if the value contains circular
8
+ * references.
9
+ */
10
+ export declare function stringiparse(string: string): any;
11
+ /**
12
+ * Changes only the first character of `str`.
13
+ *
14
+ * When `reverse` is `true` the first character is lowercased instead of
15
+ * uppercased — useful for converting PascalCase to camelCase.
16
+ */
17
+ export declare function capitalize(str: string, reverse?: boolean): string;
18
+ /**
19
+ * Returns `true` if `char` is an uppercase Latin or extended Latin character.
20
+ *
21
+ * Covers the Unicode range `U+0080`–`U+024F` in addition to `A–Z`, so
22
+ * accented capitals (e.g. `É`, `Ñ`) are recognised correctly.
23
+ */
24
+ export declare function isUppercase(char: string): boolean;
25
+ /** Returns `true` when `char` is **not** considered uppercase by {@link isUppercase}. */
26
+ export declare function isLowercase(char: string): boolean;
27
+ /**
28
+ * Converts a camelCase or PascalCase identifier to a space-separated, title-cased string.
29
+ *
30
+ * A space is inserted before each uppercase letter that is immediately preceded
31
+ * by a lowercase letter. The first character is always uppercased.
32
+ * Consecutive uppercase runs (e.g. acronyms like "URL") are not split.
33
+ */
34
+ export declare function humanizeCamelCase(str: string): string;
35
+ /**
36
+ * Truncates `str` to `maxLen` characters, appending `'...'` when truncation occurs.
37
+ *
38
+ * The three dots count toward `maxLen`, so the returned string never exceeds
39
+ * `maxLen` characters when truncated. Strings already at or below `maxLen` are
40
+ * returned unchanged.
41
+ */
42
+ export declare function ellipsis(str: string, maxLen: number): string;
43
+ //# sourceMappingURL=string.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,UAEtC;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,OAE1C;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,UAAQ,UAItD;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,WAEvC;AAED,yFAAyF;AACzF,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,WAEvC;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,UAkB5C;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,UAMnD"}
package/package.json CHANGED
@@ -1,7 +1,20 @@
1
1
  {
2
2
  "name": "@codeleap/utils",
3
- "version": "6.3.0",
3
+ "version": "6.8.0",
4
4
  "main": "src/index.ts",
5
+ "types": "dist/index.d.ts",
6
+ "exports": {
7
+ ".": {
8
+ "source": "./src/index.ts",
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "src"
17
+ ],
5
18
  "license": "UNLICENSED",
6
19
  "repository": {
7
20
  "url": "https://github.com/codeleap-uk/internal-libs-monorepo.git",
@@ -9,23 +22,24 @@
9
22
  "directory": "packages/utils"
10
23
  },
11
24
  "devDependencies": {
12
- "@codeleap/config": "6.3.0",
13
- "@codeleap/types": "6.3.0",
25
+ "@codeleap/config": "6.8.0",
26
+ "@codeleap/types": "6.8.0",
14
27
  "ts-node-dev": "1.1.8"
15
28
  },
16
29
  "scripts": {
17
- "build": "echo 'No build needed'"
30
+ "build": "tsc --build tsconfig.build.json",
31
+ "typecheck": "bun tsc --noEmit -p ./tsconfig.json"
18
32
  },
19
33
  "peerDependencies": {
20
- "@codeleap/types": "6.3.0",
34
+ "@codeleap/types": "6.8.0",
21
35
  "axios": "^1.7.9",
22
36
  "dayjs": "1.11.18",
23
- "typescript": "5.5.2",
37
+ "typescript": "6.0.3",
24
38
  "react": "19.1.0",
25
- "@tanstack/react-query": "5.89.0"
39
+ "@tanstack/react-query": "5.100.9"
26
40
  },
27
41
  "dependencies": {
28
42
  "tinycolor2": "^1.4.2",
29
43
  "deep-equal": "^2.0.5"
30
44
  }
31
- }
45
+ }