@augment-vir/common 28.2.3 → 29.0.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/cjs/augments/array/array.js +9 -10
- package/dist/cjs/augments/array/remove-duplicates.js +1 -2
- package/dist/cjs/augments/async.js +3 -4
- package/dist/cjs/augments/boolean.js +3 -4
- package/dist/cjs/augments/common-number.js +10 -10
- package/dist/cjs/augments/common-string.js +16 -16
- package/dist/cjs/augments/debounce.js +2 -2
- package/dist/cjs/augments/environment.js +1 -2
- package/dist/cjs/augments/error.js +5 -6
- package/dist/cjs/augments/esm-path.js +1 -2
- package/dist/cjs/augments/json.js +2 -3
- package/dist/cjs/augments/object/enum.js +5 -6
- package/dist/cjs/augments/object/filter-object.js +3 -4
- package/dist/cjs/augments/object/get-or-set.js +2 -3
- package/dist/cjs/augments/object/has-key.js +1 -2
- package/dist/cjs/augments/object/jsonify.js +1 -2
- package/dist/cjs/augments/object/map-object.js +2 -3
- package/dist/cjs/augments/object/merge-deep.js +1 -2
- package/dist/cjs/augments/object/merge-property-arrays.js +1 -2
- package/dist/cjs/augments/object/object-entries.js +6 -7
- package/dist/cjs/augments/object/object.js +2 -3
- package/dist/cjs/augments/object/selection-set.js +2 -0
- package/dist/cjs/augments/object/typed-has-property.js +2 -3
- package/dist/cjs/augments/promise/deferred-promise.js +1 -2
- package/dist/cjs/augments/promise/promise.js +5 -5
- package/dist/cjs/augments/promise/wait.js +4 -4
- package/dist/cjs/augments/random.js +4 -5
- package/dist/cjs/augments/regexp.js +3 -4
- package/dist/cjs/augments/string/prefixes.js +2 -3
- package/dist/cjs/augments/string/suffixes.js +7 -7
- package/dist/cjs/augments/string/uuid.js +1 -2
- package/dist/cjs/augments/time.js +2 -2
- package/dist/cjs/augments/truncate-number.js +1 -2
- package/dist/cjs/augments/tuple.js +2 -3
- package/dist/cjs/augments/type.js +4 -5
- package/dist/cjs/augments/union.js +2 -0
- package/dist/cjs/augments/wrap-in-try.js +1 -2
- package/dist/cjs/index.js +3 -2
- package/dist/esm/augments/object/selection-set.js +1 -0
- package/dist/esm/augments/union.js +1 -0
- package/dist/esm/index.js +3 -2
- package/dist/types/augments/object/key-count.d.ts +13 -0
- package/dist/types/augments/object/map-object.d.ts +1 -1
- package/dist/types/augments/object/pick-deep.d.ts +0 -6
- package/dist/types/augments/object/selection-set.d.ts +25 -0
- package/dist/types/index.d.ts +3 -2
- package/package.json +2 -2
- package/dist/cjs/augments/object/nested-keys.js +0 -61
- package/dist/esm/augments/object/nested-keys.js +0 -56
- package/dist/types/augments/object/nested-keys.d.ts +0 -18
- /package/dist/cjs/augments/object/{old-union-to-intersection.js → key-count.js} +0 -0
- /package/dist/esm/augments/object/{old-union-to-intersection.js → key-count.js} +0 -0
- /package/dist/types/augments/{object/old-union-to-intersection.d.ts → union.d.ts} +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.typedHasProperty = typedHasProperty;
|
|
4
|
+
exports.typedHasProperties = typedHasProperties;
|
|
4
5
|
const hasPropertyAttempts = [
|
|
5
6
|
(object, key) => {
|
|
6
7
|
return key in object;
|
|
@@ -23,8 +24,6 @@ function typedHasProperty(inputObject, inputKey) {
|
|
|
23
24
|
}
|
|
24
25
|
});
|
|
25
26
|
}
|
|
26
|
-
exports.typedHasProperty = typedHasProperty;
|
|
27
27
|
function typedHasProperties(inputObject, inputKeys) {
|
|
28
28
|
return inputObject && inputKeys.every((key) => typedHasProperty(inputObject, key));
|
|
29
29
|
}
|
|
30
|
-
exports.typedHasProperties = typedHasProperties;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createDeferredPromiseWrapper =
|
|
3
|
+
exports.createDeferredPromiseWrapper = createDeferredPromiseWrapper;
|
|
4
4
|
function createDeferredPromiseWrapper() {
|
|
5
5
|
let resolve;
|
|
6
6
|
let reject;
|
|
@@ -29,4 +29,3 @@ function createDeferredPromiseWrapper() {
|
|
|
29
29
|
},
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
-
exports.createDeferredPromiseWrapper = createDeferredPromiseWrapper;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.PromiseTimeoutError = void 0;
|
|
4
|
+
exports.isPromiseLike = isPromiseLike;
|
|
5
|
+
exports.wrapPromiseInTimeout = wrapPromiseInTimeout;
|
|
6
|
+
exports.callAsynchronously = callAsynchronously;
|
|
7
|
+
exports.executeWithRetries = executeWithRetries;
|
|
4
8
|
const typed_has_property_1 = require("../object/typed-has-property");
|
|
5
9
|
function isPromiseLike(input) {
|
|
6
10
|
if ((0, typed_has_property_1.typedHasProperty)(input, 'then') && typeof input.then === 'function') {
|
|
@@ -10,7 +14,6 @@ function isPromiseLike(input) {
|
|
|
10
14
|
return false;
|
|
11
15
|
}
|
|
12
16
|
}
|
|
13
|
-
exports.isPromiseLike = isPromiseLike;
|
|
14
17
|
class PromiseTimeoutError extends Error {
|
|
15
18
|
constructor(durationMs, message = `Promised timed out after ${durationMs} ms.`) {
|
|
16
19
|
super(message);
|
|
@@ -54,7 +57,6 @@ function wrapPromiseInTimeout(durationMs, originalPromise) {
|
|
|
54
57
|
}
|
|
55
58
|
});
|
|
56
59
|
}
|
|
57
|
-
exports.wrapPromiseInTimeout = wrapPromiseInTimeout;
|
|
58
60
|
/**
|
|
59
61
|
* Call a function asynchronously without interrupting current synchronous execution, even if the
|
|
60
62
|
* function was originally synchronous.
|
|
@@ -62,7 +64,6 @@ exports.wrapPromiseInTimeout = wrapPromiseInTimeout;
|
|
|
62
64
|
async function callAsynchronously(callback) {
|
|
63
65
|
return await Promise.resolve().then(() => callback());
|
|
64
66
|
}
|
|
65
|
-
exports.callAsynchronously = callAsynchronously;
|
|
66
67
|
async function executeWithRetries(retryCount, callback) {
|
|
67
68
|
let currentRetry = 0;
|
|
68
69
|
while (currentRetry < retryCount) {
|
|
@@ -76,4 +77,3 @@ async function executeWithRetries(retryCount, callback) {
|
|
|
76
77
|
}
|
|
77
78
|
throw new Error('Retry max reached.');
|
|
78
79
|
}
|
|
79
|
-
exports.executeWithRetries = executeWithRetries;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.defaultWaitUntilDefinedOptions = void 0;
|
|
4
|
+
exports.wait = wait;
|
|
5
|
+
exports.waitValue = waitValue;
|
|
6
|
+
exports.waitUntilTruthy = waitUntilTruthy;
|
|
4
7
|
const error_1 = require("../error");
|
|
5
8
|
const deferred_promise_1 = require("./deferred-promise");
|
|
6
9
|
function wait(delayMs) {
|
|
@@ -12,11 +15,9 @@ function wait(delayMs) {
|
|
|
12
15
|
}
|
|
13
16
|
return deferredPromiseWrapper.promise;
|
|
14
17
|
}
|
|
15
|
-
exports.wait = wait;
|
|
16
18
|
async function waitValue(delayMs, returnValue) {
|
|
17
19
|
return wait(delayMs).then(() => returnValue);
|
|
18
20
|
}
|
|
19
|
-
exports.waitValue = waitValue;
|
|
20
21
|
exports.defaultWaitUntilDefinedOptions = {
|
|
21
22
|
interval: {
|
|
22
23
|
milliseconds: 100,
|
|
@@ -63,4 +64,3 @@ async function waitUntilTruthy(predicate, failureMessage, optionsInput = {}) {
|
|
|
63
64
|
}
|
|
64
65
|
return lastValue;
|
|
65
66
|
}
|
|
66
|
-
exports.waitUntilTruthy = waitUntilTruthy;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.randomInteger = randomInteger;
|
|
4
|
+
exports.randomBoolean = randomBoolean;
|
|
5
|
+
exports.createUuid = createUuid;
|
|
6
|
+
exports.randomString = randomString;
|
|
4
7
|
const common_number_1 = require("./common-number");
|
|
5
8
|
function accessCrypto() {
|
|
6
9
|
if (globalThis.crypto) {
|
|
@@ -32,7 +35,6 @@ function randomInteger({ min: rawMin, max: rawMax }) {
|
|
|
32
35
|
} while (value >= cutoff);
|
|
33
36
|
return min + (value % range);
|
|
34
37
|
}
|
|
35
|
-
exports.randomInteger = randomInteger;
|
|
36
38
|
/**
|
|
37
39
|
* Returns true at rate of the percentLikelyToBeTrue input. Inputs should be whole numbers which
|
|
38
40
|
* will be treated like percents. Anything outside of 0-100 inclusively will be clamped. An input 0
|
|
@@ -61,12 +63,10 @@ function randomBoolean(percentLikelyToBeTrue = 50) {
|
|
|
61
63
|
max: 100,
|
|
62
64
|
}));
|
|
63
65
|
}
|
|
64
|
-
exports.randomBoolean = randomBoolean;
|
|
65
66
|
/** Creates a cryptographically secure uuid. */
|
|
66
67
|
function createUuid() {
|
|
67
68
|
return crypto.randomUUID();
|
|
68
69
|
}
|
|
69
|
-
exports.createUuid = createUuid;
|
|
70
70
|
const validStringCharacters = [
|
|
71
71
|
'a',
|
|
72
72
|
'b',
|
|
@@ -121,4 +121,3 @@ function randomString(inputLength = 16) {
|
|
|
121
121
|
}
|
|
122
122
|
return stringBuilder;
|
|
123
123
|
}
|
|
124
|
-
exports.randomString = randomString;
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.deDupeRegExFlags = deDupeRegExFlags;
|
|
4
|
+
exports.addRegExpFlags = addRegExpFlags;
|
|
5
|
+
exports.safeMatch = safeMatch;
|
|
4
6
|
function deDupeRegExFlags(flags) {
|
|
5
7
|
const deDuped = new Set(Array.from(flags.toLowerCase()));
|
|
6
8
|
return Array.from(deDuped).join('');
|
|
7
9
|
}
|
|
8
|
-
exports.deDupeRegExFlags = deDupeRegExFlags;
|
|
9
10
|
function addRegExpFlags(originalRegExp, flags) {
|
|
10
11
|
return new RegExp(originalRegExp.source, deDupeRegExFlags([
|
|
11
12
|
originalRegExp.flags,
|
|
12
13
|
flags,
|
|
13
14
|
].join('')));
|
|
14
15
|
}
|
|
15
|
-
exports.addRegExpFlags = addRegExpFlags;
|
|
16
16
|
function safeMatch(input, regExp) {
|
|
17
17
|
const match = input.match(regExp);
|
|
18
18
|
return match ?? [];
|
|
19
19
|
}
|
|
20
|
-
exports.safeMatch = safeMatch;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.addPrefix = addPrefix;
|
|
4
|
+
exports.removePrefix = removePrefix;
|
|
4
5
|
function addPrefix({ value, prefix, }) {
|
|
5
6
|
if (String(value).startsWith(prefix)) {
|
|
6
7
|
return String(value);
|
|
@@ -9,7 +10,6 @@ function addPrefix({ value, prefix, }) {
|
|
|
9
10
|
return `${prefix}${String(value)}`;
|
|
10
11
|
}
|
|
11
12
|
}
|
|
12
|
-
exports.addPrefix = addPrefix;
|
|
13
13
|
function removePrefix({ value, prefix, }) {
|
|
14
14
|
if (value.startsWith(prefix)) {
|
|
15
15
|
return value.substring(prefix.length);
|
|
@@ -18,4 +18,3 @@ function removePrefix({ value, prefix, }) {
|
|
|
18
18
|
return value;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
exports.removePrefix = removePrefix;
|
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.pxSuffix = exports.percentSuffix = void 0;
|
|
4
|
+
exports.addPx = addPx;
|
|
5
|
+
exports.removePx = removePx;
|
|
6
|
+
exports.addPercent = addPercent;
|
|
7
|
+
exports.removePercent = removePercent;
|
|
8
|
+
exports.addSuffix = addSuffix;
|
|
9
|
+
exports.removeSuffix = removeSuffix;
|
|
4
10
|
const common_number_1 = require("../common-number");
|
|
5
11
|
exports.percentSuffix = '%';
|
|
6
12
|
exports.pxSuffix = 'px';
|
|
7
13
|
function addPx(input) {
|
|
8
14
|
return addSuffix({ value: input, suffix: exports.pxSuffix });
|
|
9
15
|
}
|
|
10
|
-
exports.addPx = addPx;
|
|
11
16
|
function removePx(input) {
|
|
12
17
|
return (0, common_number_1.toEnsuredNumber)(removeSuffix({ value: input, suffix: exports.pxSuffix }));
|
|
13
18
|
}
|
|
14
|
-
exports.removePx = removePx;
|
|
15
19
|
function addPercent(input) {
|
|
16
20
|
return addSuffix({ value: input, suffix: exports.percentSuffix });
|
|
17
21
|
}
|
|
18
|
-
exports.addPercent = addPercent;
|
|
19
22
|
function removePercent(input) {
|
|
20
23
|
return (0, common_number_1.toEnsuredNumber)(removeSuffix({ value: input, suffix: exports.percentSuffix }));
|
|
21
24
|
}
|
|
22
|
-
exports.removePercent = removePercent;
|
|
23
25
|
function addSuffix({ value, suffix, }) {
|
|
24
26
|
if (String(value).endsWith(suffix)) {
|
|
25
27
|
return String(value);
|
|
@@ -28,7 +30,6 @@ function addSuffix({ value, suffix, }) {
|
|
|
28
30
|
return `${String(value)}${suffix}`;
|
|
29
31
|
}
|
|
30
32
|
}
|
|
31
|
-
exports.addSuffix = addSuffix;
|
|
32
33
|
function removeSuffix({ value, suffix, }) {
|
|
33
34
|
if (value.endsWith(suffix)) {
|
|
34
35
|
return value.substring(0, value.length - suffix.length);
|
|
@@ -37,4 +38,3 @@ function removeSuffix({ value, suffix, }) {
|
|
|
37
38
|
return value;
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
|
-
exports.removeSuffix = removeSuffix;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isUuid =
|
|
3
|
+
exports.isUuid = isUuid;
|
|
4
4
|
const uuidRegExp = /[\d\w]{8}-[\d\w]{4}-[\d\w]{4}-[\d\w]{4}-[\d\w]{12}/;
|
|
5
5
|
function isUuid(maybeUuid) {
|
|
6
6
|
return !!maybeUuid.match(uuidRegExp);
|
|
7
7
|
}
|
|
8
|
-
exports.isUuid = isUuid;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.measureCallbackDuration =
|
|
3
|
+
exports.measureCallbackDuration = void 0;
|
|
4
|
+
exports.timeCallback = timeCallback;
|
|
4
5
|
/**
|
|
5
6
|
* Measures how long (in milliseconds) the given callback takes to run to completion. Automatically
|
|
6
7
|
* switches to async mode and awaits callbacks if they return a promise (otherwise this function is
|
|
@@ -24,7 +25,6 @@ function timeCallback(callback) {
|
|
|
24
25
|
const endTime = Date.now();
|
|
25
26
|
return (endTime - startTime);
|
|
26
27
|
}
|
|
27
|
-
exports.timeCallback = timeCallback;
|
|
28
28
|
/**
|
|
29
29
|
* Measures how long (in milliseconds) the given callback takes to run to completion. Automatically
|
|
30
30
|
* switches to async mode and awaits callbacks if they return a promise (otherwise this function is
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.truncateNumber =
|
|
3
|
+
exports.truncateNumber = truncateNumber;
|
|
4
4
|
const common_number_1 = require("./common-number");
|
|
5
5
|
const common_string_1 = require("./common-string");
|
|
6
6
|
const regexp_1 = require("./regexp");
|
|
@@ -151,4 +151,3 @@ function truncateNumber(originalValue, { customSuffixes = defaultTruncationSuffi
|
|
|
151
151
|
}
|
|
152
152
|
return truncateBigNumber(numberAsString, customSuffixes, maxLength);
|
|
153
153
|
}
|
|
154
|
-
exports.truncateNumber = truncateNumber;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isLengthAtLeast = isLengthAtLeast;
|
|
4
|
+
exports.assertLengthAtLeast = assertLengthAtLeast;
|
|
4
5
|
function isLengthAtLeast(array, length) {
|
|
5
6
|
try {
|
|
6
7
|
assertLengthAtLeast(array, length);
|
|
@@ -10,7 +11,6 @@ function isLengthAtLeast(array, length) {
|
|
|
10
11
|
return false;
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
|
-
exports.isLengthAtLeast = isLengthAtLeast;
|
|
14
14
|
function assertLengthAtLeast(array, length, arrayName) {
|
|
15
15
|
if (array.length < length) {
|
|
16
16
|
throw new Error(arrayName
|
|
@@ -18,4 +18,3 @@ function assertLengthAtLeast(array, length, arrayName) {
|
|
|
18
18
|
: `Array is not at least '${length}' in length.`);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
exports.assertLengthAtLeast = assertLengthAtLeast;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.makeWritable = makeWritable;
|
|
4
|
+
exports.makeReadonly = makeReadonly;
|
|
5
|
+
exports.wrapNarrowTypeWithTypeCheck = wrapNarrowTypeWithTypeCheck;
|
|
6
|
+
exports.ensureType = ensureType;
|
|
4
7
|
function makeWritable(input) {
|
|
5
8
|
return input;
|
|
6
9
|
}
|
|
7
|
-
exports.makeWritable = makeWritable;
|
|
8
10
|
function makeReadonly(input) {
|
|
9
11
|
return input;
|
|
10
12
|
}
|
|
11
|
-
exports.makeReadonly = makeReadonly;
|
|
12
13
|
/**
|
|
13
14
|
* This function returns another function that simply returns whatever input it's given. However, it
|
|
14
15
|
* also checks that the input matches the original wrapNarrowTypeWithTypeCheck's generic, while
|
|
@@ -23,7 +24,6 @@ function wrapNarrowTypeWithTypeCheck() {
|
|
|
23
24
|
return input;
|
|
24
25
|
};
|
|
25
26
|
}
|
|
26
|
-
exports.wrapNarrowTypeWithTypeCheck = wrapNarrowTypeWithTypeCheck;
|
|
27
27
|
/**
|
|
28
28
|
* This is a type helper that ensures the given input matches the given generic type. The generic is
|
|
29
29
|
* setup in such a way that if it is omitted (which is typically allowed in TypeScript, resulting in
|
|
@@ -34,4 +34,3 @@ exports.wrapNarrowTypeWithTypeCheck = wrapNarrowTypeWithTypeCheck;
|
|
|
34
34
|
function ensureType(input) {
|
|
35
35
|
return input;
|
|
36
36
|
}
|
|
37
|
-
exports.ensureType = ensureType;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.wrapInTry =
|
|
3
|
+
exports.wrapInTry = wrapInTry;
|
|
4
4
|
const run_time_assertions_1 = require("run-time-assertions");
|
|
5
5
|
const error_1 = require("./error");
|
|
6
6
|
function wrapInTry(callback, options = {}) {
|
|
@@ -35,4 +35,3 @@ function wrapInTry(callback, options = {}) {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
exports.wrapInTry = wrapInTry;
|
package/dist/cjs/index.js
CHANGED
|
@@ -34,14 +34,14 @@ __exportStar(require("./augments/object/filter-object"), exports);
|
|
|
34
34
|
__exportStar(require("./augments/object/get-or-set"), exports);
|
|
35
35
|
__exportStar(require("./augments/object/has-key"), exports);
|
|
36
36
|
__exportStar(require("./augments/object/jsonify"), exports);
|
|
37
|
+
__exportStar(require("./augments/object/key-count"), exports);
|
|
37
38
|
__exportStar(require("./augments/object/map-object"), exports);
|
|
38
39
|
__exportStar(require("./augments/object/merge-deep"), exports);
|
|
39
40
|
__exportStar(require("./augments/object/merge-property-arrays"), exports);
|
|
40
|
-
__exportStar(require("./augments/object/nested-keys"), exports);
|
|
41
41
|
__exportStar(require("./augments/object/object"), exports);
|
|
42
42
|
__exportStar(require("./augments/object/object-entries"), exports);
|
|
43
|
-
__exportStar(require("./augments/object/old-union-to-intersection"), exports);
|
|
44
43
|
__exportStar(require("./augments/object/pick-deep"), exports);
|
|
44
|
+
__exportStar(require("./augments/object/selection-set"), exports);
|
|
45
45
|
__exportStar(require("./augments/object/typed-has-property"), exports);
|
|
46
46
|
__exportStar(require("./augments/promise/deferred-promise"), exports);
|
|
47
47
|
__exportStar(require("./augments/promise/promise"), exports);
|
|
@@ -56,4 +56,5 @@ __exportStar(require("./augments/truncate-number"), exports);
|
|
|
56
56
|
__exportStar(require("./augments/tuple"), exports);
|
|
57
57
|
__exportStar(require("./augments/type"), exports);
|
|
58
58
|
__exportStar(require("./augments/type-recursion"), exports);
|
|
59
|
+
__exportStar(require("./augments/union"), exports);
|
|
59
60
|
__exportStar(require("./augments/wrap-in-try"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/esm/index.js
CHANGED
|
@@ -18,14 +18,14 @@ export * from './augments/object/filter-object';
|
|
|
18
18
|
export * from './augments/object/get-or-set';
|
|
19
19
|
export * from './augments/object/has-key';
|
|
20
20
|
export * from './augments/object/jsonify';
|
|
21
|
+
export * from './augments/object/key-count';
|
|
21
22
|
export * from './augments/object/map-object';
|
|
22
23
|
export * from './augments/object/merge-deep';
|
|
23
24
|
export * from './augments/object/merge-property-arrays';
|
|
24
|
-
export * from './augments/object/nested-keys';
|
|
25
25
|
export * from './augments/object/object';
|
|
26
26
|
export * from './augments/object/object-entries';
|
|
27
|
-
export * from './augments/object/old-union-to-intersection';
|
|
28
27
|
export * from './augments/object/pick-deep';
|
|
28
|
+
export * from './augments/object/selection-set';
|
|
29
29
|
export * from './augments/object/typed-has-property';
|
|
30
30
|
export * from './augments/promise/deferred-promise';
|
|
31
31
|
export * from './augments/promise/promise';
|
|
@@ -40,4 +40,5 @@ export * from './augments/truncate-number';
|
|
|
40
40
|
export * from './augments/tuple';
|
|
41
41
|
export * from './augments/type';
|
|
42
42
|
export * from './augments/type-recursion';
|
|
43
|
+
export * from './augments/union';
|
|
43
44
|
export * from './augments/wrap-in-try';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { UnionToIntersection } from '../union';
|
|
2
|
+
import { AnyObject } from './any-object';
|
|
3
|
+
/**
|
|
4
|
+
* This is not exported because its order is not stable but it's okay for our simple use case where
|
|
5
|
+
* we simply want to count the size of the union.
|
|
6
|
+
*/
|
|
7
|
+
type UnionToTuple<T> = UnionToIntersection<T extends any ? (t: T) => T : never> extends (args: any) => infer W ? [...UnionToTuple<Exclude<T, W>>, W] : [];
|
|
8
|
+
/**
|
|
9
|
+
* Counts the number of unique keys in an object type. Note that a key of just `string` will count
|
|
10
|
+
* as 1.
|
|
11
|
+
*/
|
|
12
|
+
export type KeyCount<T extends AnyObject> = UnionToTuple<keyof T>['length'];
|
|
13
|
+
export {};
|
|
@@ -12,7 +12,7 @@ export type MappedValues<EntireInputGeneric extends object, MappedValueGeneric>
|
|
|
12
12
|
* @example
|
|
13
13
|
* mapObjectValuesSync({objectToIterateOver: 'initial value'})(callback);
|
|
14
14
|
*/
|
|
15
|
-
export declare function mapObjectValuesSync<EntireInputGeneric extends object>(inputObject: EntireInputGeneric): <OutputObjectGeneric extends object>(mapCallback: (inputKey: keyof EntireInputGeneric, keyValue: EntireInputGeneric[
|
|
15
|
+
export declare function mapObjectValuesSync<EntireInputGeneric extends object>(inputObject: EntireInputGeneric): <OutputObjectGeneric extends object>(mapCallback: (inputKey: keyof EntireInputGeneric, keyValue: EntireInputGeneric[typeof inputKey], fullObject: EntireInputGeneric) => never extends PropertyValueType<OutputObjectGeneric> ? any : PropertyValueType<OutputObjectGeneric>) => OutputObjectGeneric;
|
|
16
16
|
/**
|
|
17
17
|
* Creates a new object with the same properties as the input object, but with values set to the
|
|
18
18
|
* result of mapCallback for each property.
|
|
@@ -3,18 +3,12 @@ import { AnyFunction } from '../function';
|
|
|
3
3
|
import { ArrayElement } from '../type';
|
|
4
4
|
import { TsRecurse, TsRecursionStart, TsRecursionTracker } from '../type-recursion';
|
|
5
5
|
import { AnyObject } from './any-object';
|
|
6
|
-
import { NestedKeys } from './nested-keys';
|
|
7
6
|
export type InnerPickDeep<OriginalObject extends AnyObject, DeepKeys extends any[], Depth extends TsRecursionTracker> = DeepKeys extends [infer CurrentLevelPick, ...infer RemainingKeys] ? Extract<CurrentLevelPick, keyof OriginalObject> extends never ? OriginalObject : {
|
|
8
7
|
[CurrentProp in Extract<CurrentLevelPick, RequiredKeysOf<OriginalObject>>]: InnerPickDeepValue<OriginalObject, CurrentProp, RemainingKeys, Depth>;
|
|
9
8
|
} & {
|
|
10
9
|
[CurrentProp in Extract<CurrentLevelPick, OptionalKeysOf<OriginalObject>>]?: InnerPickDeepValue<OriginalObject, CurrentProp, RemainingKeys, Depth>;
|
|
11
10
|
} : DeepKeys extends [] ? OriginalObject : DeepKeys extends [infer CurrentLevelPick] ? CurrentLevelPick extends keyof OriginalObject ? Pick<OriginalObject, CurrentLevelPick> : never : never;
|
|
12
11
|
type InnerPickDeepValue<OriginalObject, CurrentProp extends keyof OriginalObject, RemainingKeys extends any[], Depth extends TsRecursionTracker> = AnyFunction extends Extract<OriginalObject[CurrentProp], AnyFunction> ? OriginalObject[CurrentProp] | Exclude<OriginalObject[CurrentProp], AnyFunction> : Array<any> extends Extract<OriginalObject[CurrentProp], Array<any>> ? Array<InnerPickDeep<ArrayElement<Extract<OriginalObject[CurrentProp], Array<any>>>, RemainingKeys, TsRecurse<Depth>>> | Exclude<OriginalObject[CurrentProp], Array<any>> : ReadonlyArray<any> extends Extract<OriginalObject[CurrentProp], ReadonlyArray<any>> ? ReadonlyArray<InnerPickDeep<ArrayElement<Extract<OriginalObject[CurrentProp], ReadonlyArray<any>>>, RemainingKeys, TsRecurse<Depth>>> | Exclude<OriginalObject[CurrentProp], ReadonlyArray<any>> : Extract<OriginalObject[CurrentProp], Record<any, any>> extends never ? OriginalObject[CurrentProp] : InnerPickDeep<Extract<OriginalObject[CurrentProp], Record<any, any>>, RemainingKeys, TsRecurse<Depth>> | Exclude<OriginalObject[CurrentProp], Record<any, any>>;
|
|
13
|
-
/**
|
|
14
|
-
* Pick nested keys with more strict type parameter requirements. However, these stricter type
|
|
15
|
-
* parameter requirements often lead to "excessively deep" TS compiler errors.
|
|
16
|
-
*/
|
|
17
|
-
export type PickDeepStrict<OriginalObject extends object, DeepKeys extends NestedKeys<OriginalObject>> = InnerPickDeep<OriginalObject, DeepKeys, TsRecursionStart>;
|
|
18
12
|
/** Pick nested keys. */
|
|
19
13
|
export type PickDeep<OriginalObject extends object, DeepKeys extends PropertyKey[]> = InnerPickDeep<OriginalObject, DeepKeys, TsRecursionStart>;
|
|
20
14
|
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { IsNever, Primitive } from 'type-fest';
|
|
2
|
+
import { TsRecurse, TsRecursionStart, TsRecursionTracker, TsTooMuchRecursion } from '../type-recursion';
|
|
3
|
+
import { UnionToIntersection } from '../union';
|
|
4
|
+
import { AnyObject } from './any-object';
|
|
5
|
+
import { KeyCount } from './key-count';
|
|
6
|
+
import { PropertyValueType } from './object';
|
|
7
|
+
/** All types that won't be recursed into when defining a {@link SelectionSet}. */
|
|
8
|
+
export type SelectionTypesToPreserve = Primitive | RegExp;
|
|
9
|
+
/** A generic selection set without specific keys. */
|
|
10
|
+
export type GenericSelectionSet = {
|
|
11
|
+
[Key in PropertyKey]: boolean | GenericSelectionSet;
|
|
12
|
+
};
|
|
13
|
+
/** Masks an object value with the given {@link SelectionSet}. */
|
|
14
|
+
export type PickSelection<Full extends Readonly<AnyObject>, Selection extends GenericSelectionSet, Depth extends TsRecursionTracker = TsRecursionStart> = Depth extends TsTooMuchRecursion ? ['Error: recursive object depth is too deep.'] : Full extends ReadonlyArray<infer Element extends any> ? (PickSelection<Extract<Element, AnyObject>, Selection, TsRecurse<Depth>> | Exclude<Element, AnyObject>)[] : {
|
|
15
|
+
[Key in keyof Selection as Selection[Key] extends false ? never : Key extends keyof Full ? Key : never]: (Selection[Key] extends GenericSelectionSet ? PickSelection<NonNullable<Extract<Full[Key], AnyObject>>, Selection[Key], TsRecurse<Depth>> : Full[Key]) | Exclude<Full[Key], AnyObject>;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Collapses a selected value to the first part of the selection that contains more than 1 key or
|
|
19
|
+
* that is not an object.
|
|
20
|
+
*/
|
|
21
|
+
export type FirstSelectedValue<Full extends Readonly<AnyObject>, Selection extends GenericSelectionSet, Depth extends TsRecursionTracker = TsRecursionStart> = Depth extends TsTooMuchRecursion ? 'Error: recursive object depth is too deep.' : KeyCount<PickSelection<Full, Selection, Depth>> extends 1 ? Selection[keyof PickSelection<Full, Selection, Depth>] extends GenericSelectionSet ? FirstSelectedValue<Full[keyof PickSelection<Full, Selection, Depth>], Selection[keyof PickSelection<Full, Selection, Depth>], TsRecurse<Depth>> : PropertyValueType<PickSelection<Full, Selection, Depth>> : PickSelection<Full, Selection, Depth>;
|
|
22
|
+
/** Defines a selection set for the given object. */
|
|
23
|
+
export type SelectionSet<Full extends Readonly<AnyObject>, Depth extends TsRecursionTracker = TsRecursionStart> = Depth extends TsTooMuchRecursion ? ['Error: recursive object depth is too deep.'] : Full extends ReadonlyArray<infer FullChild extends AnyObject> ? SelectionSet<FullChild, TsRecurse<Depth>> : Partial<{
|
|
24
|
+
[Key in keyof Full]: IsNever<Exclude<Full[Key], SelectionTypesToPreserve>> extends true ? boolean : boolean | UnionToIntersection<SelectionSet<Full[Key], TsRecurse<Depth>>>;
|
|
25
|
+
}>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -18,14 +18,14 @@ export * from './augments/object/filter-object';
|
|
|
18
18
|
export * from './augments/object/get-or-set';
|
|
19
19
|
export * from './augments/object/has-key';
|
|
20
20
|
export * from './augments/object/jsonify';
|
|
21
|
+
export * from './augments/object/key-count';
|
|
21
22
|
export * from './augments/object/map-object';
|
|
22
23
|
export * from './augments/object/merge-deep';
|
|
23
24
|
export * from './augments/object/merge-property-arrays';
|
|
24
|
-
export * from './augments/object/nested-keys';
|
|
25
25
|
export * from './augments/object/object';
|
|
26
26
|
export * from './augments/object/object-entries';
|
|
27
|
-
export * from './augments/object/old-union-to-intersection';
|
|
28
27
|
export * from './augments/object/pick-deep';
|
|
28
|
+
export * from './augments/object/selection-set';
|
|
29
29
|
export * from './augments/object/typed-has-property';
|
|
30
30
|
export * from './augments/promise/deferred-promise';
|
|
31
31
|
export * from './augments/promise/promise';
|
|
@@ -40,4 +40,5 @@ export * from './augments/truncate-number';
|
|
|
40
40
|
export * from './augments/tuple';
|
|
41
41
|
export * from './augments/type';
|
|
42
42
|
export * from './augments/type-recursion';
|
|
43
|
+
export * from './augments/union';
|
|
43
44
|
export * from './augments/wrap-in-try';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@augment-vir/common",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "29.0.0",
|
|
4
4
|
"homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/electrovir/augment-vir/issues"
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"type-fest": "^4.20.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"typescript": "5.
|
|
32
|
+
"typescript": "5.5.2"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getValueFromNestedKeys = exports.setValueWithNestedKeys = void 0;
|
|
4
|
-
const run_time_assertions_1 = require("run-time-assertions");
|
|
5
|
-
const tuple_1 = require("../tuple");
|
|
6
|
-
const object_1 = require("./object");
|
|
7
|
-
const typed_has_property_1 = require("./typed-has-property");
|
|
8
|
-
/** This mutates the {@link originalObject} input. */
|
|
9
|
-
function setValueWithNestedKeys(originalObject, nestedKeys, value) {
|
|
10
|
-
/**
|
|
11
|
-
* Lots of as any casts in here because these types are, under the hood, pretty complex. Since
|
|
12
|
-
* the inputs and outputs of this function are well typed, these internal as any casts do not
|
|
13
|
-
* affect the external API of this function.
|
|
14
|
-
*/
|
|
15
|
-
const nestedKeysInput = nestedKeys;
|
|
16
|
-
const inputObject = originalObject;
|
|
17
|
-
if ((0, run_time_assertions_1.isRunTimeType)(inputObject, 'array')) {
|
|
18
|
-
inputObject.forEach((entry) => {
|
|
19
|
-
if ((0, object_1.isObject)(entry)) {
|
|
20
|
-
setValueWithNestedKeys(entry, nestedKeysInput, value);
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
else if ((0, tuple_1.isLengthAtLeast)(nestedKeysInput, 2)) {
|
|
25
|
-
/** If there are more keys to traverse into. */
|
|
26
|
-
const nextKey = nestedKeysInput[0];
|
|
27
|
-
if (!(nextKey in inputObject)) {
|
|
28
|
-
inputObject[nextKey] = {};
|
|
29
|
-
}
|
|
30
|
-
const nextParent = inputObject[nextKey];
|
|
31
|
-
setValueWithNestedKeys(nextParent, nestedKeysInput.slice(1), value);
|
|
32
|
-
}
|
|
33
|
-
else if ((0, tuple_1.isLengthAtLeast)(nestedKeysInput, 1)) {
|
|
34
|
-
inputObject[nestedKeysInput[0]] = value;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.setValueWithNestedKeys = setValueWithNestedKeys;
|
|
38
|
-
function getValueFromNestedKeys(originalObject, nestedKeys) {
|
|
39
|
-
/**
|
|
40
|
-
* Lots of as any casts in here because these types are, under the hood, pretty complex. Since
|
|
41
|
-
* the inputs and outputs of this function are well typed, these internal as any casts do not
|
|
42
|
-
* affect the external API of this function.
|
|
43
|
-
*/
|
|
44
|
-
const nestedKeysInput = nestedKeys;
|
|
45
|
-
const inputObject = originalObject;
|
|
46
|
-
if ((0, run_time_assertions_1.isRunTimeType)(inputObject, 'array')) {
|
|
47
|
-
return inputObject.map((entry) => getValueFromNestedKeys(entry, nestedKeys));
|
|
48
|
-
}
|
|
49
|
-
const keyToAccess = nestedKeysInput[0];
|
|
50
|
-
if (!(0, typed_has_property_1.typedHasProperty)(inputObject, keyToAccess)) {
|
|
51
|
-
return undefined;
|
|
52
|
-
}
|
|
53
|
-
const currentValue = inputObject[keyToAccess];
|
|
54
|
-
if (nestedKeysInput.length > 1) {
|
|
55
|
-
return getValueFromNestedKeys(currentValue, nestedKeysInput.slice(1));
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
return currentValue;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
exports.getValueFromNestedKeys = getValueFromNestedKeys;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { isRunTimeType } from 'run-time-assertions';
|
|
2
|
-
import { isLengthAtLeast } from '../tuple';
|
|
3
|
-
import { isObject } from './object';
|
|
4
|
-
import { typedHasProperty } from './typed-has-property';
|
|
5
|
-
/** This mutates the {@link originalObject} input. */
|
|
6
|
-
export function setValueWithNestedKeys(originalObject, nestedKeys, value) {
|
|
7
|
-
/**
|
|
8
|
-
* Lots of as any casts in here because these types are, under the hood, pretty complex. Since
|
|
9
|
-
* the inputs and outputs of this function are well typed, these internal as any casts do not
|
|
10
|
-
* affect the external API of this function.
|
|
11
|
-
*/
|
|
12
|
-
const nestedKeysInput = nestedKeys;
|
|
13
|
-
const inputObject = originalObject;
|
|
14
|
-
if (isRunTimeType(inputObject, 'array')) {
|
|
15
|
-
inputObject.forEach((entry) => {
|
|
16
|
-
if (isObject(entry)) {
|
|
17
|
-
setValueWithNestedKeys(entry, nestedKeysInput, value);
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
else if (isLengthAtLeast(nestedKeysInput, 2)) {
|
|
22
|
-
/** If there are more keys to traverse into. */
|
|
23
|
-
const nextKey = nestedKeysInput[0];
|
|
24
|
-
if (!(nextKey in inputObject)) {
|
|
25
|
-
inputObject[nextKey] = {};
|
|
26
|
-
}
|
|
27
|
-
const nextParent = inputObject[nextKey];
|
|
28
|
-
setValueWithNestedKeys(nextParent, nestedKeysInput.slice(1), value);
|
|
29
|
-
}
|
|
30
|
-
else if (isLengthAtLeast(nestedKeysInput, 1)) {
|
|
31
|
-
inputObject[nestedKeysInput[0]] = value;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
export function getValueFromNestedKeys(originalObject, nestedKeys) {
|
|
35
|
-
/**
|
|
36
|
-
* Lots of as any casts in here because these types are, under the hood, pretty complex. Since
|
|
37
|
-
* the inputs and outputs of this function are well typed, these internal as any casts do not
|
|
38
|
-
* affect the external API of this function.
|
|
39
|
-
*/
|
|
40
|
-
const nestedKeysInput = nestedKeys;
|
|
41
|
-
const inputObject = originalObject;
|
|
42
|
-
if (isRunTimeType(inputObject, 'array')) {
|
|
43
|
-
return inputObject.map((entry) => getValueFromNestedKeys(entry, nestedKeys));
|
|
44
|
-
}
|
|
45
|
-
const keyToAccess = nestedKeysInput[0];
|
|
46
|
-
if (!typedHasProperty(inputObject, keyToAccess)) {
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
const currentValue = inputObject[keyToAccess];
|
|
50
|
-
if (nestedKeysInput.length > 1) {
|
|
51
|
-
return getValueFromNestedKeys(currentValue, nestedKeysInput.slice(1));
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
return currentValue;
|
|
55
|
-
}
|
|
56
|
-
}
|