@takeshape/util 11.133.1 → 11.134.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/clone.d.ts +16 -3
- package/dist/common/clone.js +42 -3
- package/dist/common/relay.d.ts +4 -0
- package/dist/common/strings.d.ts +1 -0
- package/dist/common/strings.js +18 -0
- package/package.json +5 -4
package/dist/common/clone.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare function deepClone<T>(value: T): T;
|
|
|
8
8
|
* @param parent the parent object or array if applicable
|
|
9
9
|
* @return a new value to use instead of the value argument. Return REMOVE to remove value from the parent. Return undefined to continue to clone recursively.
|
|
10
10
|
*/
|
|
11
|
-
type CloneHelper = (value: unknown, key: string | number | undefined, parent: Record<string, unknown> | unknown[] | undefined) => unknown;
|
|
11
|
+
export type CloneHelper = (value: unknown, key: string | number | undefined, parent: Record<string, unknown> | unknown[] | undefined) => unknown;
|
|
12
12
|
/**
|
|
13
13
|
* The callback for deepCloneWith which is called for every value in a object
|
|
14
14
|
* @param value the value to clone
|
|
@@ -19,10 +19,23 @@ type CloneHelper = (value: unknown, key: string | number | undefined, parent: Re
|
|
|
19
19
|
*/
|
|
20
20
|
export type DeepCloneWithCustomizer = (value: unknown, key: string | number | undefined, parent: Record<string, unknown> | unknown[] | undefined, clone: CloneHelper) => unknown;
|
|
21
21
|
export declare const REMOVE: unique symbol;
|
|
22
|
+
/**
|
|
23
|
+
* Clone any JSON serializable value and transform using a callback
|
|
24
|
+
* @param obj the value to clone
|
|
25
|
+
* @param customizer a callback that is called for every key/index
|
|
26
|
+
*/
|
|
27
|
+
export declare function deepCloneWith(obj: unknown, customizer: DeepCloneWithCustomizer): unknown;
|
|
28
|
+
/**
|
|
29
|
+
* @param value the value to clone
|
|
30
|
+
* @param key the key/index this value is stored under if parent is an object or array
|
|
31
|
+
* @param parent the parent object or array if applicable
|
|
32
|
+
* @param path the path to the current value being cloned
|
|
33
|
+
* @return a new value to use instead of the value argument. Return REMOVE to remove value from the parent. Return undefined to continue to clone recursively.
|
|
34
|
+
*/
|
|
35
|
+
export type CloneWithPathHelper = (value: unknown, key: string | number | undefined, parent: Record<string, unknown> | unknown[] | undefined, path: string[]) => unknown;
|
|
22
36
|
/**
|
|
23
37
|
* Clone any JSON serializable value and transform using a callback
|
|
24
38
|
* @param value the value to clone
|
|
25
39
|
* @param customizer a callback that is called for every key/index
|
|
26
40
|
*/
|
|
27
|
-
export declare function
|
|
28
|
-
export {};
|
|
41
|
+
export declare function deepCloneWithPath(obj: unknown, customizer: CloneWithPathHelper): unknown;
|
package/dist/common/clone.js
CHANGED
|
@@ -33,10 +33,10 @@ function arrayFilter(value) {
|
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
35
|
* Clone any JSON serializable value and transform using a callback
|
|
36
|
-
* @param
|
|
36
|
+
* @param obj the value to clone
|
|
37
37
|
* @param customizer a callback that is called for every key/index
|
|
38
38
|
*/
|
|
39
|
-
export function deepCloneWith(
|
|
39
|
+
export function deepCloneWith(obj, customizer) {
|
|
40
40
|
const clone = (value, key, parent) => {
|
|
41
41
|
const newValue = customizer(value, key, parent, clone);
|
|
42
42
|
if (newValue !== undefined) {
|
|
@@ -67,5 +67,44 @@ export function deepCloneWith(value, customizer) {
|
|
|
67
67
|
}
|
|
68
68
|
return value;
|
|
69
69
|
};
|
|
70
|
-
return clone(
|
|
70
|
+
return clone(obj, undefined, undefined);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Clone any JSON serializable value and transform using a callback
|
|
74
|
+
* @param value the value to clone
|
|
75
|
+
* @param customizer a callback that is called for every key/index
|
|
76
|
+
*/
|
|
77
|
+
export function deepCloneWithPath(obj, customizer) {
|
|
78
|
+
const clone = (value, key, parent, path) => {
|
|
79
|
+
const customizedValue = customizer(value, key, parent, path);
|
|
80
|
+
if (customizedValue === REMOVE) {
|
|
81
|
+
return customizedValue;
|
|
82
|
+
}
|
|
83
|
+
const cloneValue = customizedValue ?? value;
|
|
84
|
+
if (Array.isArray(cloneValue)) {
|
|
85
|
+
const { length } = cloneValue;
|
|
86
|
+
const arr = new Array(length);
|
|
87
|
+
let edited = false;
|
|
88
|
+
for (let i = 0; i < length; i++) {
|
|
89
|
+
const newValue = clone(cloneValue[i], i, cloneValue, [...path, String(i)]);
|
|
90
|
+
if (newValue === REMOVE) {
|
|
91
|
+
edited = true;
|
|
92
|
+
}
|
|
93
|
+
arr[i] = newValue;
|
|
94
|
+
}
|
|
95
|
+
return edited ? arr.filter(arrayFilter) : arr;
|
|
96
|
+
}
|
|
97
|
+
if (isIterableObject(cloneValue)) {
|
|
98
|
+
const newObject = {};
|
|
99
|
+
for (const key of Object.keys(cloneValue)) {
|
|
100
|
+
const newValue = clone(cloneValue[key], key, cloneValue, [...path, key]);
|
|
101
|
+
if (newValue !== undefined && newValue !== REMOVE) {
|
|
102
|
+
newObject[key] = newValue;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return newObject;
|
|
106
|
+
}
|
|
107
|
+
return cloneValue;
|
|
108
|
+
};
|
|
109
|
+
return clone(obj, undefined, undefined, []);
|
|
71
110
|
}
|
package/dist/common/relay.d.ts
CHANGED
package/dist/common/strings.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export declare function formatShapeName(str: string[], options: {
|
|
|
10
10
|
* Optional config triggers a namespace-preserving behavior for built-in shapes starting with `TS`.
|
|
11
11
|
*/
|
|
12
12
|
export declare function pascalCase(str: string | string[]): string;
|
|
13
|
+
export declare function pascalCaseWithAbbreviations(str: string | string[]): string;
|
|
13
14
|
export declare function isUuid(str: string): boolean;
|
|
14
15
|
export declare function isEmptyString(str: unknown): boolean;
|
|
15
16
|
export declare function isIntegerLike(value: string | number): boolean;
|
package/dist/common/strings.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { isBrowser } from 'browser-or-node';
|
|
2
2
|
import _camelCase from 'lodash/camelCase.js';
|
|
3
|
+
import deburr from 'lodash/deburr.js';
|
|
3
4
|
import isEmpty from 'lodash/isEmpty.js';
|
|
4
5
|
import isNil from 'lodash/isNil.js';
|
|
5
6
|
import isString from 'lodash/isString.js';
|
|
6
7
|
import upperFirst from 'lodash/upperFirst.js';
|
|
8
|
+
import words from 'lodash/words.js';
|
|
7
9
|
import { ensureArray } from "./arrays.js";
|
|
8
10
|
export const camelCase = _camelCase;
|
|
9
11
|
export function formatShapeName(str, options) {
|
|
@@ -38,6 +40,22 @@ export function formatShapeName(str, options) {
|
|
|
38
40
|
export function pascalCase(str) {
|
|
39
41
|
return upperFirst(camelCase(str));
|
|
40
42
|
}
|
|
43
|
+
/** Used to match apostrophes. */
|
|
44
|
+
const reApos = /['\u2019]/g;
|
|
45
|
+
/** Has caps */
|
|
46
|
+
const reCap = /[A-Z]/;
|
|
47
|
+
export function pascalCaseWithAbbreviations(str) {
|
|
48
|
+
const joined = Array.isArray(str) ? str.join(' ') : str;
|
|
49
|
+
return words(deburr(joined).replace(reApos, '')).reduce((result, word) => {
|
|
50
|
+
// If the word is all uppercase and contains letters,
|
|
51
|
+
// treat it as an abbreviation and keep it uppercase
|
|
52
|
+
if (word === word.toUpperCase() && reCap.test(word)) {
|
|
53
|
+
return result + word;
|
|
54
|
+
}
|
|
55
|
+
// Otherwise, capitalize the word
|
|
56
|
+
return result + (word.charAt(0).toUpperCase() + word.slice(1).toLowerCase());
|
|
57
|
+
}, '');
|
|
58
|
+
}
|
|
41
59
|
export function isUuid(str) {
|
|
42
60
|
return Boolean(/\w{8,}(-\w{4,}){3,}-\w{12,}/.exec(str));
|
|
43
61
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takeshape/util",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.134.0",
|
|
4
4
|
"description": "Shared utilities",
|
|
5
5
|
"homepage": "https://www.takeshape.io",
|
|
6
6
|
"repository": {
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"tiny-invariant": "1.3.3",
|
|
46
46
|
"uint8array-extras": "1.4.0",
|
|
47
47
|
"url-parse": "1.5.3",
|
|
48
|
-
"@takeshape/prism": "11.
|
|
49
|
-
"@takeshape/routing": "11.
|
|
48
|
+
"@takeshape/prism": "11.134.0",
|
|
49
|
+
"@takeshape/routing": "11.134.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/classnames": "2.2.11",
|
|
@@ -76,6 +76,7 @@
|
|
|
76
76
|
"test:ci": "TZ=UTC vitest run --reporter=default --reporter=junit --outputFile=\"${GITHUB_WORKSPACE}/test-results/${npm_package_name#*\\/}/vitest-results.xml\" --coverage.enabled --coverage.reportsDirectory=\"${GITHUB_WORKSPACE}/coverage/${npm_package_name#*\\/}\"",
|
|
77
77
|
"todo": "leasot 'src/**/*.{js,jsx,ts,tsx}'",
|
|
78
78
|
"typecheck": "tsc --noEmit",
|
|
79
|
-
"typecheck:ci": "mkdir -p \"${GITHUB_WORKSPACE}/test-results/${npm_package_name#*\\/}\" && tsc --noEmit --pretty false | typescript-jest-junit-reporter | tee \"${GITHUB_WORKSPACE}/test-results/${npm_package_name#*\\/}/typescript-results.xml\""
|
|
79
|
+
"typecheck:ci": "mkdir -p \"${GITHUB_WORKSPACE}/test-results/${npm_package_name#*\\/}\" && tsc --noEmit --pretty false | typescript-jest-junit-reporter | tee \"${GITHUB_WORKSPACE}/test-results/${npm_package_name#*\\/}/typescript-results.xml\"",
|
|
80
|
+
"watch": "TZ=UTC vitest --watch"
|
|
80
81
|
}
|
|
81
82
|
}
|