@codeleap/utils 6.8.0 → 7.0.1
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 +60 -0
- package/dist/array.js.map +1 -0
- package/dist/cloneDeep.js +44 -0
- package/dist/cloneDeep.js.map +1 -0
- package/dist/colors.js +57 -0
- package/dist/colors.js.map +1 -0
- package/dist/date.js +26 -0
- package/dist/date.js.map +1 -0
- package/dist/faker.js +43 -0
- package/dist/faker.js.map +1 -0
- package/dist/file.js +26 -0
- package/dist/file.js.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/locale.js +18 -0
- package/dist/locale.js.map +1 -0
- package/dist/misc.js +150 -0
- package/dist/misc.js.map +1 -0
- package/dist/object.js +189 -0
- package/dist/object.js.map +1 -0
- package/dist/react.js +176 -0
- package/dist/react.js.map +1 -0
- package/dist/string.js +79 -0
- package/dist/string.js.map +1 -0
- package/package.json +5 -5
package/dist/array.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Indexes an array into an object keyed by a derived value.
|
|
3
|
+
*
|
|
4
|
+
* `keyAccessor` may be a property name string or a callback that returns a
|
|
5
|
+
* key. When omitted, array indices are used as keys. Duplicate keys silently
|
|
6
|
+
* overwrite earlier entries.
|
|
7
|
+
*/
|
|
8
|
+
export function objectFromArray(arr, keyAccessor) {
|
|
9
|
+
let getObjectKey = (_, idx) => idx;
|
|
10
|
+
if (keyAccessor) {
|
|
11
|
+
switch (typeof keyAccessor) {
|
|
12
|
+
case 'string':
|
|
13
|
+
getObjectKey = (value) => value[keyAccessor];
|
|
14
|
+
break;
|
|
15
|
+
case 'function':
|
|
16
|
+
getObjectKey = keyAccessor;
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const indexedMap = arr.map((value, idx) => [getObjectKey(value, idx), value]);
|
|
21
|
+
return Object.fromEntries(indexedMap);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Returns a deduplicated copy of `array` where uniqueness is determined by
|
|
25
|
+
* the value returned from `getProperty`.
|
|
26
|
+
*
|
|
27
|
+
* When duplicates exist, the **last** occurrence wins because `objectFromArray`
|
|
28
|
+
* overwrites earlier entries with the same key.
|
|
29
|
+
*/
|
|
30
|
+
export function uniqueArrayByProperty(array, getProperty) {
|
|
31
|
+
return Object.values(objectFromArray(array, getProperty));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Recursively flattens a nested array of arbitrary depth into a single-level array.
|
|
35
|
+
*
|
|
36
|
+
* Unlike `Array.prototype.flat(Infinity)`, this implementation does not rely on
|
|
37
|
+
* native flat support and works identically across all environments.
|
|
38
|
+
*/
|
|
39
|
+
export function flatten(arr) {
|
|
40
|
+
let newArr = [];
|
|
41
|
+
arr.forEach((item) => {
|
|
42
|
+
if (Array.isArray(item)) {
|
|
43
|
+
newArr = [...newArr, ...flatten(item)];
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
newArr.push(item);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return newArr;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Returns an inclusive integer array from `start` to `end`.
|
|
53
|
+
*
|
|
54
|
+
* Both bounds are included: `range(1, 3)` → `[1, 2, 3]`.
|
|
55
|
+
*/
|
|
56
|
+
export function range(start, end) {
|
|
57
|
+
const length = end - start + 1;
|
|
58
|
+
return Array.from({ length }, (_, index) => index + start);
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=array.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array.js","sourceRoot":"","sources":["../src/array.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAC7B,GAAQ,EACR,WAAoB;IAEpB,IAAI,YAAY,GAA+C,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,CAAA;I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C,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,KAAK,CAAC,CAAA;AAC5D,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
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 function cloneDeep(value) {
|
|
10
|
+
if (value === null || typeof value !== 'object') {
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
if (Array.isArray(value)) {
|
|
14
|
+
return value.map(cloneDeep);
|
|
15
|
+
}
|
|
16
|
+
if (value instanceof Date) {
|
|
17
|
+
return new Date(value.getTime());
|
|
18
|
+
}
|
|
19
|
+
if (value instanceof Map) {
|
|
20
|
+
const clonedMap = new Map();
|
|
21
|
+
value.forEach((v, k) => {
|
|
22
|
+
clonedMap.set(k, cloneDeep(v));
|
|
23
|
+
});
|
|
24
|
+
return clonedMap;
|
|
25
|
+
}
|
|
26
|
+
if (value instanceof Set) {
|
|
27
|
+
const clonedSet = new Set();
|
|
28
|
+
value.forEach((v) => {
|
|
29
|
+
clonedSet.add(cloneDeep(v));
|
|
30
|
+
});
|
|
31
|
+
return clonedSet;
|
|
32
|
+
}
|
|
33
|
+
if (value instanceof RegExp) {
|
|
34
|
+
return new RegExp(value.source, value.flags);
|
|
35
|
+
}
|
|
36
|
+
const clonedObj = {};
|
|
37
|
+
for (const key in value) {
|
|
38
|
+
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
39
|
+
clonedObj[key] = cloneDeep(value[key]);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return clonedObj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AE,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,57 @@
|
|
|
1
|
+
import tinycolor from 'tinycolor2';
|
|
2
|
+
import { TypeGuards } from '@codeleap/types';
|
|
3
|
+
/**
|
|
4
|
+
* Parses a 6-digit hex colour string (with or without leading `#`) into its
|
|
5
|
+
* `{ r, g, b }` components.
|
|
6
|
+
*
|
|
7
|
+
* Returns `null` for invalid or short (3-digit) hex values.
|
|
8
|
+
*/
|
|
9
|
+
export function hexToRgb(hex) {
|
|
10
|
+
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
11
|
+
return result
|
|
12
|
+
? {
|
|
13
|
+
r: parseInt(result[1], 16),
|
|
14
|
+
g: parseInt(result[2], 16),
|
|
15
|
+
b: parseInt(result[3], 16),
|
|
16
|
+
}
|
|
17
|
+
: null;
|
|
18
|
+
}
|
|
19
|
+
const shadeColorCache = {};
|
|
20
|
+
/**
|
|
21
|
+
* Lightens or darkens `color` by `percent` and optionally applies `opacity`,
|
|
22
|
+
* returning an `rgba(...)` string.
|
|
23
|
+
*
|
|
24
|
+
* - Positive `percent` → lighten; negative → darken (magnitude is used).
|
|
25
|
+
* - `opacity` must be in the `0–1` range (passed directly to tinycolor's `setAlpha`).
|
|
26
|
+
* - Results are memoised in a module-level cache keyed by the serialised parameters,
|
|
27
|
+
* so repeated calls with identical arguments are effectively free.
|
|
28
|
+
*/
|
|
29
|
+
export function shadeColor(color, percent = 0, opacity = null) {
|
|
30
|
+
const _color = color.trim();
|
|
31
|
+
const serialParams = [_color, percent.toString()];
|
|
32
|
+
if (TypeGuards.isNumber(opacity)) {
|
|
33
|
+
serialParams.push(opacity.toString());
|
|
34
|
+
}
|
|
35
|
+
const cacheKey = serialParams.join('/');
|
|
36
|
+
if (!!shadeColorCache[cacheKey]) {
|
|
37
|
+
return shadeColorCache[cacheKey];
|
|
38
|
+
}
|
|
39
|
+
const cl = tinycolor(_color);
|
|
40
|
+
if (percent !== 0) {
|
|
41
|
+
const shouldDarken = percent < 0;
|
|
42
|
+
if (shouldDarken) {
|
|
43
|
+
cl.darken(-percent);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
cl.lighten(percent);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (TypeGuards.isNumber(opacity)) {
|
|
50
|
+
cl.setAlpha(opacity);
|
|
51
|
+
}
|
|
52
|
+
const rgbObj = cl.toRgb();
|
|
53
|
+
const rgbStr = `rgba(${rgbObj.r},${rgbObj.g},${rgbObj.b},${rgbObj.a})`;
|
|
54
|
+
shadeColorCache[cacheKey] = rgbStr;
|
|
55
|
+
return rgbStr;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=colors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colors.js","sourceRoot":"","sources":["../src/colors.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE5C;;;;;GAKG;AACH,MAAM,UAAU,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,EAA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IAEtB,CAAC;IAED,MAAM,MAAM,GAAG,EAAE,CAAC,KAAK,EAAE,CAAA;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,26 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
const removeTimezoneAndFormat = (date, format = 'YYYY-MM-DD') => {
|
|
3
|
+
if (!date)
|
|
4
|
+
return '';
|
|
5
|
+
let normalizedDate = date;
|
|
6
|
+
if (date instanceof Date) {
|
|
7
|
+
normalizedDate = date.toISOString().split('T')[0] + 'T12:00:00';
|
|
8
|
+
}
|
|
9
|
+
else if (typeof date === 'string' && date.includes('T')) {
|
|
10
|
+
normalizedDate = date.split('T')[0] + 'T12:00:00';
|
|
11
|
+
}
|
|
12
|
+
return dayjs(normalizedDate).startOf('day').format(format);
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Date helpers that normalise timezone-sensitive values before formatting.
|
|
16
|
+
*
|
|
17
|
+
* - `removeTimezoneAndFormat(date, format?)` — strips the time component from
|
|
18
|
+
* a `Date` or ISO string, anchors it to noon local time, then formats with
|
|
19
|
+
* dayjs. This prevents off-by-one-day errors that occur when UTC midnight
|
|
20
|
+
* falls on a different calendar day in the user's timezone. Returns `''` for
|
|
21
|
+
* falsy input.
|
|
22
|
+
*/
|
|
23
|
+
export const dateUtils = {
|
|
24
|
+
removeTimezoneAndFormat,
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=date.js.map
|
package/dist/date.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.js","sourceRoot":"","sources":["../src/date.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;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,KAAK,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;AAC5D,CAAC,CAAA;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,uBAAuB;CACxB,CAAA"}
|
package/dist/faker.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const names = [
|
|
2
|
+
'James', 'John', 'Robert', 'Michael', 'William', 'David', 'Richard', 'Joseph', 'Thomas',
|
|
3
|
+
'Charles', 'Christopher', 'Daniel', 'Matthew', 'Anthony', 'Donald', 'Mark', 'Paul', 'Steven',
|
|
4
|
+
'Andrew', 'Kenneth', 'Joshua', 'Kevin', 'Brian', 'George', 'Edward', 'Ronald', 'Timothy',
|
|
5
|
+
'Jason', 'Jeffrey', 'Ryan', 'Gary', 'Jacob'
|
|
6
|
+
];
|
|
7
|
+
const surnames = [
|
|
8
|
+
'Smith', 'Johnson', 'Williams', 'Brown', 'Jones', 'Garcia', 'Miller', 'Davis',
|
|
9
|
+
'Lopez', 'Wilson', 'Anderson', 'Thomas', 'Taylor', 'Moore',
|
|
10
|
+
'Jackson', 'Martin', 'Lee', 'Perez', 'Thompson', 'White', 'Harris', 'Sanchez', 'Clark',
|
|
11
|
+
'Ramirez', 'Lewis', 'Robinson', 'Walker', 'Young', 'Allen', 'King', 'Wright', 'Scott', 'Torres',
|
|
12
|
+
];
|
|
13
|
+
const animals = [
|
|
14
|
+
'lion', 'tiger', 'zebra', 'panda', 'koala', 'bear',
|
|
15
|
+
'wolf', 'fox', 'rabbit', 'bat', 'spider', 'frog', 'shark'
|
|
16
|
+
];
|
|
17
|
+
function getRandom(list) {
|
|
18
|
+
return list[Math.floor(Math.random() * list.length)];
|
|
19
|
+
}
|
|
20
|
+
function number(min = 0, max = 100) {
|
|
21
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Lightweight in-house fixture-data generator with no external dependencies.
|
|
25
|
+
*
|
|
26
|
+
* Provided methods:
|
|
27
|
+
* - `firstName()` / `lastName()` — random entries from hard-coded name lists.
|
|
28
|
+
* - `name()` — space-joined first + last name.
|
|
29
|
+
* - `animal()` — random animal name.
|
|
30
|
+
* - `number(min?, max?)` — random integer in `[min, max]` (default 0–100).
|
|
31
|
+
*
|
|
32
|
+
* All selections use `Math.random`, so results are not reproducible across calls.
|
|
33
|
+
* Use this instead of heavy faker libraries in tests or seed scripts where the
|
|
34
|
+
* small vocabulary is sufficient.
|
|
35
|
+
*/
|
|
36
|
+
export const faker = {
|
|
37
|
+
lastName: () => getRandom(surnames),
|
|
38
|
+
firstName: () => getRandom(names),
|
|
39
|
+
animal: () => getRandom(animals),
|
|
40
|
+
number,
|
|
41
|
+
name: () => `${getRandom(names)} ${getRandom(surnames)}`
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=faker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"faker.js","sourceRoot":"","sources":["../src/faker.ts"],"names":[],"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,CAAC;AAED,SAAS,MAAM,CAAC,MAAc,CAAC,EAAE,MAAc,GAAG;IAChD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAA;AAC1D,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,QAAQ,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC;IACnC,SAAS,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC;IACjC,MAAM,EAAE,GAAG,EAAE,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,26 @@
|
|
|
1
|
+
const separators = /[\\\/]+/;
|
|
2
|
+
/**
|
|
3
|
+
* Splits a file system path into its directory, base name, and extension.
|
|
4
|
+
*
|
|
5
|
+
* Both `/` and `\` are treated as separators, so Windows and POSIX paths are
|
|
6
|
+
* handled uniformly. Files without an extension return an empty string for
|
|
7
|
+
* `extension`. The returned `path` is always joined with `/` regardless of the
|
|
8
|
+
* original separator.
|
|
9
|
+
*/
|
|
10
|
+
export function parseFilePathData(path) {
|
|
11
|
+
const parts = path.split(separators);
|
|
12
|
+
const lastPart = parts[parts.length - 1];
|
|
13
|
+
let fileName = lastPart;
|
|
14
|
+
let ext = '';
|
|
15
|
+
if (lastPart.includes('.')) {
|
|
16
|
+
const dotIdx = fileName.lastIndexOf('.');
|
|
17
|
+
fileName = fileName.substring(0, dotIdx);
|
|
18
|
+
ext = lastPart.substring(dotIdx + 1);
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
path: parts.slice(0, -1).join('/'),
|
|
22
|
+
extension: ext,
|
|
23
|
+
name: fileName,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=file.js.map
|
package/dist/file.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.js","sourceRoot":"","sources":["../src/file.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,GAAG,SAAS,CAAA;AAE5B;;;;;;;GAOG;AACH,MAAM,UAAU,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,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.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","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"}
|
package/dist/locale.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds the closest matching key in `languageDictionary` for a given `locale`.
|
|
3
|
+
*
|
|
4
|
+
* Matching uses only the first two characters (the language subtag), so `'en-AU'`
|
|
5
|
+
* will match an `'en-US'` dictionary key. Returns `defaultLocale` when no
|
|
6
|
+
* partial match exists.
|
|
7
|
+
*/
|
|
8
|
+
export function getSimilarLocale(locale, defaultLocale, languageDictionary) {
|
|
9
|
+
const inputFirstPart = locale.substring(0, 2);
|
|
10
|
+
const keys = Object.keys(languageDictionary);
|
|
11
|
+
for (const key of keys) {
|
|
12
|
+
const keyFirstPart = key.substring(0, 2);
|
|
13
|
+
if (inputFirstPart === keyFirstPart)
|
|
14
|
+
return key;
|
|
15
|
+
}
|
|
16
|
+
return defaultLocale;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=locale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locale.js","sourceRoot":"","sources":["../src/locale.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,UAAU,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,150 @@
|
|
|
1
|
+
import { capitalize } from './string';
|
|
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 function imagePathToFileObject(imagePath) {
|
|
10
|
+
const parts = imagePath ? imagePath.split('.') : '';
|
|
11
|
+
const ext = imagePath ? parts[parts.length - 1].toLowerCase() : '';
|
|
12
|
+
const fileValue = imagePath
|
|
13
|
+
? {
|
|
14
|
+
uri: imagePath,
|
|
15
|
+
name: 'image_' + imagePath,
|
|
16
|
+
type: `image/${ext}`,
|
|
17
|
+
}
|
|
18
|
+
: null;
|
|
19
|
+
return fileValue;
|
|
20
|
+
}
|
|
21
|
+
const letterToColorMap = {
|
|
22
|
+
a: '#7CB9E8',
|
|
23
|
+
b: '#3a9e77',
|
|
24
|
+
c: '#A3C1AD',
|
|
25
|
+
d: '#E1BD27',
|
|
26
|
+
e: '#badc58',
|
|
27
|
+
f: '#db5970',
|
|
28
|
+
g: '#9b8ef1',
|
|
29
|
+
h: '#ffe169',
|
|
30
|
+
i: '#3ea9d1',
|
|
31
|
+
j: '#8aa341',
|
|
32
|
+
k: '#baf2f5',
|
|
33
|
+
l: '#ffa02d',
|
|
34
|
+
m: '#d46830',
|
|
35
|
+
n: '#62ecaa',
|
|
36
|
+
o: '#ffbe50',
|
|
37
|
+
p: '#0078D7',
|
|
38
|
+
q: '#8764B8',
|
|
39
|
+
r: '#52dd64',
|
|
40
|
+
s: '#7edce9',
|
|
41
|
+
t: '#dadd5d',
|
|
42
|
+
u: '#e9b55d',
|
|
43
|
+
v: '#99d669',
|
|
44
|
+
w: '#a3c83a',
|
|
45
|
+
x: '#f28d67',
|
|
46
|
+
y: '#ea82ec',
|
|
47
|
+
z: '#ff8295',
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Maps the first character of `anyString` to a deterministic colour for use in
|
|
51
|
+
* avatar placeholders.
|
|
52
|
+
*
|
|
53
|
+
* Lookup is case-insensitive. Returns `'#999999'` for empty, undefined, or
|
|
54
|
+
* characters not in the `a–z` range.
|
|
55
|
+
*/
|
|
56
|
+
export function matchInitialToColor(anyString) {
|
|
57
|
+
if (!anyString)
|
|
58
|
+
return '#999999';
|
|
59
|
+
return letterToColorMap[anyString.toLowerCase().charAt(0)] || '#999999';
|
|
60
|
+
}
|
|
61
|
+
/** Returns a Promise that resolves after `ms` milliseconds. */
|
|
62
|
+
export function waitFor(ms) {
|
|
63
|
+
return new Promise((resolve) => {
|
|
64
|
+
setTimeout(() => {
|
|
65
|
+
resolve();
|
|
66
|
+
}, ms);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
export function parseSourceUrl(args, Settings) {
|
|
70
|
+
if (!args)
|
|
71
|
+
return null;
|
|
72
|
+
let res = '';
|
|
73
|
+
let address = '';
|
|
74
|
+
if (typeof args === 'string') {
|
|
75
|
+
address = args;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
address = args.source || args.src || '';
|
|
79
|
+
}
|
|
80
|
+
if (address && address.startsWith('/media/')) {
|
|
81
|
+
const tmp = address.substr(1, address.length);
|
|
82
|
+
res = `${Settings.BaseURL}${tmp}`;
|
|
83
|
+
}
|
|
84
|
+
else if (address) {
|
|
85
|
+
res = address;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
res = `https://picsum.photos/600?random=${Math.random() * 100}`;
|
|
89
|
+
}
|
|
90
|
+
return res;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Extracts style entries from a variant styles map whose keys begin with `match`,
|
|
94
|
+
* returning them as a new object with the prefix stripped and the first
|
|
95
|
+
* remaining character lowercased.
|
|
96
|
+
*
|
|
97
|
+
* Used internally by component style systems to pull out sub-part styles
|
|
98
|
+
* (e.g. `inputLabel`, `inputWrapper`) into their own namespaced objects.
|
|
99
|
+
*/
|
|
100
|
+
export function getNestedStylesByKey(match, variantStyles) {
|
|
101
|
+
const styles = {};
|
|
102
|
+
for (const [key, value] of Object.entries(variantStyles)) {
|
|
103
|
+
if (key.startsWith(match)) {
|
|
104
|
+
const partName = capitalize(key.replace(match, ''), true);
|
|
105
|
+
styles[partName] = value;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return styles;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Heuristically detects whether the app has been React Fast Refreshed since
|
|
112
|
+
* initial launch.
|
|
113
|
+
*
|
|
114
|
+
* Compares the elapsed time since `Settings.Environment.InitTime` against a
|
|
115
|
+
* 1-second threshold. Fast Refresh typically completes well under 1 second from
|
|
116
|
+
* app start; anything longer suggests a subsequent refresh rather than cold boot.
|
|
117
|
+
* Returns `undefined` and logs a warning when `InitTime` is not set.
|
|
118
|
+
*/
|
|
119
|
+
export function hasFastRefreshed(Settings) {
|
|
120
|
+
var _a;
|
|
121
|
+
if ((_a = Settings === null || Settings === void 0 ? void 0 : Settings.Environment) === null || _a === void 0 ? void 0 : _a.InitTime) {
|
|
122
|
+
const timeFromStartup = (new Date()).getTime() - Settings.Environment.InitTime.getTime();
|
|
123
|
+
// 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
|
|
124
|
+
const fastRefreshed = Settings.Environment.IsDev && timeFromStartup > 1000;
|
|
125
|
+
return fastRefreshed;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
console.log('hasFreshRefreshed() => Missing datetime from settings, please include to make this work');
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const throttleTimerId = {};
|
|
133
|
+
/**
|
|
134
|
+
* Leading-edge throttle keyed by a `ref` identifier rather than by function reference.
|
|
135
|
+
*
|
|
136
|
+
* `func` is called immediately on the first invocation for a given `ref`; subsequent
|
|
137
|
+
* calls with the same `ref` are dropped until `delay` milliseconds have elapsed.
|
|
138
|
+
* Using a string/number `ref` allows multiple independent throttle timers to coexist
|
|
139
|
+
* in a single module without needing to hold separate timer handles.
|
|
140
|
+
*/
|
|
141
|
+
export function throttle(func, ref, delay) {
|
|
142
|
+
if (throttleTimerId[ref]) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
throttleTimerId[ref] = setTimeout(function () {
|
|
146
|
+
func();
|
|
147
|
+
throttleTimerId[ref] = undefined;
|
|
148
|
+
}, delay);
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=misc.js.map
|
package/dist/misc.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../src/misc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAGrC;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,SAAwB;IAC5D,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IAEnD,MAAM,GAAG,GAAG,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IAElE,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AAC,KAAK,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,CAAA;YACzD,MAAM,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAA;QAC1B,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAa;;IAC5C,IAAI,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,WAAW,0CAAE,QAAQ,EAAE,CAAC;QACpC,MAAM,eAAe,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,GAAG,QAAQ,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAA;QACxF,2IAA2I;QAC3I,MAAM,aAAa,GAAG,QAAQ,CAAC,WAAW,CAAC,KAAK,IAAI,eAAe,GAAG,IAAI,CAAA;QAC1E,OAAO,aAAa,CAAA;IACtB,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,yFAAyF,CAAC,CAAA;QACtG,OAAO,SAAS,CAAA;IAClB,CAAC;AACH,CAAC;AAED,MAAM,eAAe,GAAuE,EAAE,CAAA;AAE9F;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAgB,EAAE,GAAoB,EAAE,KAAa;IAC5E,IAAI,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC;QACzB,OAAM;IACR,CAAC;IAED,eAAe,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC;QAChC,IAAI,EAAE,CAAA;QACN,eAAe,CAAC,GAAG,CAAC,GAAG,SAAS,CAAA;IAClC,CAAC,EAAE,KAAK,CAAC,CAAA;AACX,CAAC"}
|
package/dist/object.js
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively merges `changes` into `base`, deep-merging nested plain objects.
|
|
3
|
+
*
|
|
4
|
+
* Arrays and `Date` instances are treated as scalar values — they replace rather
|
|
5
|
+
* than merge. If `changes` is not iterable, it is returned as-is.
|
|
6
|
+
*/
|
|
7
|
+
export function deepMerge(base = {}, changes = {}) {
|
|
8
|
+
const obj = Object.assign({}, base);
|
|
9
|
+
let changeEntries = [];
|
|
10
|
+
try {
|
|
11
|
+
changeEntries = Object.entries(changes);
|
|
12
|
+
}
|
|
13
|
+
catch (e) {
|
|
14
|
+
return changes;
|
|
15
|
+
}
|
|
16
|
+
for (const [key, value] of changeEntries) {
|
|
17
|
+
obj[key] =
|
|
18
|
+
typeof value === 'object' && !Array.isArray(value) && !(value instanceof Date)
|
|
19
|
+
? deepMerge(obj[key], changes[key])
|
|
20
|
+
: value;
|
|
21
|
+
}
|
|
22
|
+
return obj;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Like `Array.prototype.map` but over an object's entries.
|
|
26
|
+
*
|
|
27
|
+
* Returns an array — not a new object — so it is useful when you need to
|
|
28
|
+
* transform key-value pairs into arbitrary values (e.g. JSX elements).
|
|
29
|
+
*/
|
|
30
|
+
export function mapObject(obj, callback) {
|
|
31
|
+
return Object.entries(obj).map((args) => callback(args));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Sets a value at an arbitrarily deep dot-separated `path`, mutating `base` in place
|
|
35
|
+
* and returning it.
|
|
36
|
+
*
|
|
37
|
+
* Numeric path segments are coerced to array indices when the current node is an array.
|
|
38
|
+
*/
|
|
39
|
+
export const deepSet = (base = {}, path, value) => {
|
|
40
|
+
const keys = path.split('.');
|
|
41
|
+
const obj = base;
|
|
42
|
+
let thisKey = keys[0];
|
|
43
|
+
if (Array.isArray(base)) {
|
|
44
|
+
thisKey = Number(thisKey);
|
|
45
|
+
}
|
|
46
|
+
obj[thisKey] = keys.length === 1 ? value : deepSet(obj[thisKey], keys.slice(1).join('.'), value);
|
|
47
|
+
return obj;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Reads a value from `obj` at a dot-separated `path`.
|
|
51
|
+
*
|
|
52
|
+
* Returns `undefined` (without throwing) when any intermediate node is absent,
|
|
53
|
+
* because property access on `undefined` propagates silently through the loop.
|
|
54
|
+
*/
|
|
55
|
+
export const deepGet = (path, obj) => {
|
|
56
|
+
const parts = path.split('.');
|
|
57
|
+
let newObj = Object.assign({}, obj);
|
|
58
|
+
for (const prop of parts) {
|
|
59
|
+
newObj = newObj[prop];
|
|
60
|
+
}
|
|
61
|
+
return newObj;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Returns every dot-separated leaf path in a nested object.
|
|
65
|
+
*
|
|
66
|
+
* Array values are treated as leaves — their indices are not traversed.
|
|
67
|
+
*/
|
|
68
|
+
export function objectPaths(obj) {
|
|
69
|
+
let paths = [];
|
|
70
|
+
Object.entries(obj).forEach(([key, value]) => {
|
|
71
|
+
if (!Array.isArray(value) && typeof value === 'object') {
|
|
72
|
+
paths = [...paths, ...objectPaths(value).map((k) => `${key}.${k}`)];
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
paths.push(key);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
return paths;
|
|
79
|
+
}
|
|
80
|
+
/** Returns `true` only for `string`, `number`, and `boolean` — `null`, `undefined`, and objects are excluded. */
|
|
81
|
+
export function isValuePrimitive(a) {
|
|
82
|
+
return ['string', 'number', 'boolean'].includes(typeof a);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Inline ternary helper for spread-merging optional style or prop objects.
|
|
86
|
+
*
|
|
87
|
+
* Intended for use inside object spreads where the ternary would otherwise
|
|
88
|
+
* require wrapping: `{ ...optionalObject(flag, trueProps, {}) }`.
|
|
89
|
+
*/
|
|
90
|
+
export function optionalObject(condition, ifTrue, ifFalse) {
|
|
91
|
+
return condition ? ifTrue : ifFalse;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Depth-first walk over a nested object, invoking `callback` at each node.
|
|
95
|
+
*
|
|
96
|
+
* The callback receives metadata about each visited node (`path`, `depth`,
|
|
97
|
+
* `key`, `type`, `primitive`). Primitive leaves fire the callback once; object
|
|
98
|
+
* nodes fire it for each child before recursing into it. Returning `{ stop: true }`
|
|
99
|
+
* from the callback is accepted by the type but **does not halt traversal** —
|
|
100
|
+
* the implementation does not check the return value.
|
|
101
|
+
*/
|
|
102
|
+
export function traverse(obj = {}, callback, args) {
|
|
103
|
+
const isPrimitive = isValuePrimitive(obj);
|
|
104
|
+
const info = Object.assign({ path: [], depth: 0, key: '', type: typeof obj, value: obj, primitive: isPrimitive }, args);
|
|
105
|
+
if (isPrimitive) {
|
|
106
|
+
callback(Object.assign(Object.assign({}, info), { depth: info.depth }));
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
for (const [key, value] of Object.entries(obj || {})) {
|
|
110
|
+
const isPrimitive = isValuePrimitive(value);
|
|
111
|
+
if (!isPrimitive) {
|
|
112
|
+
callback(Object.assign(Object.assign({}, info), { key,
|
|
113
|
+
value, type: typeof value, primitive: isPrimitive, path: [...info.path, key] }));
|
|
114
|
+
}
|
|
115
|
+
traverse(value, callback, Object.assign(Object.assign({}, info), { key,
|
|
116
|
+
value, type: typeof value, primitive: isValuePrimitive(value), path: [...info.path, key], depth: info.depth + 1 }));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Identity helper that returns its argument unchanged, typed as `AppSettings`.
|
|
122
|
+
*
|
|
123
|
+
* Exists solely to give TypeScript a typed entry point for authoring settings
|
|
124
|
+
* objects so that editors provide autocompletion and type errors at the
|
|
125
|
+
* definition site rather than at the point of use.
|
|
126
|
+
*/
|
|
127
|
+
export function createSettings(a) {
|
|
128
|
+
return a;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Returns `obj.id` if it exists, otherwise `undefined`.
|
|
132
|
+
*
|
|
133
|
+
* Intended as a default `keyExtractor` in list utilities where records are
|
|
134
|
+
* expected to carry an `id` field.
|
|
135
|
+
*/
|
|
136
|
+
export function extractKey(obj) {
|
|
137
|
+
if (obj.id) {
|
|
138
|
+
return obj.id;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Returns a new object containing only the entries for which `predicate` returns `true`.
|
|
143
|
+
*
|
|
144
|
+
* Only own enumerable keys are visited; prototype-chain properties are skipped.
|
|
145
|
+
*/
|
|
146
|
+
export function objectPickBy(obj, predicate) {
|
|
147
|
+
var _a;
|
|
148
|
+
const result = {};
|
|
149
|
+
for (const key in obj) {
|
|
150
|
+
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))) {
|
|
151
|
+
result[key] = obj === null || obj === void 0 ? void 0 : obj[key];
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Rebuilds an object by running every entry through `predicate`, which must
|
|
158
|
+
* return a `[newKey, newValue]` tuple.
|
|
159
|
+
*
|
|
160
|
+
* Keys returned by `predicate` need not be unique — later entries silently
|
|
161
|
+
* overwrite earlier ones if they resolve to the same key.
|
|
162
|
+
*/
|
|
163
|
+
export function transformObject(obj, predicate) {
|
|
164
|
+
const result = {};
|
|
165
|
+
for (const key in obj) {
|
|
166
|
+
const [newKey, newValue] = predicate === null || predicate === void 0 ? void 0 : predicate(obj === null || obj === void 0 ? void 0 : obj[key], key);
|
|
167
|
+
result[newKey] = newValue;
|
|
168
|
+
}
|
|
169
|
+
return result;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Returns a new object containing only keys that start with `prefix`, with the
|
|
173
|
+
* prefix stripped and the first remaining character lowercased.
|
|
174
|
+
*
|
|
175
|
+
* Useful for splitting a flat props object into logical groups, e.g. separating
|
|
176
|
+
* all `inputXxx` props from a combined component interface.
|
|
177
|
+
*/
|
|
178
|
+
export function filterObjectByPrefix(obj, prefix) {
|
|
179
|
+
const result = {};
|
|
180
|
+
for (const key in obj) {
|
|
181
|
+
if (key.startsWith(prefix)) {
|
|
182
|
+
const newKey = key.slice(prefix.length);
|
|
183
|
+
const formattedKey = newKey.charAt(0).toLowerCase() + newKey.slice(1);
|
|
184
|
+
result[formattedKey] = obj[key];
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return result;
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=object.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object.js","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,UAAU,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,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,aAAa,EAAE,CAAC;QACzC,GAAG,CAAC,GAAG,CAAC;YACN,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,YAAY,IAAI,CAAC;gBAC5E,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;gBACnC,CAAC,CAAC,KAAK,CAAA;IACb,CAAC;IAED,OAAO,GAAG,CAAA;AACZ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CACvB,GAAM,EACN,QAAoD;IAEpD,OAAO,MAAM,CAAC,OAAO,CAAC,GAA8B,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI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@@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import equals from 'deep-equal';
|
|
13
|
+
import React from 'react';
|
|
14
|
+
import { TypeGuards } from '@codeleap/types';
|
|
15
|
+
/** Deep structural equality backed by the `deep-equal` package. */
|
|
16
|
+
export const deepEqual = equals;
|
|
17
|
+
/**
|
|
18
|
+
* Checks a specific subset of props for deep equality between two render cycles.
|
|
19
|
+
*
|
|
20
|
+
* `excludeKeys` are deleted from each compared value **in place** before
|
|
21
|
+
* comparison — this mutates the items inside `previous` and `next`.
|
|
22
|
+
* Pass only the keys you want to ignore, and be aware of the side-effect.
|
|
23
|
+
*/
|
|
24
|
+
export function arePropsEqual(previous, next, options) {
|
|
25
|
+
const { check, excludeKeys = [] } = options;
|
|
26
|
+
for (const c of check) {
|
|
27
|
+
const nextItem = next[c];
|
|
28
|
+
const prevItem = previous[c];
|
|
29
|
+
for (const key of excludeKeys) {
|
|
30
|
+
if (nextItem === null || nextItem === void 0 ? void 0 : nextItem[key])
|
|
31
|
+
delete nextItem[key];
|
|
32
|
+
if (prevItem === null || prevItem === void 0 ? void 0 : prevItem[key])
|
|
33
|
+
delete prevItem[key];
|
|
34
|
+
}
|
|
35
|
+
const propsAreEqual = equals(nextItem, prevItem);
|
|
36
|
+
if (!propsAreEqual) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Recursively collects a React children tree into a single flat array.
|
|
44
|
+
*
|
|
45
|
+
* Uses `React.Children.toArray` at each level (which assigns stable keys), then
|
|
46
|
+
* follows any `children` prop on the top-level element to continue flattening.
|
|
47
|
+
* Only one level of `props.children` nesting is followed per call — deeply
|
|
48
|
+
* nested component trees (not just wrapper nodes) are not fully unwound.
|
|
49
|
+
*/
|
|
50
|
+
export const flattenChildren = (children, flat = []) => {
|
|
51
|
+
flat = [...flat, ...React.Children.toArray(children)];
|
|
52
|
+
if ((children === null || children === void 0 ? void 0 : children.props) && children.props.children) {
|
|
53
|
+
return flattenChildren(children.props.children, flat);
|
|
54
|
+
}
|
|
55
|
+
return flat;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Flattens a children tree and strips the `children` prop from each element's
|
|
59
|
+
* props, returning a serialisable summary of the tree.
|
|
60
|
+
*
|
|
61
|
+
* Intended for introspection and testing — not for re-rendering, since `ref`
|
|
62
|
+
* and event-handler functions are preserved as-is.
|
|
63
|
+
*/
|
|
64
|
+
export const simplifyChildren = (children) => {
|
|
65
|
+
const flat = flattenChildren(children);
|
|
66
|
+
return flat.map((_a) => {
|
|
67
|
+
var { key, ref, type } = _a, _b = _a.props, { children } = _b, props = __rest(_b, ["children"]);
|
|
68
|
+
return ({
|
|
69
|
+
key, ref, type, props,
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Renders a slot that accepts a component, a props object, or a pre-rendered node.
|
|
75
|
+
*
|
|
76
|
+
* Resolution order:
|
|
77
|
+
* 1. If `ComponentOrProps` is a function → render it as `<ComponentOrProps {...props} />`.
|
|
78
|
+
* 2. If it is `null`, `undefined`, or an empty object → return `null`.
|
|
79
|
+
* 3. If it is already a valid React element → return it as-is.
|
|
80
|
+
* 4. Otherwise treat it as a props object and render `<DefaultComponent {...props} {...ComponentOrProps} />`.
|
|
81
|
+
*
|
|
82
|
+
* This lets call sites pass either a component override, extra props, or nothing,
|
|
83
|
+
* without needing separate conditional rendering logic.
|
|
84
|
+
*/
|
|
85
|
+
export function getRenderedComponent(ComponentOrProps, DefaultComponent, props) {
|
|
86
|
+
const _ComponentOrProps = ComponentOrProps;
|
|
87
|
+
const _DefaultComponent = DefaultComponent;
|
|
88
|
+
if (TypeGuards.isFunction(ComponentOrProps)) {
|
|
89
|
+
return React.createElement(_ComponentOrProps, Object.assign({}, props));
|
|
90
|
+
}
|
|
91
|
+
if (TypeGuards.isNil(ComponentOrProps) || Object.keys(ComponentOrProps).length === 0) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
if (React.isValidElement(ComponentOrProps)) {
|
|
95
|
+
return ComponentOrProps;
|
|
96
|
+
}
|
|
97
|
+
const _props = ComponentOrProps;
|
|
98
|
+
return React.createElement(_DefaultComponent, Object.assign({}, props, _props));
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Memoizes a React functional component to prevent unnecessary re-renders.
|
|
102
|
+
*
|
|
103
|
+
* This function wraps a React functional component using `React.memo`, which provides
|
|
104
|
+
* a mechanism for memoizing the result of rendering the component. By default, it
|
|
105
|
+
* uses a comparison function that always returns `true`, indicating that the component
|
|
106
|
+
* should not re-render, regardless of prop changes. This behavior essentially freezes
|
|
107
|
+
* the component's rendering until explicitly updated.
|
|
108
|
+
*
|
|
109
|
+
* @template P - The type of the component's props.
|
|
110
|
+
* @param ComponentToMemoize - The React functional component to memoize.
|
|
111
|
+
* @returns A memoized version of the input component (`React.NamedExoticComponent`).
|
|
112
|
+
*/
|
|
113
|
+
export function memoize(ComponentToMemoize) {
|
|
114
|
+
return React.memo(ComponentToMemoize, () => true);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Checks whether a specific property in two sets of props is equal.
|
|
118
|
+
*
|
|
119
|
+
* This function compares the value of a given property (`prop`) between two objects
|
|
120
|
+
* (`prevProps` and `nextProps`) using a deep equality check (`equals`).
|
|
121
|
+
*
|
|
122
|
+
* @template P - The type of the props object.
|
|
123
|
+
* @param prop - The key of the property to compare.
|
|
124
|
+
* @param prevProps - The previous props object.
|
|
125
|
+
* @param nextProps - The next props object.
|
|
126
|
+
* @returns `true` if the values of the specified property are deeply equal; otherwise, `false`.
|
|
127
|
+
*/
|
|
128
|
+
export function memoChecker(prop, prevProps, nextProps) {
|
|
129
|
+
const nextItem = nextProps[prop];
|
|
130
|
+
const prevItem = prevProps[prop];
|
|
131
|
+
return equals(nextItem, prevItem);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Memoizes a React functional component based on specific props.
|
|
135
|
+
*
|
|
136
|
+
* This function wraps a React functional component using `React.memo` with a custom comparison
|
|
137
|
+
* function. The comparison function checks if the specified properties (passed as `check`)
|
|
138
|
+
* remain equal between renders. If all specified properties are equal, the component will not re-render.
|
|
139
|
+
*
|
|
140
|
+
* @template P - The type of the component's props.
|
|
141
|
+
* @param ComponentToMemoize - The React functional component to memoize.
|
|
142
|
+
* @param check - A single property key or an array of property keys to compare for memoization.
|
|
143
|
+
* @returns A memoized version of the input component (`React.NamedExoticComponent`).
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* import React from 'react';
|
|
147
|
+
* import { memoBy } from './utils';
|
|
148
|
+
*
|
|
149
|
+
* const MyComponent: React.FC<{ name: string; age: number }> = ({ name, age }) => {
|
|
150
|
+
* console.log('Rendering MyComponent...');
|
|
151
|
+
* return (
|
|
152
|
+
* <div>
|
|
153
|
+
* {name}, {age}
|
|
154
|
+
* </div>
|
|
155
|
+
* );
|
|
156
|
+
* };
|
|
157
|
+
*
|
|
158
|
+
* // Memoize the component based on the `name` prop.
|
|
159
|
+
* const MemoizedByName = memoBy(MyComponent, 'name');
|
|
160
|
+
*
|
|
161
|
+
* // Memoize the component based on both `name` and `age` props.
|
|
162
|
+
* const MemoizedByNameAndAge = memoBy(MyComponent, ['name', 'age']);
|
|
163
|
+
*
|
|
164
|
+
* export { MemoizedByName, MemoizedByNameAndAge };
|
|
165
|
+
*
|
|
166
|
+
* // Usage in a parent component
|
|
167
|
+
* <MemoizedByName name="Alice" age={25} />;
|
|
168
|
+
* <MemoizedByNameAndAge name="Alice" age={25} />;
|
|
169
|
+
*/
|
|
170
|
+
export function memoBy(ComponentToMemoize, check) {
|
|
171
|
+
return React.memo(ComponentToMemoize, (prevProps, nextProps) => {
|
|
172
|
+
const checks = Array.isArray(check) ? check : [check];
|
|
173
|
+
return checks.every((key) => memoChecker(key, prevProps, nextProps));
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.js","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,MAAM,MAAM,YAAY,CAAA;AAC/B,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE5C,mEAAmE;AACnE,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAA;AAO/B;;;;;;GAMG;AACH,MAAM,UAAU,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,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OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;QACrD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,CAAA;IACtE,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/string.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/** Collapses all newline characters in `text` to single spaces. */
|
|
2
|
+
export function singleLine(text) {
|
|
3
|
+
return text === null || text === void 0 ? void 0 : text.replace(/\n/g, ' ');
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Round-trips a value through `JSON.stringify` → `JSON.parse`.
|
|
7
|
+
*
|
|
8
|
+
* Strips non-serialisable properties (functions, `undefined`, class instances)
|
|
9
|
+
* and produces a plain-object clone. Throws if the value contains circular
|
|
10
|
+
* references.
|
|
11
|
+
*/
|
|
12
|
+
export function stringiparse(string) {
|
|
13
|
+
return JSON.parse(JSON.stringify(string));
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Changes only the first character of `str`.
|
|
17
|
+
*
|
|
18
|
+
* When `reverse` is `true` the first character is lowercased instead of
|
|
19
|
+
* uppercased — useful for converting PascalCase to camelCase.
|
|
20
|
+
*/
|
|
21
|
+
export function capitalize(str, reverse = false) {
|
|
22
|
+
if (!str.length)
|
|
23
|
+
return str;
|
|
24
|
+
const firstChar = reverse ? str[0].toLowerCase() : str[0].toUpperCase();
|
|
25
|
+
return firstChar + str.substring(1);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Returns `true` if `char` is an uppercase Latin or extended Latin character.
|
|
29
|
+
*
|
|
30
|
+
* Covers the Unicode range `U+0080`–`U+024F` in addition to `A–Z`, so
|
|
31
|
+
* accented capitals (e.g. `É`, `Ñ`) are recognised correctly.
|
|
32
|
+
*/
|
|
33
|
+
export function isUppercase(char) {
|
|
34
|
+
return /[A-Z]|[\u0080-\u024F]/.test(char) && char.toUpperCase() === char;
|
|
35
|
+
}
|
|
36
|
+
/** Returns `true` when `char` is **not** considered uppercase by {@link isUppercase}. */
|
|
37
|
+
export function isLowercase(char) {
|
|
38
|
+
return !isUppercase(char);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Converts a camelCase or PascalCase identifier to a space-separated, title-cased string.
|
|
42
|
+
*
|
|
43
|
+
* A space is inserted before each uppercase letter that is immediately preceded
|
|
44
|
+
* by a lowercase letter. The first character is always uppercased.
|
|
45
|
+
* Consecutive uppercase runs (e.g. acronyms like "URL") are not split.
|
|
46
|
+
*/
|
|
47
|
+
export function humanizeCamelCase(str) {
|
|
48
|
+
const characters = [];
|
|
49
|
+
let previousCharacter = '';
|
|
50
|
+
str.split('').forEach((char, idx) => {
|
|
51
|
+
if (idx === 0) {
|
|
52
|
+
characters.push(char.toUpperCase());
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
if (isUppercase(char) && isLowercase(previousCharacter)) {
|
|
56
|
+
characters.push(` ${char}`);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
characters.push(char);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
previousCharacter = char;
|
|
63
|
+
});
|
|
64
|
+
return characters.join('');
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Truncates `str` to `maxLen` characters, appending `'...'` when truncation occurs.
|
|
68
|
+
*
|
|
69
|
+
* The three dots count toward `maxLen`, so the returned string never exceeds
|
|
70
|
+
* `maxLen` characters when truncated. Strings already at or below `maxLen` are
|
|
71
|
+
* returned unchanged.
|
|
72
|
+
*/
|
|
73
|
+
export function ellipsis(str, maxLen) {
|
|
74
|
+
if (str.length - 3 > maxLen) {
|
|
75
|
+
return str.slice(0, maxLen - 3) + '...';
|
|
76
|
+
}
|
|
77
|
+
return str;
|
|
78
|
+
}
|
|
79
|
+
//# source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AAC,OAAO,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;QAClC,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC;YACd,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAA;QACrC,CAAC;aAAM,CAAC;YACN,IAAI,WAAW,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,iBAAiB,CAAC,EAAE,CAAC;gBACxD,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC,CAAA;YAC7B,CAAC;iBAAM,CAAC;gBACN,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACvB,CAAC;QACH,CAAC;QAED,iBAAiB,GAAG,IAAI,CAAA;IAC1B,CAAC,CAAC,CAAA;IAEF,OAAO,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AAC5B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAW,EAAE,MAAc;IAClD,IAAI,GAAG,CAAC,MAAM,GAAG,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": "
|
|
4
|
-
"main": "
|
|
3
|
+
"version": "7.0.1",
|
|
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": "
|
|
26
|
-
"@codeleap/types": "
|
|
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": "
|
|
34
|
+
"@codeleap/types": "7.0.1",
|
|
35
35
|
"axios": "^1.7.9",
|
|
36
36
|
"dayjs": "1.11.18",
|
|
37
37
|
"typescript": "6.0.3",
|