@codeleap/utils 7.0.0 → 7.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/array.js ADDED
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.objectFromArray = objectFromArray;
4
+ exports.uniqueArrayByProperty = uniqueArrayByProperty;
5
+ exports.flatten = flatten;
6
+ exports.range = range;
7
+ /**
8
+ * Indexes an array into an object keyed by a derived value.
9
+ *
10
+ * `keyAccessor` may be a property name string or a callback that returns a
11
+ * key. When omitted, array indices are used as keys. Duplicate keys silently
12
+ * overwrite earlier entries.
13
+ */
14
+ function objectFromArray(arr, keyAccessor) {
15
+ let getObjectKey = (_, idx) => idx;
16
+ if (keyAccessor) {
17
+ switch (typeof keyAccessor) {
18
+ case 'string':
19
+ getObjectKey = (value) => value[keyAccessor];
20
+ break;
21
+ case 'function':
22
+ getObjectKey = keyAccessor;
23
+ break;
24
+ }
25
+ }
26
+ const indexedMap = arr.map((value, idx) => [getObjectKey(value, idx), value]);
27
+ return Object.fromEntries(indexedMap);
28
+ }
29
+ /**
30
+ * Returns a deduplicated copy of `array` where uniqueness is determined by
31
+ * the value returned from `getProperty`.
32
+ *
33
+ * When duplicates exist, the **last** occurrence wins because `objectFromArray`
34
+ * overwrites earlier entries with the same key.
35
+ */
36
+ function uniqueArrayByProperty(array, getProperty) {
37
+ return Object.values(objectFromArray(array, getProperty));
38
+ }
39
+ /**
40
+ * Recursively flattens a nested array of arbitrary depth into a single-level array.
41
+ *
42
+ * Unlike `Array.prototype.flat(Infinity)`, this implementation does not rely on
43
+ * native flat support and works identically across all environments.
44
+ */
45
+ function flatten(arr) {
46
+ let newArr = [];
47
+ arr.forEach((item) => {
48
+ if (Array.isArray(item)) {
49
+ newArr = [...newArr, ...flatten(item)];
50
+ }
51
+ else {
52
+ newArr.push(item);
53
+ }
54
+ });
55
+ return newArr;
56
+ }
57
+ /**
58
+ * Returns an inclusive integer array from `start` to `end`.
59
+ *
60
+ * Both bounds are included: `range(1, 3)` → `[1, 2, 3]`.
61
+ */
62
+ function range(start, end) {
63
+ const length = end - start + 1;
64
+ return Array.from({ length }, (_, index) => index + start);
65
+ }
66
+ //# sourceMappingURL=array.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array.js","sourceRoot":"","sources":["../src/array.ts"],"names":[],"mappings":";;AAWA,0CAoBC;AASD,sDAKC;AAQD,0BAYC;AAOD,sBAGC;AAvED;;;;;;GAMG;AACH,SAAgB,eAAe,CAC7B,GAAQ,EACR,WAAoB;IAEpB,IAAI,YAAY,GAA+C,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,CAAA;IAE9E,IAAI,WAAW,EAAE,CAAC;QAChB,QAAQ,OAAO,WAAW,EAAE,CAAC;YAC3B,KAAK,QAAQ;gBACX,YAAY,GAAG,CAAC,KAAQ,EAAE,EAAE,CAAC,KAAK,CAAC,WAAsB,CAA+B,CAAA;gBACxF,MAAK;YACP,KAAK,UAAU;gBACb,YAAY,GAAG,WAAyD,CAAA;gBACxE,MAAK;QACT,CAAC;IACH,CAAC;IAED,MAAM,UAAU,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,YAAY,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC,CAAA;IAE7E,OAAO,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,CAAA;AACvC,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,qBAAqB,CACnC,KAAU,EACV,WAAc;IAEd,OAAO,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAA;AAC3D,CAAC;AAED;;;;;GAKG;AACH,SAAgB,OAAO,CAAoB,GAAQ;IACjD,IAAI,MAAM,GAAG,EAAS,CAAA;IAEtB,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACnB,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACxB,MAAM,GAAG,CAAC,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;QACxC,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACnB,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;;;GAIG;AACH,SAAgB,KAAK,CAAC,KAAa,EAAE,GAAW;IAC9C,MAAM,MAAM,GAAG,GAAG,GAAG,KAAK,GAAG,CAAC,CAAA;IAC9B,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,KAAK,CAAC,CAAA;AAC5D,CAAC"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cloneDeep = cloneDeep;
4
+ /**
5
+ * Produces a full recursive clone of `value` without any external dependencies.
6
+ *
7
+ * Supported types: primitives (returned as-is), plain objects, arrays, `Date`,
8
+ * `Map`, `Set`, and `RegExp`. Class instances with prototype methods beyond
9
+ * these built-ins are cloned as plain objects — prototype chain is not preserved.
10
+ * Circular references will cause a stack overflow.
11
+ */
12
+ function cloneDeep(value) {
13
+ if (value === null || typeof value !== 'object') {
14
+ return value;
15
+ }
16
+ if (Array.isArray(value)) {
17
+ return value.map(cloneDeep);
18
+ }
19
+ if (value instanceof Date) {
20
+ return new Date(value.getTime());
21
+ }
22
+ if (value instanceof Map) {
23
+ const clonedMap = new Map();
24
+ value.forEach((v, k) => {
25
+ clonedMap.set(k, cloneDeep(v));
26
+ });
27
+ return clonedMap;
28
+ }
29
+ if (value instanceof Set) {
30
+ const clonedSet = new Set();
31
+ value.forEach((v) => {
32
+ clonedSet.add(cloneDeep(v));
33
+ });
34
+ return clonedSet;
35
+ }
36
+ if (value instanceof RegExp) {
37
+ return new RegExp(value.source, value.flags);
38
+ }
39
+ const clonedObj = {};
40
+ for (const key in value) {
41
+ if (Object.prototype.hasOwnProperty.call(value, key)) {
42
+ clonedObj[key] = cloneDeep(value[key]);
43
+ }
44
+ }
45
+ return clonedObj;
46
+ }
47
+ //# sourceMappingURL=cloneDeep.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloneDeep.js","sourceRoot":"","sources":["../src/cloneDeep.ts"],"names":[],"mappings":";;AAQA,8BA0CC;AAlDD;;;;;;;GAOG;AACH,SAAgB,SAAS,CAAU,KAAQ;IACzC,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAChD,OAAO,KAAK,CAAA;IACd,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC,GAAG,CAAC,SAAS,CAAiB,CAAA;IAC7C,CAAC;IAED,IAAI,KAAK,YAAY,IAAI,EAAE,CAAC;QAC1B,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAiB,CAAA;IAClD,CAAC;IAED,IAAI,KAAK,YAAY,GAAG,EAAE,CAAC;QACzB,MAAM,SAAS,GAAG,IAAI,GAAG,EAAE,CAAA;QAC3B,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YACrB,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;QAChC,CAAC,CAAC,CAAA;QACF,OAAO,SAAyB,CAAA;IAClC,CAAC;IAED,IAAI,KAAK,YAAY,GAAG,EAAE,CAAC;QACzB,MAAM,SAAS,GAAG,IAAI,GAAG,EAAE,CAAA;QAC3B,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;YAClB,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;QAC7B,CAAC,CAAC,CAAA;QACF,OAAO,SAAyB,CAAA;IAClC,CAAC;IAED,IAAI,KAAK,YAAY,MAAM,EAAE,CAAC;QAC5B,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAiB,CAAA;IAC9D,CAAC;IAED,MAAM,SAAS,GAA4B,EAAE,CAAA;IAE7C,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;QACxB,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC;YACrD,SAAS,CAAC,GAAG,CAAC,GAAG,SAAS,CAAE,KAAiC,CAAC,GAAG,CAAC,CAAC,CAAA;QACrE,CAAC;IACH,CAAC;IAED,OAAO,SAAyB,CAAA;AAClC,CAAC"}
package/dist/colors.js ADDED
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.hexToRgb = hexToRgb;
7
+ exports.shadeColor = shadeColor;
8
+ const tinycolor2_1 = __importDefault(require("tinycolor2"));
9
+ const types_1 = require("@codeleap/types");
10
+ /**
11
+ * Parses a 6-digit hex colour string (with or without leading `#`) into its
12
+ * `{ r, g, b }` components.
13
+ *
14
+ * Returns `null` for invalid or short (3-digit) hex values.
15
+ */
16
+ function hexToRgb(hex) {
17
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
18
+ return result
19
+ ? {
20
+ r: parseInt(result[1], 16),
21
+ g: parseInt(result[2], 16),
22
+ b: parseInt(result[3], 16),
23
+ }
24
+ : null;
25
+ }
26
+ const shadeColorCache = {};
27
+ /**
28
+ * Lightens or darkens `color` by `percent` and optionally applies `opacity`,
29
+ * returning an `rgba(...)` string.
30
+ *
31
+ * - Positive `percent` → lighten; negative → darken (magnitude is used).
32
+ * - `opacity` must be in the `0–1` range (passed directly to tinycolor's `setAlpha`).
33
+ * - Results are memoised in a module-level cache keyed by the serialised parameters,
34
+ * so repeated calls with identical arguments are effectively free.
35
+ */
36
+ function shadeColor(color, percent = 0, opacity = null) {
37
+ const _color = color.trim();
38
+ const serialParams = [_color, percent.toString()];
39
+ if (types_1.TypeGuards.isNumber(opacity)) {
40
+ serialParams.push(opacity.toString());
41
+ }
42
+ const cacheKey = serialParams.join('/');
43
+ if (!!shadeColorCache[cacheKey]) {
44
+ return shadeColorCache[cacheKey];
45
+ }
46
+ const cl = (0, tinycolor2_1.default)(_color);
47
+ if (percent !== 0) {
48
+ const shouldDarken = percent < 0;
49
+ if (shouldDarken) {
50
+ cl.darken(-percent);
51
+ }
52
+ else {
53
+ cl.lighten(percent);
54
+ }
55
+ }
56
+ if (types_1.TypeGuards.isNumber(opacity)) {
57
+ cl.setAlpha(opacity);
58
+ }
59
+ const rgbObj = cl.toRgb();
60
+ const rgbStr = `rgba(${rgbObj.r},${rgbObj.g},${rgbObj.b},${rgbObj.a})`;
61
+ shadeColorCache[cacheKey] = rgbStr;
62
+ return rgbStr;
63
+ }
64
+ //# sourceMappingURL=colors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"colors.js","sourceRoot":"","sources":["../src/colors.ts"],"names":[],"mappings":";;;;;AASA,4BASC;AAaD,gCA+BC;AA9DD,4DAAkC;AAClC,2CAA4C;AAE5C;;;;;GAKG;AACH,SAAgB,QAAQ,CAAC,GAAW;IAClC,MAAM,MAAM,GAAG,2CAA2C,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACpE,OAAO,MAAM;QACX,CAAC,CAAC;YACA,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;YAC1B,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,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IACzB,MAAM,MAAM,GAAG,QAAQ,MAAM,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,GAAG,CAAA;IACtE,eAAe,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAA;IAClC,OAAO,MAAM,CAAA;AACf,CAAC"}
package/dist/date.js ADDED
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.dateUtils = void 0;
7
+ const dayjs_1 = __importDefault(require("dayjs"));
8
+ const removeTimezoneAndFormat = (date, format = 'YYYY-MM-DD') => {
9
+ if (!date)
10
+ return '';
11
+ let normalizedDate = date;
12
+ if (date instanceof Date) {
13
+ normalizedDate = date.toISOString().split('T')[0] + 'T12:00:00';
14
+ }
15
+ else if (typeof date === 'string' && date.includes('T')) {
16
+ normalizedDate = date.split('T')[0] + 'T12:00:00';
17
+ }
18
+ return (0, dayjs_1.default)(normalizedDate).startOf('day').format(format);
19
+ };
20
+ /**
21
+ * Date helpers that normalise timezone-sensitive values before formatting.
22
+ *
23
+ * - `removeTimezoneAndFormat(date, format?)` — strips the time component from
24
+ * a `Date` or ISO string, anchors it to noon local time, then formats with
25
+ * dayjs. This prevents off-by-one-day errors that occur when UTC midnight
26
+ * falls on a different calendar day in the user's timezone. Returns `''` for
27
+ * falsy input.
28
+ */
29
+ exports.dateUtils = {
30
+ removeTimezoneAndFormat,
31
+ };
32
+ //# sourceMappingURL=date.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date.js","sourceRoot":"","sources":["../src/date.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAyB;AAEzB,MAAM,uBAAuB,GAAG,CAAC,IAAS,EAAE,MAAM,GAAG,YAAY,EAAE,EAAE;IACnE,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAA;IAEpB,IAAI,cAAc,GAAG,IAAI,CAAA;IAEzB,IAAI,IAAI,YAAY,IAAI,EAAE,CAAC;QACzB,cAAc,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,WAAW,CAAA;IACjE,CAAC;SAAM,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1D,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,WAAW,CAAA;IACnD,CAAC;IAED,OAAO,IAAA,eAAK,EAAC,cAAc,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;AAC5D,CAAC,CAAA;AAED;;;;;;;;GAQG;AACU,QAAA,SAAS,GAAG;IACvB,uBAAuB;CACxB,CAAA"}
package/dist/faker.js ADDED
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.faker = void 0;
4
+ const names = [
5
+ 'James', 'John', 'Robert', 'Michael', 'William', 'David', 'Richard', 'Joseph', 'Thomas',
6
+ 'Charles', 'Christopher', 'Daniel', 'Matthew', 'Anthony', 'Donald', 'Mark', 'Paul', 'Steven',
7
+ 'Andrew', 'Kenneth', 'Joshua', 'Kevin', 'Brian', 'George', 'Edward', 'Ronald', 'Timothy',
8
+ 'Jason', 'Jeffrey', 'Ryan', 'Gary', 'Jacob'
9
+ ];
10
+ const surnames = [
11
+ 'Smith', 'Johnson', 'Williams', 'Brown', 'Jones', 'Garcia', 'Miller', 'Davis',
12
+ 'Lopez', 'Wilson', 'Anderson', 'Thomas', 'Taylor', 'Moore',
13
+ 'Jackson', 'Martin', 'Lee', 'Perez', 'Thompson', 'White', 'Harris', 'Sanchez', 'Clark',
14
+ 'Ramirez', 'Lewis', 'Robinson', 'Walker', 'Young', 'Allen', 'King', 'Wright', 'Scott', 'Torres',
15
+ ];
16
+ const animals = [
17
+ 'lion', 'tiger', 'zebra', 'panda', 'koala', 'bear',
18
+ 'wolf', 'fox', 'rabbit', 'bat', 'spider', 'frog', 'shark'
19
+ ];
20
+ function getRandom(list) {
21
+ return list[Math.floor(Math.random() * list.length)];
22
+ }
23
+ function number(min = 0, max = 100) {
24
+ return Math.floor(Math.random() * (max - min + 1)) + min;
25
+ }
26
+ /**
27
+ * Lightweight in-house fixture-data generator with no external dependencies.
28
+ *
29
+ * Provided methods:
30
+ * - `firstName()` / `lastName()` — random entries from hard-coded name lists.
31
+ * - `name()` — space-joined first + last name.
32
+ * - `animal()` — random animal name.
33
+ * - `number(min?, max?)` — random integer in `[min, max]` (default 0–100).
34
+ *
35
+ * All selections use `Math.random`, so results are not reproducible across calls.
36
+ * Use this instead of heavy faker libraries in tests or seed scripts where the
37
+ * small vocabulary is sufficient.
38
+ */
39
+ exports.faker = {
40
+ lastName: () => getRandom(surnames),
41
+ firstName: () => getRandom(names),
42
+ animal: () => getRandom(animals),
43
+ number,
44
+ name: () => `${getRandom(names)} ${getRandom(surnames)}`
45
+ };
46
+ //# sourceMappingURL=faker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"faker.js","sourceRoot":"","sources":["../src/faker.ts"],"names":[],"mappings":";;;AAAA,MAAM,KAAK,GAAG;IACZ,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ;IACvF,SAAS,EAAE,aAAa,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ;IAC5F,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS;IACxF,OAAO,EAAE,SAAS,EAAE,M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AAE,CAAC,SAAS,CAAC,OAAO,CAAC;IAChC,MAAM;IACN,IAAI,EAAE,GAAG,EAAE,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,SAAS,CAAC,QAAQ,CAAC,EAAE;CACzD,CAAA"}
package/dist/file.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseFilePathData = parseFilePathData;
4
+ const separators = /[\\\/]+/;
5
+ /**
6
+ * Splits a file system path into its directory, base name, and extension.
7
+ *
8
+ * Both `/` and `\` are treated as separators, so Windows and POSIX paths are
9
+ * handled uniformly. Files without an extension return an empty string for
10
+ * `extension`. The returned `path` is always joined with `/` regardless of the
11
+ * original separator.
12
+ */
13
+ function parseFilePathData(path) {
14
+ const parts = path.split(separators);
15
+ const lastPart = parts[parts.length - 1];
16
+ let fileName = lastPart;
17
+ let ext = '';
18
+ if (lastPart.includes('.')) {
19
+ const dotIdx = fileName.lastIndexOf('.');
20
+ fileName = fileName.substring(0, dotIdx);
21
+ ext = lastPart.substring(dotIdx + 1);
22
+ }
23
+ return {
24
+ path: parts.slice(0, -1).join('/'),
25
+ extension: ext,
26
+ name: fileName,
27
+ };
28
+ }
29
+ //# sourceMappingURL=file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.js","sourceRoot":"","sources":["../src/file.ts"],"names":[],"mappings":";;AAUA,8CAoBC;AA9BD,MAAM,UAAU,GAAG,SAAS,CAAA;AAE5B;;;;;;;GAOG;AACH,SAAgB,iBAAiB,CAAC,IAAY;IAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;IAEpC,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IAExC,IAAI,QAAQ,GAAG,QAAQ,CAAA;IACvB,IAAI,GAAG,GAAG,EAAE,CAAA;IAEZ,IAAI,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC3B,MAAM,MAAM,GAAG,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;QACxC,QAAQ,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;QAExC,GAAG,GAAG,QAAQ,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IACtC,CAAC;IAED,OAAO;QACL,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;QAClC,SAAS,EAAE,GAAG;QACd,IAAI,EAAE,QAAQ;KACf,CAAA;AACH,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./array"), exports);
18
+ __exportStar(require("./colors"), exports);
19
+ __exportStar(require("./misc"), exports);
20
+ __exportStar(require("./object"), exports);
21
+ __exportStar(require("./react"), exports);
22
+ __exportStar(require("./file"), exports);
23
+ __exportStar(require("./string"), exports);
24
+ __exportStar(require("./faker"), exports);
25
+ __exportStar(require("./cloneDeep"), exports);
26
+ __exportStar(require("./locale"), exports);
27
+ __exportStar(require("./date"), exports);
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,2CAAwB;AACxB,yCAAsB;AACtB,2CAAwB;AACxB,0CAAuB;AACvB,yCAAsB;AACtB,2CAAwB;AACxB,0CAAuB;AACvB,8CAA2B;AAC3B,2CAAwB;AACxB,yCAAsB"}
package/dist/locale.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSimilarLocale = getSimilarLocale;
4
+ /**
5
+ * Finds the closest matching key in `languageDictionary` for a given `locale`.
6
+ *
7
+ * Matching uses only the first two characters (the language subtag), so `'en-AU'`
8
+ * will match an `'en-US'` dictionary key. Returns `defaultLocale` when no
9
+ * partial match exists.
10
+ */
11
+ function getSimilarLocale(locale, defaultLocale, languageDictionary) {
12
+ const inputFirstPart = locale.substring(0, 2);
13
+ const keys = Object.keys(languageDictionary);
14
+ for (const key of keys) {
15
+ const keyFirstPart = key.substring(0, 2);
16
+ if (inputFirstPart === keyFirstPart)
17
+ return key;
18
+ }
19
+ return defaultLocale;
20
+ }
21
+ //# sourceMappingURL=locale.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locale.js","sourceRoot":"","sources":["../src/locale.ts"],"names":[],"mappings":";;AASA,4CAYC;AAnBD;;;;;;GAMG;AACH,SAAgB,gBAAgB,CAC9B,MAAc,EACd,aAAqB,EACrB,kBAA6B;IAE7B,MAAM,cAAc,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAC7C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAA;IAC5C,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,YAAY,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;QACxC,IAAI,cAAc,KAAK,YAAY;YAAE,OAAO,GAAG,CAAA;IACjD,CAAC;IACD,OAAO,aAAa,CAAA;AACtB,CAAC"}
package/dist/misc.js ADDED
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.imagePathToFileObject = imagePathToFileObject;
4
+ exports.matchInitialToColor = matchInitialToColor;
5
+ exports.waitFor = waitFor;
6
+ exports.parseSourceUrl = parseSourceUrl;
7
+ exports.getNestedStylesByKey = getNestedStylesByKey;
8
+ exports.hasFastRefreshed = hasFastRefreshed;
9
+ exports.throttle = throttle;
10
+ const string_1 = require("./string");
11
+ /**
12
+ * Converts a remote image URL into a file-upload-compatible object
13
+ * (`{ uri, name, type }`).
14
+ *
15
+ * The `type` is inferred from the URL's file extension. Returns `null` when
16
+ * `imagePath` is falsy, making it safe to pass directly to optional file-input APIs.
17
+ */
18
+ function imagePathToFileObject(imagePath) {
19
+ const parts = imagePath ? imagePath.split('.') : '';
20
+ const ext = imagePath ? parts[parts.length - 1].toLowerCase() : '';
21
+ const fileValue = imagePath
22
+ ? {
23
+ uri: imagePath,
24
+ name: 'image_' + imagePath,
25
+ type: `image/${ext}`,
26
+ }
27
+ : null;
28
+ return fileValue;
29
+ }
30
+ const letterToColorMap = {
31
+ a: '#7CB9E8',
32
+ b: '#3a9e77',
33
+ c: '#A3C1AD',
34
+ d: '#E1BD27',
35
+ e: '#badc58',
36
+ f: '#db5970',
37
+ g: '#9b8ef1',
38
+ h: '#ffe169',
39
+ i: '#3ea9d1',
40
+ j: '#8aa341',
41
+ k: '#baf2f5',
42
+ l: '#ffa02d',
43
+ m: '#d46830',
44
+ n: '#62ecaa',
45
+ o: '#ffbe50',
46
+ p: '#0078D7',
47
+ q: '#8764B8',
48
+ r: '#52dd64',
49
+ s: '#7edce9',
50
+ t: '#dadd5d',
51
+ u: '#e9b55d',
52
+ v: '#99d669',
53
+ w: '#a3c83a',
54
+ x: '#f28d67',
55
+ y: '#ea82ec',
56
+ z: '#ff8295',
57
+ };
58
+ /**
59
+ * Maps the first character of `anyString` to a deterministic colour for use in
60
+ * avatar placeholders.
61
+ *
62
+ * Lookup is case-insensitive. Returns `'#999999'` for empty, undefined, or
63
+ * characters not in the `a–z` range.
64
+ */
65
+ function matchInitialToColor(anyString) {
66
+ if (!anyString)
67
+ return '#999999';
68
+ return letterToColorMap[anyString.toLowerCase().charAt(0)] || '#999999';
69
+ }
70
+ /** Returns a Promise that resolves after `ms` milliseconds. */
71
+ function waitFor(ms) {
72
+ return new Promise((resolve) => {
73
+ setTimeout(() => {
74
+ resolve();
75
+ }, ms);
76
+ });
77
+ }
78
+ function parseSourceUrl(args, Settings) {
79
+ if (!args)
80
+ return null;
81
+ let res = '';
82
+ let address = '';
83
+ if (typeof args === 'string') {
84
+ address = args;
85
+ }
86
+ else {
87
+ address = args.source || args.src || '';
88
+ }
89
+ if (address && address.startsWith('/media/')) {
90
+ const tmp = address.substr(1, address.length);
91
+ res = `${Settings.BaseURL}${tmp}`;
92
+ }
93
+ else if (address) {
94
+ res = address;
95
+ }
96
+ else {
97
+ res = `https://picsum.photos/600?random=${Math.random() * 100}`;
98
+ }
99
+ return res;
100
+ }
101
+ /**
102
+ * Extracts style entries from a variant styles map whose keys begin with `match`,
103
+ * returning them as a new object with the prefix stripped and the first
104
+ * remaining character lowercased.
105
+ *
106
+ * Used internally by component style systems to pull out sub-part styles
107
+ * (e.g. `inputLabel`, `inputWrapper`) into their own namespaced objects.
108
+ */
109
+ function getNestedStylesByKey(match, variantStyles) {
110
+ const styles = {};
111
+ for (const [key, value] of Object.entries(variantStyles)) {
112
+ if (key.startsWith(match)) {
113
+ const partName = (0, string_1.capitalize)(key.replace(match, ''), true);
114
+ styles[partName] = value;
115
+ }
116
+ }
117
+ return styles;
118
+ }
119
+ /**
120
+ * Heuristically detects whether the app has been React Fast Refreshed since
121
+ * initial launch.
122
+ *
123
+ * Compares the elapsed time since `Settings.Environment.InitTime` against a
124
+ * 1-second threshold. Fast Refresh typically completes well under 1 second from
125
+ * app start; anything longer suggests a subsequent refresh rather than cold boot.
126
+ * Returns `undefined` and logs a warning when `InitTime` is not set.
127
+ */
128
+ function hasFastRefreshed(Settings) {
129
+ var _a;
130
+ if ((_a = Settings === null || Settings === void 0 ? void 0 : Settings.Environment) === null || _a === void 0 ? void 0 : _a.InitTime) {
131
+ const timeFromStartup = (new Date()).getTime() - Settings.Environment.InitTime.getTime();
132
+ // It usually takes less than a seconds (~300ms) from app launch to running this, so if's been more than that we've probably fast refreshed
133
+ const fastRefreshed = Settings.Environment.IsDev && timeFromStartup > 1000;
134
+ return fastRefreshed;
135
+ }
136
+ else {
137
+ console.log('hasFreshRefreshed() => Missing datetime from settings, please include to make this work');
138
+ return undefined;
139
+ }
140
+ }
141
+ const throttleTimerId = {};
142
+ /**
143
+ * Leading-edge throttle keyed by a `ref` identifier rather than by function reference.
144
+ *
145
+ * `func` is called immediately on the first invocation for a given `ref`; subsequent
146
+ * calls with the same `ref` are dropped until `delay` milliseconds have elapsed.
147
+ * Using a string/number `ref` allows multiple independent throttle timers to coexist
148
+ * in a single module without needing to hold separate timer handles.
149
+ */
150
+ function throttle(func, ref, delay) {
151
+ if (throttleTimerId[ref]) {
152
+ return;
153
+ }
154
+ throttleTimerId[ref] = setTimeout(function () {
155
+ func();
156
+ throttleTimerId[ref] = undefined;
157
+ }, delay);
158
+ }
159
+ //# sourceMappingURL=misc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"misc.js","sourceRoot":"","sources":["../src/misc.ts"],"names":[],"mappings":";;AAUA,sDAcC;AAsCD,kDAGC;AAGD,0BAMC;AAoBD,wCAuBC;AAUD,oDAYC;AAWD,4CAUC;AAYD,4BASC;AArLD,qCAAqC;AAGrC;;;;;;GAMG;AACH,SAAgB,qBAAqB,CAAC,SAAwB;IAC5D,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAA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+1,205 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deepGet = exports.deepSet = void 0;
4
+ exports.deepMerge = deepMerge;
5
+ exports.mapObject = mapObject;
6
+ exports.objectPaths = objectPaths;
7
+ exports.isValuePrimitive = isValuePrimitive;
8
+ exports.optionalObject = optionalObject;
9
+ exports.traverse = traverse;
10
+ exports.createSettings = createSettings;
11
+ exports.extractKey = extractKey;
12
+ exports.objectPickBy = objectPickBy;
13
+ exports.transformObject = transformObject;
14
+ exports.filterObjectByPrefix = filterObjectByPrefix;
15
+ /**
16
+ * Recursively merges `changes` into `base`, deep-merging nested plain objects.
17
+ *
18
+ * Arrays and `Date` instances are treated as scalar values — they replace rather
19
+ * than merge. If `changes` is not iterable, it is returned as-is.
20
+ */
21
+ function deepMerge(base = {}, changes = {}) {
22
+ const obj = Object.assign({}, base);
23
+ let changeEntries = [];
24
+ try {
25
+ changeEntries = Object.entries(changes);
26
+ }
27
+ catch (e) {
28
+ return changes;
29
+ }
30
+ for (const [key, value] of changeEntries) {
31
+ obj[key] =
32
+ typeof value === 'object' && !Array.isArray(value) && !(value instanceof Date)
33
+ ? deepMerge(obj[key], changes[key])
34
+ : value;
35
+ }
36
+ return obj;
37
+ }
38
+ /**
39
+ * Like `Array.prototype.map` but over an object's entries.
40
+ *
41
+ * Returns an array — not a new object — so it is useful when you need to
42
+ * transform key-value pairs into arbitrary values (e.g. JSX elements).
43
+ */
44
+ function mapObject(obj, callback) {
45
+ return Object.entries(obj).map((args) => callback(args));
46
+ }
47
+ /**
48
+ * Sets a value at an arbitrarily deep dot-separated `path`, mutating `base` in place
49
+ * and returning it.
50
+ *
51
+ * Numeric path segments are coerced to array indices when the current node is an array.
52
+ */
53
+ const deepSet = (base = {}, path, value) => {
54
+ const keys = path.split('.');
55
+ const obj = base;
56
+ let thisKey = keys[0];
57
+ if (Array.isArray(base)) {
58
+ thisKey = Number(thisKey);
59
+ }
60
+ obj[thisKey] = keys.length === 1 ? value : (0, exports.deepSet)(obj[thisKey], keys.slice(1).join('.'), value);
61
+ return obj;
62
+ };
63
+ exports.deepSet = deepSet;
64
+ /**
65
+ * Reads a value from `obj` at a dot-separated `path`.
66
+ *
67
+ * Returns `undefined` (without throwing) when any intermediate node is absent,
68
+ * because property access on `undefined` propagates silently through the loop.
69
+ */
70
+ const deepGet = (path, obj) => {
71
+ const parts = path.split('.');
72
+ let newObj = Object.assign({}, obj);
73
+ for (const prop of parts) {
74
+ newObj = newObj[prop];
75
+ }
76
+ return newObj;
77
+ };
78
+ exports.deepGet = deepGet;
79
+ /**
80
+ * Returns every dot-separated leaf path in a nested object.
81
+ *
82
+ * Array values are treated as leaves — their indices are not traversed.
83
+ */
84
+ function objectPaths(obj) {
85
+ let paths = [];
86
+ Object.entries(obj).forEach(([key, value]) => {
87
+ if (!Array.isArray(value) && typeof value === 'object') {
88
+ paths = [...paths, ...objectPaths(value).map((k) => `${key}.${k}`)];
89
+ }
90
+ else {
91
+ paths.push(key);
92
+ }
93
+ });
94
+ return paths;
95
+ }
96
+ /** Returns `true` only for `string`, `number`, and `boolean` — `null`, `undefined`, and objects are excluded. */
97
+ function isValuePrimitive(a) {
98
+ return ['string', 'number', 'boolean'].includes(typeof a);
99
+ }
100
+ /**
101
+ * Inline ternary helper for spread-merging optional style or prop objects.
102
+ *
103
+ * Intended for use inside object spreads where the ternary would otherwise
104
+ * require wrapping: `{ ...optionalObject(flag, trueProps, {}) }`.
105
+ */
106
+ function optionalObject(condition, ifTrue, ifFalse) {
107
+ return condition ? ifTrue : ifFalse;
108
+ }
109
+ /**
110
+ * Depth-first walk over a nested object, invoking `callback` at each node.
111
+ *
112
+ * The callback receives metadata about each visited node (`path`, `depth`,
113
+ * `key`, `type`, `primitive`). Primitive leaves fire the callback once; object
114
+ * nodes fire it for each child before recursing into it. Returning `{ stop: true }`
115
+ * from the callback is accepted by the type but **does not halt traversal** —
116
+ * the implementation does not check the return value.
117
+ */
118
+ function traverse(obj = {}, callback, args) {
119
+ const isPrimitive = isValuePrimitive(obj);
120
+ const info = Object.assign({ path: [], depth: 0, key: '', type: typeof obj, value: obj, primitive: isPrimitive }, args);
121
+ if (isPrimitive) {
122
+ callback(Object.assign(Object.assign({}, info), { depth: info.depth }));
123
+ }
124
+ else {
125
+ for (const [key, value] of Object.entries(obj || {})) {
126
+ const isPrimitive = isValuePrimitive(value);
127
+ if (!isPrimitive) {
128
+ callback(Object.assign(Object.assign({}, info), { key,
129
+ value, type: typeof value, primitive: isPrimitive, path: [...info.path, key] }));
130
+ }
131
+ traverse(value, callback, Object.assign(Object.assign({}, info), { key,
132
+ value, type: typeof value, primitive: isValuePrimitive(value), path: [...info.path, key], depth: info.depth + 1 }));
133
+ }
134
+ }
135
+ }
136
+ /**
137
+ * Identity helper that returns its argument unchanged, typed as `AppSettings`.
138
+ *
139
+ * Exists solely to give TypeScript a typed entry point for authoring settings
140
+ * objects so that editors provide autocompletion and type errors at the
141
+ * definition site rather than at the point of use.
142
+ */
143
+ function createSettings(a) {
144
+ return a;
145
+ }
146
+ /**
147
+ * Returns `obj.id` if it exists, otherwise `undefined`.
148
+ *
149
+ * Intended as a default `keyExtractor` in list utilities where records are
150
+ * expected to carry an `id` field.
151
+ */
152
+ function extractKey(obj) {
153
+ if (obj.id) {
154
+ return obj.id;
155
+ }
156
+ }
157
+ /**
158
+ * Returns a new object containing only the entries for which `predicate` returns `true`.
159
+ *
160
+ * Only own enumerable keys are visited; prototype-chain properties are skipped.
161
+ */
162
+ function objectPickBy(obj, predicate) {
163
+ var _a;
164
+ const result = {};
165
+ for (const key in obj) {
166
+ if (((_a = obj === null || obj === void 0 ? void 0 : obj.hasOwnProperty) === null || _a === void 0 ? void 0 : _a.call(obj, key)) && (predicate === null || predicate === void 0 ? void 0 : predicate(obj === null || obj === void 0 ? void 0 : obj[key], key))) {
167
+ result[key] = obj === null || obj === void 0 ? void 0 : obj[key];
168
+ }
169
+ }
170
+ return result;
171
+ }
172
+ /**
173
+ * Rebuilds an object by running every entry through `predicate`, which must
174
+ * return a `[newKey, newValue]` tuple.
175
+ *
176
+ * Keys returned by `predicate` need not be unique — later entries silently
177
+ * overwrite earlier ones if they resolve to the same key.
178
+ */
179
+ function transformObject(obj, predicate) {
180
+ const result = {};
181
+ for (const key in obj) {
182
+ const [newKey, newValue] = predicate === null || predicate === void 0 ? void 0 : predicate(obj === null || obj === void 0 ? void 0 : obj[key], key);
183
+ result[newKey] = newValue;
184
+ }
185
+ return result;
186
+ }
187
+ /**
188
+ * Returns a new object containing only keys that start with `prefix`, with the
189
+ * prefix stripped and the first remaining character lowercased.
190
+ *
191
+ * Useful for splitting a flat props object into logical groups, e.g. separating
192
+ * all `inputXxx` props from a combined component interface.
193
+ */
194
+ function filterObjectByPrefix(obj, prefix) {
195
+ const result = {};
196
+ for (const key in obj) {
197
+ if (key.startsWith(prefix)) {
198
+ const newKey = key.slice(prefix.length);
199
+ const formattedKey = newKey.charAt(0).toLowerCase() + newKey.slice(1);
200
+ result[formattedKey] = obj[key];
201
+ }
202
+ }
203
+ return result;
204
+ }
205
+ //# sourceMappingURL=object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.js","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":";;;AAQA,8BAmBC;AAQD,8BAMC;AAyCD,kCAYC;AAGD,4CAEC;AAQD,wCAEC;AAeD,4BA8CC;AASD,wCAEC;AAQD,gCAIC;AAOD,oCAUC;AASD,0CAUC;AAqBD,oDAaC;AArQD;;;;;GAKG;AACH,SAAgB,SAAS,CAAC,OAA4B,EAAE,EAAE,UAA+B,EAAE;IACzF,MAAM,GAAG,qBACJ,IAAI,CACR,CAAA;IACD,IAAI,aAAa,GAAoB,EAAE,CAAA;IACvC,IAAI,CAAC;QACH,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IACzC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,OAAO,CAAA;IAChB,CAAC;IAED,KAAK,MAAM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M,GAAG,EAAS,CAAA;IACxB,KAAK,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;QACtB,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;YAC3B,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;YACvC,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;YACrE,MAAM,CAAC,YAAY,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAA;QACjC,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
package/dist/react.js ADDED
@@ -0,0 +1,189 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.simplifyChildren = exports.flattenChildren = exports.deepEqual = void 0;
18
+ exports.arePropsEqual = arePropsEqual;
19
+ exports.getRenderedComponent = getRenderedComponent;
20
+ exports.memoize = memoize;
21
+ exports.memoChecker = memoChecker;
22
+ exports.memoBy = memoBy;
23
+ const deep_equal_1 = __importDefault(require("deep-equal"));
24
+ const react_1 = __importDefault(require("react"));
25
+ const types_1 = require("@codeleap/types");
26
+ /** Deep structural equality backed by the `deep-equal` package. */
27
+ exports.deepEqual = deep_equal_1.default;
28
+ /**
29
+ * Checks a specific subset of props for deep equality between two render cycles.
30
+ *
31
+ * `excludeKeys` are deleted from each compared value **in place** before
32
+ * comparison — this mutates the items inside `previous` and `next`.
33
+ * Pass only the keys you want to ignore, and be aware of the side-effect.
34
+ */
35
+ function arePropsEqual(previous, next, options) {
36
+ const { check, excludeKeys = [] } = options;
37
+ for (const c of check) {
38
+ const nextItem = next[c];
39
+ const prevItem = previous[c];
40
+ for (const key of excludeKeys) {
41
+ if (nextItem === null || nextItem === void 0 ? void 0 : nextItem[key])
42
+ delete nextItem[key];
43
+ if (prevItem === null || prevItem === void 0 ? void 0 : prevItem[key])
44
+ delete prevItem[key];
45
+ }
46
+ const propsAreEqual = (0, deep_equal_1.default)(nextItem, prevItem);
47
+ if (!propsAreEqual) {
48
+ return false;
49
+ }
50
+ }
51
+ return true;
52
+ }
53
+ /**
54
+ * Recursively collects a React children tree into a single flat array.
55
+ *
56
+ * Uses `React.Children.toArray` at each level (which assigns stable keys), then
57
+ * follows any `children` prop on the top-level element to continue flattening.
58
+ * Only one level of `props.children` nesting is followed per call — deeply
59
+ * nested component trees (not just wrapper nodes) are not fully unwound.
60
+ */
61
+ const flattenChildren = (children, flat = []) => {
62
+ flat = [...flat, ...react_1.default.Children.toArray(children)];
63
+ if ((children === null || children === void 0 ? void 0 : children.props) && children.props.children) {
64
+ return (0, exports.flattenChildren)(children.props.children, flat);
65
+ }
66
+ return flat;
67
+ };
68
+ exports.flattenChildren = flattenChildren;
69
+ /**
70
+ * Flattens a children tree and strips the `children` prop from each element's
71
+ * props, returning a serialisable summary of the tree.
72
+ *
73
+ * Intended for introspection and testing — not for re-rendering, since `ref`
74
+ * and event-handler functions are preserved as-is.
75
+ */
76
+ const simplifyChildren = (children) => {
77
+ const flat = (0, exports.flattenChildren)(children);
78
+ return flat.map((_a) => {
79
+ var { key, ref, type } = _a, _b = _a.props, { children } = _b, props = __rest(_b, ["children"]);
80
+ return ({
81
+ key, ref, type, props,
82
+ });
83
+ });
84
+ };
85
+ exports.simplifyChildren = simplifyChildren;
86
+ /**
87
+ * Renders a slot that accepts a component, a props object, or a pre-rendered node.
88
+ *
89
+ * Resolution order:
90
+ * 1. If `ComponentOrProps` is a function → render it as `<ComponentOrProps {...props} />`.
91
+ * 2. If it is `null`, `undefined`, or an empty object → return `null`.
92
+ * 3. If it is already a valid React element → return it as-is.
93
+ * 4. Otherwise treat it as a props object and render `<DefaultComponent {...props} {...ComponentOrProps} />`.
94
+ *
95
+ * This lets call sites pass either a component override, extra props, or nothing,
96
+ * without needing separate conditional rendering logic.
97
+ */
98
+ function getRenderedComponent(ComponentOrProps, DefaultComponent, props) {
99
+ const _ComponentOrProps = ComponentOrProps;
100
+ const _DefaultComponent = DefaultComponent;
101
+ if (types_1.TypeGuards.isFunction(ComponentOrProps)) {
102
+ return react_1.default.createElement(_ComponentOrProps, Object.assign({}, props));
103
+ }
104
+ if (types_1.TypeGuards.isNil(ComponentOrProps) || Object.keys(ComponentOrProps).length === 0) {
105
+ return null;
106
+ }
107
+ if (react_1.default.isValidElement(ComponentOrProps)) {
108
+ return ComponentOrProps;
109
+ }
110
+ const _props = ComponentOrProps;
111
+ return react_1.default.createElement(_DefaultComponent, Object.assign({}, props, _props));
112
+ }
113
+ /**
114
+ * Memoizes a React functional component to prevent unnecessary re-renders.
115
+ *
116
+ * This function wraps a React functional component using `React.memo`, which provides
117
+ * a mechanism for memoizing the result of rendering the component. By default, it
118
+ * uses a comparison function that always returns `true`, indicating that the component
119
+ * should not re-render, regardless of prop changes. This behavior essentially freezes
120
+ * the component's rendering until explicitly updated.
121
+ *
122
+ * @template P - The type of the component's props.
123
+ * @param ComponentToMemoize - The React functional component to memoize.
124
+ * @returns A memoized version of the input component (`React.NamedExoticComponent`).
125
+ */
126
+ function memoize(ComponentToMemoize) {
127
+ return react_1.default.memo(ComponentToMemoize, () => true);
128
+ }
129
+ /**
130
+ * Checks whether a specific property in two sets of props is equal.
131
+ *
132
+ * This function compares the value of a given property (`prop`) between two objects
133
+ * (`prevProps` and `nextProps`) using a deep equality check (`equals`).
134
+ *
135
+ * @template P - The type of the props object.
136
+ * @param prop - The key of the property to compare.
137
+ * @param prevProps - The previous props object.
138
+ * @param nextProps - The next props object.
139
+ * @returns `true` if the values of the specified property are deeply equal; otherwise, `false`.
140
+ */
141
+ function memoChecker(prop, prevProps, nextProps) {
142
+ const nextItem = nextProps[prop];
143
+ const prevItem = prevProps[prop];
144
+ return (0, deep_equal_1.default)(nextItem, prevItem);
145
+ }
146
+ /**
147
+ * Memoizes a React functional component based on specific props.
148
+ *
149
+ * This function wraps a React functional component using `React.memo` with a custom comparison
150
+ * function. The comparison function checks if the specified properties (passed as `check`)
151
+ * remain equal between renders. If all specified properties are equal, the component will not re-render.
152
+ *
153
+ * @template P - The type of the component's props.
154
+ * @param ComponentToMemoize - The React functional component to memoize.
155
+ * @param check - A single property key or an array of property keys to compare for memoization.
156
+ * @returns A memoized version of the input component (`React.NamedExoticComponent`).
157
+ *
158
+ * @example
159
+ * import React from 'react';
160
+ * import { memoBy } from './utils';
161
+ *
162
+ * const MyComponent: React.FC<{ name: string; age: number }> = ({ name, age }) => {
163
+ * console.log('Rendering MyComponent...');
164
+ * return (
165
+ * <div>
166
+ * {name}, {age}
167
+ * </div>
168
+ * );
169
+ * };
170
+ *
171
+ * // Memoize the component based on the `name` prop.
172
+ * const MemoizedByName = memoBy(MyComponent, 'name');
173
+ *
174
+ * // Memoize the component based on both `name` and `age` props.
175
+ * const MemoizedByNameAndAge = memoBy(MyComponent, ['name', 'age']);
176
+ *
177
+ * export { MemoizedByName, MemoizedByNameAndAge };
178
+ *
179
+ * // Usage in a parent component
180
+ * <MemoizedByName name="Alice" age={25} />;
181
+ * <MemoizedByNameAndAge name="Alice" age={25} />;
182
+ */
183
+ function memoBy(ComponentToMemoize, check) {
184
+ return react_1.default.memo(ComponentToMemoize, (prevProps, nextProps) => {
185
+ const checks = Array.isArray(check) ? check : [check];
186
+ return checks.every((key) => memoChecker(key, prevProps, nextProps));
187
+ });
188
+ }
189
+ //# sourceMappingURL=react.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.js","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAmBA,sCAwBC;AAyDD,oDAuBC;AAeD,0BAEC;AAcD,kCAKC;AAuCD,wBAQC;AA9MD,4DAA+B;AAC/B,kDAAyB;AACzB,2CAA4C;AAE5C,mEAAmE;AACtD,QAAA,SAAS,GAAG,oBAAM,CAAA;AAO/B;;;;;;GAMG;AACH,SAAgB,aAAa,CAC3B,QAAW,EACX,IAAO,EACP,OAAoC;IAEpC,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,EAAE,EAAE,GAAG,OAAO,CAAA;IAE3C,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;QACtB,MAAM,QAAQ,GAAI,IAAY,CAAC,CAAW,CAAC,CAAA;QAC3C,MAAM,QAAQ,GAAI,QAAgB,CAAC,CAAW,CAAC,CAAA;QAE/C,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;YAC9B,IAAI,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAG,GAAG,CAAC;gBAAE,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAA;YACzC,IAAI,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAG,GAAG,CAAC;gBAAE,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAA;QAC3C,CAAC;QAED,MAAM,aAAa,GAAG,IAAA,oBAAM,EAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;QAEhD,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC;AAED;;;;;;;GAOG;AACI,MAAM,eAAe,GAAG,CAAC,QAAa,EAAE,OAA0B,EAAE,EAAqB,EAAE;IAChG,IAAI,GAAG,C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perty(exports, "__esModule", { value: true });
3
+ exports.singleLine = singleLine;
4
+ exports.stringiparse = stringiparse;
5
+ exports.capitalize = capitalize;
6
+ exports.isUppercase = isUppercase;
7
+ exports.isLowercase = isLowercase;
8
+ exports.humanizeCamelCase = humanizeCamelCase;
9
+ exports.ellipsis = ellipsis;
10
+ /** Collapses all newline characters in `text` to single spaces. */
11
+ function singleLine(text) {
12
+ return text === null || text === void 0 ? void 0 : text.replace(/\n/g, ' ');
13
+ }
14
+ /**
15
+ * Round-trips a value through `JSON.stringify` → `JSON.parse`.
16
+ *
17
+ * Strips non-serialisable properties (functions, `undefined`, class instances)
18
+ * and produces a plain-object clone. Throws if the value contains circular
19
+ * references.
20
+ */
21
+ function stringiparse(string) {
22
+ return JSON.parse(JSON.stringify(string));
23
+ }
24
+ /**
25
+ * Changes only the first character of `str`.
26
+ *
27
+ * When `reverse` is `true` the first character is lowercased instead of
28
+ * uppercased — useful for converting PascalCase to camelCase.
29
+ */
30
+ function capitalize(str, reverse = false) {
31
+ if (!str.length)
32
+ return str;
33
+ const firstChar = reverse ? str[0].toLowerCase() : str[0].toUpperCase();
34
+ return firstChar + str.substring(1);
35
+ }
36
+ /**
37
+ * Returns `true` if `char` is an uppercase Latin or extended Latin character.
38
+ *
39
+ * Covers the Unicode range `U+0080`–`U+024F` in addition to `A–Z`, so
40
+ * accented capitals (e.g. `É`, `Ñ`) are recognised correctly.
41
+ */
42
+ function isUppercase(char) {
43
+ return /[A-Z]|[\u0080-\u024F]/.test(char) && char.toUpperCase() === char;
44
+ }
45
+ /** Returns `true` when `char` is **not** considered uppercase by {@link isUppercase}. */
46
+ function isLowercase(char) {
47
+ return !isUppercase(char);
48
+ }
49
+ /**
50
+ * Converts a camelCase or PascalCase identifier to a space-separated, title-cased string.
51
+ *
52
+ * A space is inserted before each uppercase letter that is immediately preceded
53
+ * by a lowercase letter. The first character is always uppercased.
54
+ * Consecutive uppercase runs (e.g. acronyms like "URL") are not split.
55
+ */
56
+ function humanizeCamelCase(str) {
57
+ const characters = [];
58
+ let previousCharacter = '';
59
+ str.split('').forEach((char, idx) => {
60
+ if (idx === 0) {
61
+ characters.push(char.toUpperCase());
62
+ }
63
+ else {
64
+ if (isUppercase(char) && isLowercase(previousCharacter)) {
65
+ characters.push(` ${char}`);
66
+ }
67
+ else {
68
+ characters.push(char);
69
+ }
70
+ }
71
+ previousCharacter = char;
72
+ });
73
+ return characters.join('');
74
+ }
75
+ /**
76
+ * Truncates `str` to `maxLen` characters, appending `'...'` when truncation occurs.
77
+ *
78
+ * The three dots count toward `maxLen`, so the returned string never exceeds
79
+ * `maxLen` characters when truncated. Strings already at or below `maxLen` are
80
+ * returned unchanged.
81
+ */
82
+ function ellipsis(str, maxLen) {
83
+ if (str.length - 3 > maxLen) {
84
+ return str.slice(0, maxLen - 3) + '...';
85
+ }
86
+ return str;
87
+ }
88
+ //# sourceMappingURL=string.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.js","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":";;AACA,gCAEC;AASD,oCAEC;AAQD,gCAIC;AAQD,kCAEC;AAGD,kCAEC;AASD,8CAkBC;AASD,4BAMC;AAnFD,mEAAmE;AACnE,SAAgB,UAAU,CAAC,IAAY;IACrC,OAAO,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;AAClC,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,YAAY,CAAC,MAAc;IACzC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAA;AAC3C,CAAC;AAED;;;;;GAKG;AACH,SAAgB,UAAU,CAAC,GAAW,EAAE,OAAO,GAAG,KAAK;IACrD,IAAI,CAAC,GAAG,CAAC,MAAM;QAAE,OAAO,GAAG,CAAA;IAC3B,MAAM,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC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G,CAAC,GAAG,MAAM,EAAE,CAAC;QAC5B,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,KAAK,CAAA;IACzC,CAAC;IAED,OAAO,GAAG,CAAA;AACZ,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@codeleap/utils",
3
- "version": "7.0.0",
4
- "main": "src/index.ts",
3
+ "version": "7.0.2",
4
+ "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "exports": {
7
7
  ".": {
@@ -22,8 +22,8 @@
22
22
  "directory": "packages/utils"
23
23
  },
24
24
  "devDependencies": {
25
- "@codeleap/config": "7.0.0",
26
- "@codeleap/types": "7.0.0",
25
+ "@codeleap/config": "7.0.1",
26
+ "@codeleap/types": "7.0.1",
27
27
  "ts-node-dev": "1.1.8"
28
28
  },
29
29
  "scripts": {
@@ -31,7 +31,7 @@
31
31
  "typecheck": "bun tsc --noEmit -p ./tsconfig.json"
32
32
  },
33
33
  "peerDependencies": {
34
- "@codeleap/types": "7.0.0",
34
+ "@codeleap/types": "7.0.1",
35
35
  "axios": "^1.7.9",
36
36
  "dayjs": "1.11.18",
37
37
  "typescript": "6.0.3",