@augment-vir/common 32.2.1 → 32.2.3
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/augments/array/extract-duplicates.js +3 -1
- package/dist/augments/error/combine-errors.js +3 -1
- package/dist/augments/function/retry.js +8 -6
- package/dist/augments/log/log-string.js +6 -4
- package/dist/augments/log/logger.js +6 -4
- package/dist/augments/number/wrap-number.js +6 -6
- package/dist/augments/object/diff.js +3 -1
- package/dist/augments/object/object-entries.js +9 -5
- package/dist/augments/object/object-filter.js +6 -2
- package/dist/augments/selection-set/select-from.js +3 -1
- package/dist/augments/string/shell-quote.d.ts +27 -0
- package/dist/augments/string/shell-quote.js +33 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +11 -11
|
@@ -24,7 +24,9 @@ export function extractDuplicates(items, comparator = check.strictEquals) {
|
|
|
24
24
|
const duplicates = [];
|
|
25
25
|
const uniques = [];
|
|
26
26
|
items.forEach((item) => {
|
|
27
|
-
const duplicatesIndex = duplicates.findIndex((duplicateEntry) =>
|
|
27
|
+
const duplicatesIndex = duplicates.findIndex((duplicateEntry) => {
|
|
28
|
+
return comparator(duplicateEntry, item);
|
|
29
|
+
});
|
|
28
30
|
if (duplicatesIndex < 0) {
|
|
29
31
|
const uniquesIndex = uniques.findIndex((uniqueEntry) => comparator(uniqueEntry, item));
|
|
30
32
|
if (uniquesIndex < 0) {
|
|
@@ -30,5 +30,7 @@ export function combineErrors(errors) {
|
|
|
30
30
|
else if (errors.length === 1) {
|
|
31
31
|
return errors[0];
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
else {
|
|
34
|
+
return new Error(errors.map((error) => extractErrorMessage(error).trim()).join('\n'));
|
|
35
|
+
}
|
|
34
36
|
}
|
|
@@ -65,12 +65,14 @@ function internalRetry({ currentRetry, maxRetries, callback, options = {}, }) {
|
|
|
65
65
|
throw ensureErrorAndPrependMessage(error, 'Retry max reached');
|
|
66
66
|
}
|
|
67
67
|
else if (options.interval) {
|
|
68
|
-
return wait(options.interval).then(() =>
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
return wait(options.interval).then(() => {
|
|
69
|
+
return internalRetry({
|
|
70
|
+
currentRetry: currentRetry + 1,
|
|
71
|
+
maxRetries,
|
|
72
|
+
callback,
|
|
73
|
+
options,
|
|
74
|
+
});
|
|
75
|
+
});
|
|
74
76
|
}
|
|
75
77
|
else {
|
|
76
78
|
return internalRetry({
|
|
@@ -42,10 +42,12 @@ async function createToLogString() {
|
|
|
42
42
|
return ({ args, colorKey, options }) => {
|
|
43
43
|
const css = options.omitColors
|
|
44
44
|
? undefined
|
|
45
|
-
: filterMap(options.colorConfig[colorKey].colors, (cssString) =>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
: filterMap(options.colorConfig[colorKey].colors, (cssString) => {
|
|
46
|
+
return removeSuffix({
|
|
47
|
+
value: cssString,
|
|
48
|
+
suffix: ';',
|
|
49
|
+
});
|
|
50
|
+
}, check.isTruthy).join('; ');
|
|
49
51
|
const argStrings = args.map((arg) => {
|
|
50
52
|
if (typeof arg === 'string') {
|
|
51
53
|
return arg;
|
|
@@ -40,10 +40,12 @@ export function createLogger(logWriters, optionsOverride) {
|
|
|
40
40
|
}));
|
|
41
41
|
}
|
|
42
42
|
const loggerLogs = mapEnumToObject(LogColorKey, (colorKey) => {
|
|
43
|
-
return (...args) =>
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
return (...args) => {
|
|
44
|
+
return writeLog({
|
|
45
|
+
args,
|
|
46
|
+
colorKey,
|
|
47
|
+
});
|
|
48
|
+
};
|
|
47
49
|
});
|
|
48
50
|
return {
|
|
49
51
|
...loggerLogs,
|
|
@@ -33,13 +33,13 @@ export function wrapNumber(value, minMax) {
|
|
|
33
33
|
return min + offset;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
+
else if (value > max) {
|
|
37
|
+
return min;
|
|
38
|
+
}
|
|
39
|
+
else if (value < min) {
|
|
40
|
+
return max;
|
|
41
|
+
}
|
|
36
42
|
else {
|
|
37
|
-
if (value > max) {
|
|
38
|
-
return min;
|
|
39
|
-
}
|
|
40
|
-
else if (value < min) {
|
|
41
|
-
return max;
|
|
42
|
-
}
|
|
43
43
|
return value;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -94,7 +94,9 @@ export function diffArrays(array0, array1) {
|
|
|
94
94
|
*/
|
|
95
95
|
export function diffBasic(value0, value1,
|
|
96
96
|
/** A custom equality checker. Defaults to a strict equality check (`===`). */
|
|
97
|
-
areEqual = (value0, value1) =>
|
|
97
|
+
areEqual = (value0, value1) => {
|
|
98
|
+
return value0 === value1;
|
|
99
|
+
}) {
|
|
98
100
|
if (areEqual(value0, value1)) {
|
|
99
101
|
return [];
|
|
100
102
|
}
|
|
@@ -9,10 +9,12 @@ import { getObjectTypedKeys } from '@augment-vir/core';
|
|
|
9
9
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
10
10
|
*/
|
|
11
11
|
export function getObjectTypedEntries(input) {
|
|
12
|
-
return getObjectTypedKeys(input).map((key) =>
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
return getObjectTypedKeys(input).map((key) => {
|
|
13
|
+
return [
|
|
14
|
+
key,
|
|
15
|
+
input[key],
|
|
16
|
+
];
|
|
17
|
+
});
|
|
16
18
|
}
|
|
17
19
|
/**
|
|
18
20
|
* Create an object from an array of entries. This is the same as
|
|
@@ -36,5 +38,7 @@ export function typedObjectFromEntries(entries) {
|
|
|
36
38
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
37
39
|
*/
|
|
38
40
|
export function getEntriesSortedByKey(input) {
|
|
39
|
-
return getObjectTypedEntries(input).sort((tupleA, tupleB) =>
|
|
41
|
+
return getObjectTypedEntries(input).sort((tupleA, tupleB) => {
|
|
42
|
+
return String(tupleA[0]).localeCompare(String(tupleB[0]));
|
|
43
|
+
});
|
|
40
44
|
}
|
|
@@ -75,7 +75,9 @@ export function removeNullishValues(input) {
|
|
|
75
75
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
76
76
|
*/
|
|
77
77
|
export function replaceUndefinedValuesWithNull(input) {
|
|
78
|
-
return mapObjectValues(input, (key, value) =>
|
|
78
|
+
return mapObjectValues(input, (key, value) => {
|
|
79
|
+
return value === undefined ? null : value;
|
|
80
|
+
});
|
|
79
81
|
}
|
|
80
82
|
/**
|
|
81
83
|
* Replaces all `null` values with `undefined`.
|
|
@@ -85,5 +87,7 @@ export function replaceUndefinedValuesWithNull(input) {
|
|
|
85
87
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
86
88
|
*/
|
|
87
89
|
export function replaceNullValuesWithUndefined(input) {
|
|
88
|
-
return mapObjectValues(input, (key, value) =>
|
|
90
|
+
return mapObjectValues(input, (key, value) => {
|
|
91
|
+
return value === null ? undefined : value;
|
|
92
|
+
});
|
|
89
93
|
}
|
|
@@ -50,7 +50,9 @@ export function shouldPreserveInSelectionSet(input) {
|
|
|
50
50
|
*/
|
|
51
51
|
export function selectFrom(originalObject, selectionSet) {
|
|
52
52
|
if (Array.isArray(originalObject)) {
|
|
53
|
-
return originalObject.map((originalEntry) =>
|
|
53
|
+
return originalObject.map((originalEntry) => {
|
|
54
|
+
return selectFrom(originalEntry, selectionSet);
|
|
55
|
+
});
|
|
54
56
|
}
|
|
55
57
|
const keysToRemove = [];
|
|
56
58
|
return omitObjectKeys(mapObjectValues(originalObject, (key, value) => {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wraps a string in single quotes so that a POSIX shell treats it as a single literal argument.
|
|
3
|
+
* Single quotes disable word splitting, glob expansion, and command substitution, so the shell
|
|
4
|
+
* passes the value through exactly as given. The only character that cannot appear inside single
|
|
5
|
+
* quotes is a single quote itself, which is closed, escaped, and reopened.
|
|
6
|
+
*
|
|
7
|
+
* This is only valid for POSIX shells like `bash`. It is not correct for `cmd.exe`, which uses
|
|
8
|
+
* entirely different quoting rules.
|
|
9
|
+
*
|
|
10
|
+
* This protects a single round of shell parsing. If the command string will be parsed twice (bash
|
|
11
|
+
* hands it to something that parses it again), quoting once is not enough; see
|
|
12
|
+
* `interpolationSafeWindowsPath` in `@augment-vir/node`, whose backslash count assumes two rounds.
|
|
13
|
+
*
|
|
14
|
+
* @category String
|
|
15
|
+
* @category Package : @augment-vir/common
|
|
16
|
+
* @example
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* import {shellQuote} from '@augment-vir/common';
|
|
20
|
+
*
|
|
21
|
+
* shellQuote('hello world'); // outputs `"'hello world'"`
|
|
22
|
+
* shellQuote("it's"); // outputs `"'it'\\''s'"`
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
26
|
+
*/
|
|
27
|
+
export declare function shellQuote(input: string): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wraps a string in single quotes so that a POSIX shell treats it as a single literal argument.
|
|
3
|
+
* Single quotes disable word splitting, glob expansion, and command substitution, so the shell
|
|
4
|
+
* passes the value through exactly as given. The only character that cannot appear inside single
|
|
5
|
+
* quotes is a single quote itself, which is closed, escaped, and reopened.
|
|
6
|
+
*
|
|
7
|
+
* This is only valid for POSIX shells like `bash`. It is not correct for `cmd.exe`, which uses
|
|
8
|
+
* entirely different quoting rules.
|
|
9
|
+
*
|
|
10
|
+
* This protects a single round of shell parsing. If the command string will be parsed twice (bash
|
|
11
|
+
* hands it to something that parses it again), quoting once is not enough; see
|
|
12
|
+
* `interpolationSafeWindowsPath` in `@augment-vir/node`, whose backslash count assumes two rounds.
|
|
13
|
+
*
|
|
14
|
+
* @category String
|
|
15
|
+
* @category Package : @augment-vir/common
|
|
16
|
+
* @example
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* import {shellQuote} from '@augment-vir/common';
|
|
20
|
+
*
|
|
21
|
+
* shellQuote('hello world'); // outputs `"'hello world'"`
|
|
22
|
+
* shellQuote("it's"); // outputs `"'it'\\''s'"`
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
26
|
+
*/
|
|
27
|
+
export function shellQuote(input) {
|
|
28
|
+
return [
|
|
29
|
+
"'",
|
|
30
|
+
input.replaceAll("'", String.raw `'\''`),
|
|
31
|
+
"'",
|
|
32
|
+
].join('');
|
|
33
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -93,6 +93,7 @@ export * from './augments/string/length.js';
|
|
|
93
93
|
export * from './augments/string/lines.js';
|
|
94
94
|
export * from './augments/string/prefix.js';
|
|
95
95
|
export * from './augments/string/replace.js';
|
|
96
|
+
export * from './augments/string/shell-quote.js';
|
|
96
97
|
export * from './augments/string/split.js';
|
|
97
98
|
export * from './augments/string/substring-index.js';
|
|
98
99
|
export * from './augments/string/suffix.js';
|
package/dist/index.js
CHANGED
|
@@ -93,6 +93,7 @@ export * from './augments/string/length.js';
|
|
|
93
93
|
export * from './augments/string/lines.js';
|
|
94
94
|
export * from './augments/string/prefix.js';
|
|
95
95
|
export * from './augments/string/replace.js';
|
|
96
|
+
export * from './augments/string/shell-quote.js';
|
|
96
97
|
export * from './augments/string/split.js';
|
|
97
98
|
export * from './augments/string/substring-index.js';
|
|
98
99
|
export * from './augments/string/suffix.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@augment-vir/common",
|
|
3
|
-
"version": "32.2.
|
|
3
|
+
"version": "32.2.3",
|
|
4
4
|
"description": "A collection of augments, helpers types, functions, and classes for any JavaScript environment.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"augment",
|
|
@@ -40,22 +40,22 @@
|
|
|
40
40
|
"test:web": "virmator --no-deps test web"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@augment-vir/assert": "^32.2.
|
|
44
|
-
"@augment-vir/core": "^32.2.
|
|
45
|
-
"@date-vir/duration": "^
|
|
43
|
+
"@augment-vir/assert": "^32.2.3",
|
|
44
|
+
"@augment-vir/core": "^32.2.3",
|
|
45
|
+
"@date-vir/duration": "^9.0.0",
|
|
46
46
|
"@paralleldrive/cuid2": "^3.3.0",
|
|
47
|
-
"ansi-styles": "^
|
|
47
|
+
"ansi-styles": "^7.0.0",
|
|
48
48
|
"deepcopy-esm": "^2.1.2",
|
|
49
49
|
"json5": "^2.2.3",
|
|
50
|
-
"typed-event-target": "^4.3.
|
|
50
|
+
"typed-event-target": "^4.3.3"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@web/dev-server-esbuild": "^
|
|
54
|
-
"@web/test-runner": "^0.
|
|
55
|
-
"@web/test-runner-playwright": "^0.
|
|
56
|
-
"execute-in-browser": "^1.0.
|
|
53
|
+
"@web/dev-server-esbuild": "^2.0.0",
|
|
54
|
+
"@web/test-runner": "^1.0.0",
|
|
55
|
+
"@web/test-runner-playwright": "^1.0.0",
|
|
56
|
+
"execute-in-browser": "^1.0.10",
|
|
57
57
|
"istanbul-smart-text-reporter": "^1.1.5",
|
|
58
|
-
"runstorm": "^1.0.
|
|
58
|
+
"runstorm": "^1.0.6",
|
|
59
59
|
"typescript": "^6.0.3"
|
|
60
60
|
},
|
|
61
61
|
"engines": {
|