@voiceflow/common 7.20.2 → 7.22.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/build/common/constants/environment.js +0 -1
- package/build/common/constants/index.js +0 -1
- package/build/common/constants/intent.js +0 -1
- package/build/common/constants/regexp.js +0 -1
- package/build/common/constants/runtime.js +0 -1
- package/build/common/constants/slot.js +0 -1
- package/build/common/crypto/base64.js +0 -1
- package/build/common/crypto/hex2abc.js +0 -1
- package/build/common/crypto/index.js +0 -1
- package/build/common/crypto/murmurhash.js +0 -1
- package/build/common/crypto/synchronous.js +0 -1
- package/build/common/index.js +0 -1
- package/build/common/types.d.ts +6 -2
- package/build/common/types.js +0 -1
- package/build/common/utils/array.d.ts +12 -2
- package/build/common/utils/array.js +18 -12
- package/build/common/utils/emails.js +0 -1
- package/build/common/utils/functional.d.ts +1 -0
- package/build/common/utils/functional.js +4 -4
- package/build/common/utils/generate.js +0 -1
- package/build/common/utils/id.js +2 -4
- package/build/common/utils/index.js +0 -1
- package/build/common/utils/intent.js +0 -1
- package/build/common/utils/mathjs.js +0 -1
- package/build/common/utils/normalized.js +0 -1
- package/build/common/utils/number.js +0 -1
- package/build/common/utils/object/common.d.ts +26 -0
- package/build/common/utils/object/common.js +63 -0
- package/build/common/utils/object/deepMap.d.ts +5 -0
- package/build/common/utils/object/deepMap.js +76 -0
- package/build/common/utils/object/diff.d.ts +3 -0
- package/build/common/utils/object/diff.js +40 -0
- package/build/common/utils/object/index.d.ts +4 -0
- package/build/common/utils/object/index.js +16 -0
- package/build/common/utils/object/keys.d.ts +4 -0
- package/build/common/utils/object/keys.js +61 -0
- package/build/common/utils/promise.js +0 -1
- package/build/common/utils/protocol.js +0 -1
- package/build/common/utils/slot.js +0 -1
- package/build/common/utils/string.js +0 -1
- package/build/common/utils/time.js +0 -1
- package/build/common/utils/timezones.js +0 -1
- package/build/common/utils/typeguard.js +0 -1
- package/build/common/utils/variables.js +0 -1
- package/build/esm/constants/environment.js +0 -1
- package/build/esm/constants/index.js +0 -1
- package/build/esm/constants/intent.js +0 -1
- package/build/esm/constants/regexp.js +0 -1
- package/build/esm/constants/runtime.js +0 -1
- package/build/esm/constants/slot.js +0 -1
- package/build/esm/crypto/base64.js +0 -1
- package/build/esm/crypto/hex2abc.js +0 -1
- package/build/esm/crypto/index.js +0 -1
- package/build/esm/crypto/murmurhash.js +0 -1
- package/build/esm/crypto/synchronous.js +0 -1
- package/build/esm/index.js +0 -1
- package/build/esm/types.d.ts +6 -2
- package/build/esm/types.js +0 -1
- package/build/esm/utils/array.d.ts +12 -2
- package/build/esm/utils/array.js +16 -11
- package/build/esm/utils/emails.js +0 -1
- package/build/esm/utils/functional.d.ts +1 -0
- package/build/esm/utils/functional.js +2 -3
- package/build/esm/utils/generate.js +0 -1
- package/build/esm/utils/id.js +1 -3
- package/build/esm/utils/index.js +0 -1
- package/build/esm/utils/intent.js +0 -1
- package/build/esm/utils/mathjs.js +0 -1
- package/build/esm/utils/normalized.js +0 -1
- package/build/esm/utils/number.js +0 -1
- package/build/esm/utils/object/common.d.ts +26 -0
- package/build/esm/utils/object/common.js +53 -0
- package/build/esm/utils/object/deepMap.d.ts +5 -0
- package/build/esm/utils/object/deepMap.js +71 -0
- package/build/esm/utils/object/diff.d.ts +3 -0
- package/build/esm/utils/object/diff.js +32 -0
- package/build/esm/utils/object/index.d.ts +4 -0
- package/build/esm/utils/object/index.js +4 -0
- package/build/esm/utils/object/keys.d.ts +4 -0
- package/build/esm/utils/object/keys.js +52 -0
- package/build/esm/utils/promise.js +0 -1
- package/build/esm/utils/protocol.js +0 -1
- package/build/esm/utils/slot.js +0 -1
- package/build/esm/utils/string.js +0 -1
- package/build/esm/utils/time.js +0 -1
- package/build/esm/utils/timezones.js +0 -1
- package/build/esm/utils/typeguard.js +0 -1
- package/build/esm/utils/variables.js +0 -1
- package/package.json +4 -6
- package/build/common/constants/environment.js.map +0 -1
- package/build/common/constants/index.js.map +0 -1
- package/build/common/constants/intent.js.map +0 -1
- package/build/common/constants/regexp.js.map +0 -1
- package/build/common/constants/runtime.js.map +0 -1
- package/build/common/constants/slot.js.map +0 -1
- package/build/common/crypto/base64.js.map +0 -1
- package/build/common/crypto/hex2abc.js.map +0 -1
- package/build/common/crypto/index.js.map +0 -1
- package/build/common/crypto/murmurhash.js.map +0 -1
- package/build/common/crypto/synchronous.js.map +0 -1
- package/build/common/index.js.map +0 -1
- package/build/common/types.js.map +0 -1
- package/build/common/utils/array.js.map +0 -1
- package/build/common/utils/emails.js.map +0 -1
- package/build/common/utils/functional.js.map +0 -1
- package/build/common/utils/generate.js.map +0 -1
- package/build/common/utils/id.js.map +0 -1
- package/build/common/utils/index.js.map +0 -1
- package/build/common/utils/intent.js.map +0 -1
- package/build/common/utils/mathjs.js.map +0 -1
- package/build/common/utils/normalized.js.map +0 -1
- package/build/common/utils/number.js.map +0 -1
- package/build/common/utils/object.d.ts +0 -20
- package/build/common/utils/object.js +0 -113
- package/build/common/utils/object.js.map +0 -1
- package/build/common/utils/promise.js.map +0 -1
- package/build/common/utils/protocol.js.map +0 -1
- package/build/common/utils/slot.js.map +0 -1
- package/build/common/utils/string.js.map +0 -1
- package/build/common/utils/time.js.map +0 -1
- package/build/common/utils/timezones.js.map +0 -1
- package/build/common/utils/typeguard.js.map +0 -1
- package/build/common/utils/variables.js.map +0 -1
- package/build/esm/constants/environment.js.map +0 -1
- package/build/esm/constants/index.js.map +0 -1
- package/build/esm/constants/intent.js.map +0 -1
- package/build/esm/constants/regexp.js.map +0 -1
- package/build/esm/constants/runtime.js.map +0 -1
- package/build/esm/constants/slot.js.map +0 -1
- package/build/esm/crypto/base64.js.map +0 -1
- package/build/esm/crypto/hex2abc.js.map +0 -1
- package/build/esm/crypto/index.js.map +0 -1
- package/build/esm/crypto/murmurhash.js.map +0 -1
- package/build/esm/crypto/synchronous.js.map +0 -1
- package/build/esm/index.js.map +0 -1
- package/build/esm/types.js.map +0 -1
- package/build/esm/utils/array.js.map +0 -1
- package/build/esm/utils/emails.js.map +0 -1
- package/build/esm/utils/functional.js.map +0 -1
- package/build/esm/utils/generate.js.map +0 -1
- package/build/esm/utils/id.js.map +0 -1
- package/build/esm/utils/index.js.map +0 -1
- package/build/esm/utils/intent.js.map +0 -1
- package/build/esm/utils/mathjs.js.map +0 -1
- package/build/esm/utils/normalized.js.map +0 -1
- package/build/esm/utils/number.js.map +0 -1
- package/build/esm/utils/object.d.ts +0 -20
- package/build/esm/utils/object.js +0 -97
- package/build/esm/utils/object.js.map +0 -1
- package/build/esm/utils/promise.js.map +0 -1
- package/build/esm/utils/protocol.js.map +0 -1
- package/build/esm/utils/slot.js.map +0 -1
- package/build/esm/utils/string.js.map +0 -1
- package/build/esm/utils/time.js.map +0 -1
- package/build/esm/utils/timezones.js.map +0 -1
- package/build/esm/utils/typeguard.js.map +0 -1
- package/build/esm/utils/variables.js.map +0 -1
|
@@ -16,4 +16,3 @@ exports.VALID_SAMPLE_CHARACTERS_WITHOUT_CURLY_BRACES_OR_SPACES = `${exports.VALI
|
|
|
16
16
|
exports.VALID_SAMPLE_CHARACTERS = `${exports.VALID_SAMPLE_CHARACTERS_WITHOUT_CURLY_BRACES_OR_SPACES} \\[\\]`;
|
|
17
17
|
// TYLER: lmao I decompiled the ADC front end source code so these regexes are good as it gets 👌
|
|
18
18
|
exports.VALID_SAMPLE_UTTERANCE = `[^${exports.VALID_SAMPLE_CHARACTERS}|]`;
|
|
19
|
-
//# sourceMappingURL=regexp.js.map
|
|
@@ -10,4 +10,3 @@ var murmurhash_1 = require("./murmurhash");
|
|
|
10
10
|
Object.defineProperty(exports, "MurmurHash", { enumerable: true, get: function () { return __importDefault(murmurhash_1).default; } });
|
|
11
11
|
var synchronous_1 = require("./synchronous");
|
|
12
12
|
Object.defineProperty(exports, "Synchronous", { enumerable: true, get: function () { return __importDefault(synchronous_1).default; } });
|
|
13
|
-
//# sourceMappingURL=index.js.map
|
package/build/common/index.js
CHANGED
package/build/common/types.d.ts
CHANGED
|
@@ -15,10 +15,11 @@ export declare type WithRequired<T, K extends keyof T> = Omit<T, K> & Required<P
|
|
|
15
15
|
export declare type Writeable<T> = {
|
|
16
16
|
-readonly [P in keyof T]: T[P];
|
|
17
17
|
};
|
|
18
|
-
export declare type
|
|
18
|
+
export declare type PartialRecord<K extends PropertyKey, T> = Partial<Record<K, T>>;
|
|
19
|
+
export declare type NullableRecord<T> = {
|
|
19
20
|
[K in keyof T]: Nullable<T[K]>;
|
|
20
21
|
};
|
|
21
|
-
export declare type NonNullishRecord<T
|
|
22
|
+
export declare type NonNullishRecord<T> = Required<{
|
|
22
23
|
[K in keyof T]: NonNullable<T[K]>;
|
|
23
24
|
}>;
|
|
24
25
|
export declare type Struct = Record<string, unknown>;
|
|
@@ -34,3 +35,6 @@ export declare type EmptyObject = Record<never, never>;
|
|
|
34
35
|
/** Avoids accidentally converting an immutable array type to a mutable one. */
|
|
35
36
|
export declare type SafeArray<Element, Original> = Original extends Array<Element> ? Element[] : Original extends ReadonlyArray<Element> ? ReadonlyArray<Element> : Original extends ArrayLike<Element> ? ArrayLike<Element> : never;
|
|
36
37
|
export declare type ArrayUnionToIntersection<T extends ArrayLike<unknown>> = SafeArray<T[number], T>;
|
|
38
|
+
export declare type PrimitiveMap<T extends PropertyKey> = {
|
|
39
|
+
[P in T]: P;
|
|
40
|
+
};
|
package/build/common/types.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyRecord, ArrayUnionToIntersection } from "../types";
|
|
1
|
+
import { AnyRecord, ArrayUnionToIntersection, PrimitiveMap } from "../types";
|
|
2
2
|
export declare const unique: <T>(items: T[]) => T[];
|
|
3
3
|
export declare const without: <T>(items: T[], index: number) => T[];
|
|
4
4
|
export declare const withoutValue: <T>(items: T[], value: T) => T[];
|
|
@@ -12,7 +12,16 @@ export declare const head: <T>(items: T[]) => [T, T[]];
|
|
|
12
12
|
export declare const tail: <T>(items: T[]) => [T[], T];
|
|
13
13
|
export declare const reorder: <T>(items: T[], fromIndex: number, toIndex: number) => T[];
|
|
14
14
|
export declare const separate: <T>(items: T[], predicate: (item: T, index: number) => boolean) => [T[], T[]];
|
|
15
|
-
|
|
15
|
+
interface CreateEntries {
|
|
16
|
+
<T extends PropertyKey>(array: readonly T[]): Array<readonly [T, T]>;
|
|
17
|
+
<T extends AnyRecord, K extends PropertyKey = string>(array: readonly T[], getKey: (value: T) => K): Array<readonly [K, T]>;
|
|
18
|
+
}
|
|
19
|
+
interface CreateMap {
|
|
20
|
+
<T extends PropertyKey>(array: readonly T[]): PrimitiveMap<T>;
|
|
21
|
+
<T extends AnyRecord, K extends PropertyKey = string>(array: readonly T[], getKey: (value: T) => K): Record<K, T>;
|
|
22
|
+
}
|
|
23
|
+
export declare const createEntries: CreateEntries;
|
|
24
|
+
export declare const createMap: CreateMap;
|
|
16
25
|
export declare const findUnion: <T>(lhs: T[], rhs: T[]) => {
|
|
17
26
|
rhsOnly: T[];
|
|
18
27
|
lhsOnly: T[];
|
|
@@ -27,3 +36,4 @@ export declare const isNotNullish: <T>(value: T) => value is NonNullable<T>;
|
|
|
27
36
|
export declare const filterOutNullish: <T>(items: readonly T[]) => NonNullable<T>[];
|
|
28
37
|
export declare const filterAndGetLastRemovedValue: <T>(list: T[], filter: (item: T) => boolean) => [T[], T | null];
|
|
29
38
|
export declare const inferUnion: <T extends ArrayLike<unknown>>(array: T) => import("../types").SafeArray<T[number], T>;
|
|
39
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.inferUnion = exports.filterAndGetLastRemovedValue = exports.filterOutNullish = exports.isNotNullish = exports.isNullish = exports.asyncForEach = exports.hasIdenticalMembers = exports.diff = exports.findUnion = exports.createMap = exports.separate = exports.reorder = exports.tail = exports.head = exports.toggleMembership = exports.append = exports.insertAll = exports.insert = exports.replace = exports.withoutValues = exports.withoutValue = exports.without = exports.unique = void 0;
|
|
3
|
+
exports.inferUnion = exports.filterAndGetLastRemovedValue = exports.filterOutNullish = exports.isNotNullish = exports.isNullish = exports.asyncForEach = exports.hasIdenticalMembers = exports.diff = exports.findUnion = exports.createMap = exports.createEntries = exports.separate = exports.reorder = exports.tail = exports.head = exports.toggleMembership = exports.append = exports.insertAll = exports.insert = exports.replace = exports.withoutValues = exports.withoutValue = exports.without = exports.unique = void 0;
|
|
4
4
|
const unique = (items) => Array.from(new Set(items));
|
|
5
5
|
exports.unique = unique;
|
|
6
6
|
const without = (items, index) => (index < 0 ? items : [...items.slice(0, index), ...items.slice(index + 1)]);
|
|
@@ -53,24 +53,31 @@ const separate = (items, predicate) => items.reduce(([passAcc, failAcc], item, i
|
|
|
53
53
|
return [passAcc, failAcc];
|
|
54
54
|
}, [[], []]);
|
|
55
55
|
exports.separate = separate;
|
|
56
|
-
const
|
|
56
|
+
const createEntries = (array, getKey = (value) => value) => array.map((item) => [getKey(item), item]);
|
|
57
|
+
exports.createEntries = createEntries;
|
|
58
|
+
const createMap = (array, getKey = (value) => value) => Object.fromEntries((0, exports.createEntries)(array, getKey));
|
|
57
59
|
exports.createMap = createMap;
|
|
58
60
|
const findUnion = (lhs, rhs) => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
// using sets instead of arrays since .has is O(1)
|
|
62
|
+
const lSet = new Set(lhs);
|
|
63
|
+
const rSet = new Set(rhs);
|
|
64
|
+
const unionSet = new Set([...lhs, ...rhs]);
|
|
65
|
+
const result = { rhsOnly: [], lhsOnly: [], union: [] };
|
|
66
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
67
|
+
for (const item of unionSet) {
|
|
68
|
+
if (lSet.has(item)) {
|
|
69
|
+
if (rSet.has(item)) {
|
|
70
|
+
result.union.push(item);
|
|
64
71
|
}
|
|
65
72
|
else {
|
|
66
|
-
|
|
73
|
+
result.lhsOnly.push(item);
|
|
67
74
|
}
|
|
68
75
|
}
|
|
69
76
|
else {
|
|
70
|
-
|
|
77
|
+
result.rhsOnly.push(item);
|
|
71
78
|
}
|
|
72
|
-
|
|
73
|
-
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
74
81
|
};
|
|
75
82
|
exports.findUnion = findUnion;
|
|
76
83
|
const diff = (lhs, rhs) => {
|
|
@@ -116,4 +123,3 @@ const filterAndGetLastRemovedValue = (list, filter) => {
|
|
|
116
123
|
exports.filterAndGetLastRemovedValue = filterAndGetLastRemovedValue;
|
|
117
124
|
const inferUnion = (array) => array;
|
|
118
125
|
exports.inferUnion = inferUnion;
|
|
119
|
-
//# sourceMappingURL=array.js.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Nullish } from '../types';
|
|
2
|
+
export declare const isFunction: <T extends (...args: any[]) => any = (...args: any[]) => any>(value: unknown) => value is T;
|
|
2
3
|
export declare type Transform<T = any, R = T> = (value: T) => R;
|
|
3
4
|
export interface Compose {
|
|
4
5
|
<R, T1>(t0: Transform<T1, R>): (value: T1) => R;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.withEffect = exports.chainVoidAsync = exports.chainAsync = exports.chainVoid = exports.chain = exports.stringify = exports.identity = exports.noop = exports.compose = void 0;
|
|
3
|
+
exports.withEffect = exports.chainVoidAsync = exports.chainAsync = exports.chainVoid = exports.chain = exports.stringify = exports.identity = exports.noop = exports.compose = exports.isFunction = void 0;
|
|
4
|
+
const isFunction = (value) => typeof value === 'function';
|
|
5
|
+
exports.isFunction = isFunction;
|
|
4
6
|
const compose = (...transforms) => (value) => {
|
|
5
7
|
if (transforms.length === 1) {
|
|
6
8
|
return transforms[0](value);
|
|
@@ -11,8 +13,7 @@ const compose = (...transforms) => (value) => {
|
|
|
11
13
|
return transforms.reduceRight((acc, transform) => transform(acc), value);
|
|
12
14
|
};
|
|
13
15
|
exports.compose = compose;
|
|
14
|
-
|
|
15
|
-
const noop = () => { };
|
|
16
|
+
const noop = () => undefined;
|
|
16
17
|
exports.noop = noop;
|
|
17
18
|
const identity = (value) => value;
|
|
18
19
|
exports.identity = identity;
|
|
@@ -61,4 +62,3 @@ const withEffect = (callback) => (value) => {
|
|
|
61
62
|
return value;
|
|
62
63
|
};
|
|
63
64
|
exports.withEffect = withEffect;
|
|
64
|
-
//# sourceMappingURL=functional.js.map
|
package/build/common/utils/id.js
CHANGED
|
@@ -7,8 +7,7 @@ exports.remapObjectIDs = exports.objectID = exports.cuid = void 0;
|
|
|
7
7
|
const bson_objectid_1 = __importDefault(require("bson-objectid"));
|
|
8
8
|
const cuid_1 = __importDefault(require("cuid"));
|
|
9
9
|
exports.cuid = cuid_1.default;
|
|
10
|
-
const
|
|
11
|
-
const deep_map_keys_1 = __importDefault(require("deep-map-keys"));
|
|
10
|
+
const object_1 = require("./object");
|
|
12
11
|
const objectID = () => new bson_objectid_1.default().toHexString();
|
|
13
12
|
exports.objectID = objectID;
|
|
14
13
|
const remapObjectIDs = (object, lookupMap) => {
|
|
@@ -19,7 +18,6 @@ const remapObjectIDs = (object, lookupMap) => {
|
|
|
19
18
|
}
|
|
20
19
|
return value;
|
|
21
20
|
};
|
|
22
|
-
return (0,
|
|
21
|
+
return (0, object_1.deepMapKeys)((0, object_1.deepMap)(object, mapping), mapping);
|
|
23
22
|
};
|
|
24
23
|
exports.remapObjectIDs = remapObjectIDs;
|
|
25
|
-
//# sourceMappingURL=id.js.map
|
|
@@ -149,4 +149,3 @@ exports.injectUtteranceSpaces = injectUtteranceSpaces;
|
|
|
149
149
|
// VF.HELP -> help
|
|
150
150
|
const cleanVFIntentName = (intentName) => (intentName.startsWith('VF.') ? intentName.slice(3).toLowerCase() : intentName);
|
|
151
151
|
exports.cleanVFIntentName = cleanVFIntentName;
|
|
152
|
-
//# sourceMappingURL=intent.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AnyRecord, Struct } from "../../types";
|
|
2
|
+
export declare const selectField: <K extends string | number>(field: K) => <T extends { [key in K]: any; }>(obj: T) => T[K];
|
|
3
|
+
export declare const selectID: <T extends {
|
|
4
|
+
id: any;
|
|
5
|
+
}>(obj: T) => T["id"];
|
|
6
|
+
export declare const selectKey: <T extends {
|
|
7
|
+
key: any;
|
|
8
|
+
}>(obj: T) => T["key"];
|
|
9
|
+
export declare const selectValue: <T extends {
|
|
10
|
+
value: any;
|
|
11
|
+
}>(obj: T) => T["value"];
|
|
12
|
+
export declare const isObject: (obj: unknown) => obj is Struct;
|
|
13
|
+
export declare const hasProperty: <T, K extends string | keyof T>(obj: T, key: K) => obj is T & Record<K, unknown>;
|
|
14
|
+
export declare const omit: <T, K extends keyof T>(obj: T, keys: K[]) => Omit<T, K>;
|
|
15
|
+
export declare const pick: <T, K extends keyof T>(obj: T, keys: K[]) => Pick<T, K>;
|
|
16
|
+
interface PickOmitBy {
|
|
17
|
+
<T extends AnyRecord>(obj: T, predicate: (key: keyof T, value: T[keyof T]) => boolean): Partial<T>;
|
|
18
|
+
<T extends AnyRecord, R extends AnyRecord>(obj: T, predicate: (key: keyof T, value: T[keyof T]) => boolean): R;
|
|
19
|
+
}
|
|
20
|
+
export declare const pickBy: PickOmitBy;
|
|
21
|
+
export declare const omitBy: PickOmitBy;
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated use pickBy instead
|
|
24
|
+
*/
|
|
25
|
+
export declare const filterEntries: PickOmitBy;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.filterEntries = exports.omitBy = exports.pickBy = exports.pick = exports.omit = exports.hasProperty = exports.isObject = exports.selectValue = exports.selectKey = exports.selectID = exports.selectField = void 0;
|
|
4
|
+
const selectField = (field) => (obj) => obj[field];
|
|
5
|
+
exports.selectField = selectField;
|
|
6
|
+
exports.selectID = (0, exports.selectField)('id');
|
|
7
|
+
exports.selectKey = (0, exports.selectField)('key');
|
|
8
|
+
exports.selectValue = (0, exports.selectField)('value');
|
|
9
|
+
const isObject = (obj) => obj !== null && typeof obj === 'object';
|
|
10
|
+
exports.isObject = isObject;
|
|
11
|
+
const hasProperty = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
|
|
12
|
+
exports.hasProperty = hasProperty;
|
|
13
|
+
const omit = (obj, keys) => {
|
|
14
|
+
const newObj = Object.assign({}, obj);
|
|
15
|
+
if (keys.length === 0) {
|
|
16
|
+
return newObj;
|
|
17
|
+
}
|
|
18
|
+
if (keys.length === 1) {
|
|
19
|
+
delete newObj[keys[0]];
|
|
20
|
+
return newObj;
|
|
21
|
+
}
|
|
22
|
+
if (keys.length === 2) {
|
|
23
|
+
delete newObj[keys[0]];
|
|
24
|
+
delete newObj[keys[1]];
|
|
25
|
+
return newObj;
|
|
26
|
+
}
|
|
27
|
+
return keys.reduce((acc, key) => {
|
|
28
|
+
delete acc[key];
|
|
29
|
+
return acc;
|
|
30
|
+
}, newObj);
|
|
31
|
+
};
|
|
32
|
+
exports.omit = omit;
|
|
33
|
+
const pick = (obj, keys) => {
|
|
34
|
+
if (keys.length === 0) {
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
if (keys.length === 1) {
|
|
38
|
+
return { [keys[0]]: obj[keys[0]] };
|
|
39
|
+
}
|
|
40
|
+
if (keys.length === 2) {
|
|
41
|
+
return { [keys[0]]: obj[keys[0]], [keys[1]]: obj[keys[1]] };
|
|
42
|
+
}
|
|
43
|
+
return keys.reduce((acc, key) => Object.assign(acc, { [key]: obj[key] }), {});
|
|
44
|
+
};
|
|
45
|
+
exports.pick = pick;
|
|
46
|
+
const pickBy = (obj, predicate) => Object.entries(obj).reduce((acc, [key, value]) => {
|
|
47
|
+
if (predicate(key, value)) {
|
|
48
|
+
acc[key] = value;
|
|
49
|
+
}
|
|
50
|
+
return acc;
|
|
51
|
+
}, {});
|
|
52
|
+
exports.pickBy = pickBy;
|
|
53
|
+
const omitBy = (obj, predicate) => Object.entries(obj).reduce((acc, [key, value]) => {
|
|
54
|
+
if (predicate(key, value)) {
|
|
55
|
+
delete acc[key];
|
|
56
|
+
}
|
|
57
|
+
return acc;
|
|
58
|
+
}, Object.assign({}, obj));
|
|
59
|
+
exports.omitBy = omitBy;
|
|
60
|
+
/**
|
|
61
|
+
* @deprecated use pickBy instead
|
|
62
|
+
*/
|
|
63
|
+
exports.filterEntries = exports.pickBy;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Struct } from "../../types";
|
|
2
|
+
export declare const deepMap: <T = Struct>(object: unknown, mapFunction: (value: unknown, key: string | number) => unknown, options?: {
|
|
3
|
+
inPlace?: boolean;
|
|
4
|
+
}) => T;
|
|
5
|
+
export declare const deepMapKeys: <T = Struct>(object: unknown, mapFunction: (key: string, value: unknown) => string) => T;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deepMapKeys = exports.deepMap = void 0;
|
|
4
|
+
const common_1 = require("./common");
|
|
5
|
+
const deepMap = (object, mapFunction, options = {}) => {
|
|
6
|
+
const cache = new WeakMap();
|
|
7
|
+
const mapArray = (arr) => {
|
|
8
|
+
if (cache.has(arr)) {
|
|
9
|
+
return cache.get(arr);
|
|
10
|
+
}
|
|
11
|
+
const result = options.inPlace ? arr : [];
|
|
12
|
+
cache.set(arr, result);
|
|
13
|
+
const { length } = arr;
|
|
14
|
+
for (let index = 0; index < length; index++) {
|
|
15
|
+
result[index] = map(arr[index], index);
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
};
|
|
19
|
+
const mapObject = (obj) => {
|
|
20
|
+
if (cache.has(obj)) {
|
|
21
|
+
return cache.get(obj);
|
|
22
|
+
}
|
|
23
|
+
const result = options.inPlace ? obj : {};
|
|
24
|
+
cache.set(obj, result);
|
|
25
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
26
|
+
for (const key of Object.keys(obj)) {
|
|
27
|
+
result[key] = map(obj[key], key);
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
const map = (value, key) => {
|
|
32
|
+
if (Array.isArray(value))
|
|
33
|
+
return mapArray(value);
|
|
34
|
+
if ((0, common_1.isObject)(value))
|
|
35
|
+
return mapObject(value);
|
|
36
|
+
return mapFunction(value, key);
|
|
37
|
+
};
|
|
38
|
+
return map(object);
|
|
39
|
+
};
|
|
40
|
+
exports.deepMap = deepMap;
|
|
41
|
+
const deepMapKeys = (object, mapFunction) => {
|
|
42
|
+
const cache = new WeakMap();
|
|
43
|
+
const mapArray = (arr) => {
|
|
44
|
+
if (cache.has(arr)) {
|
|
45
|
+
return cache.get(arr);
|
|
46
|
+
}
|
|
47
|
+
const result = [];
|
|
48
|
+
cache.set(arr, result);
|
|
49
|
+
const { length } = arr;
|
|
50
|
+
for (let i = 0; i < length; i++) {
|
|
51
|
+
result.push(map(arr[i]));
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
};
|
|
55
|
+
const mapObject = (obj) => {
|
|
56
|
+
if (cache.has(obj)) {
|
|
57
|
+
return cache.get(obj);
|
|
58
|
+
}
|
|
59
|
+
const result = {};
|
|
60
|
+
cache.set(obj, result);
|
|
61
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
62
|
+
for (const key of Object.keys(obj)) {
|
|
63
|
+
result[mapFunction(key, obj[key])] = map(obj[key]);
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
};
|
|
67
|
+
const map = (value) => {
|
|
68
|
+
if (Array.isArray(value))
|
|
69
|
+
return mapArray(value);
|
|
70
|
+
if ((0, common_1.isObject)(value))
|
|
71
|
+
return mapObject(value);
|
|
72
|
+
return value;
|
|
73
|
+
};
|
|
74
|
+
return map(object);
|
|
75
|
+
};
|
|
76
|
+
exports.deepMapKeys = deepMapKeys;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { AnyRecord, DeepPartial } from "../../types";
|
|
2
|
+
export declare const getDiff: <S extends AnyRecord>(object: S, base: S, compare?: <T>(left: T, right: T) => boolean) => DeepPartial<S>;
|
|
3
|
+
export declare const getTopLevelDiff: <S extends AnyRecord>(object: S, base: S, compare?: <T>(left: T, right: T) => boolean) => Partial<S>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getTopLevelDiff = exports.getDiff = void 0;
|
|
7
|
+
const transform_1 = __importDefault(require("lodash/transform"));
|
|
8
|
+
const common_1 = require("./common");
|
|
9
|
+
const defaultCompare = (left, right) => left === right;
|
|
10
|
+
const getDiff = (object, base, compare = defaultCompare) => {
|
|
11
|
+
const changes = (object, base) => (0, transform_1.default)(object, (result, value, key) => {
|
|
12
|
+
var _a;
|
|
13
|
+
if (!compare(value, base[key])) {
|
|
14
|
+
if ((0, common_1.isObject)(value) && (0, common_1.isObject)(base[key])) {
|
|
15
|
+
// eslint-disable-next-line no-param-reassign
|
|
16
|
+
result[key] = changes(value, base[key]);
|
|
17
|
+
if (Object.keys((_a = result[key]) !== null && _a !== void 0 ? _a : {}).length === 0) {
|
|
18
|
+
// eslint-disable-next-line no-param-reassign
|
|
19
|
+
delete result[key];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
// eslint-disable-next-line no-param-reassign
|
|
24
|
+
result[key] = value;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return changes(object, base);
|
|
29
|
+
};
|
|
30
|
+
exports.getDiff = getDiff;
|
|
31
|
+
const getTopLevelDiff = (object, base, compare = defaultCompare) => {
|
|
32
|
+
const changes = (object, base) => (0, transform_1.default)(object, (result, value, key) => {
|
|
33
|
+
if (!compare(value, base[key])) {
|
|
34
|
+
// eslint-disable-next-line no-param-reassign
|
|
35
|
+
result[key] = value;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return changes(object, base);
|
|
39
|
+
};
|
|
40
|
+
exports.getTopLevelDiff = getTopLevelDiff;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./common"), exports);
|
|
14
|
+
__exportStar(require("./deepMap"), exports);
|
|
15
|
+
__exportStar(require("./diff"), exports);
|
|
16
|
+
__exportStar(require("./keys"), exports);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { AnyRecord } from "../../types";
|
|
2
|
+
export declare const getKeys: <T>(obj: T) => (keyof T)[];
|
|
3
|
+
export declare const getIn: <T, K extends string | keyof T>(rawObj: T, key: K | K[], def?: any, index?: number) => rawObj is T & Record<K, unknown>;
|
|
4
|
+
export declare const setIn: (obj: AnyRecord, path: unknown, value: unknown) => any;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.setIn = exports.getIn = exports.getKeys = void 0;
|
|
7
|
+
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
8
|
+
const toPath_1 = __importDefault(require("lodash/toPath"));
|
|
9
|
+
const getKeys = (obj) => Object.keys(obj);
|
|
10
|
+
exports.getKeys = getKeys;
|
|
11
|
+
const getIn = (rawObj, key, def, index = 0) => {
|
|
12
|
+
const path = (0, toPath_1.default)(key);
|
|
13
|
+
let obj = rawObj;
|
|
14
|
+
let i = index;
|
|
15
|
+
if (path.length === 1) {
|
|
16
|
+
return obj[path[0]];
|
|
17
|
+
}
|
|
18
|
+
while (obj && i < path.length) {
|
|
19
|
+
obj = obj[path[i++]];
|
|
20
|
+
}
|
|
21
|
+
return obj === undefined ? def : obj;
|
|
22
|
+
};
|
|
23
|
+
exports.getIn = getIn;
|
|
24
|
+
const setIn = (obj, path, value) => {
|
|
25
|
+
const res = {};
|
|
26
|
+
const pathArray = (0, toPath_1.default)(path);
|
|
27
|
+
let resVal = res;
|
|
28
|
+
let index = 0;
|
|
29
|
+
for (; index < pathArray.length - 1; index++) {
|
|
30
|
+
const currentPath = pathArray[index];
|
|
31
|
+
if (resVal[currentPath]) {
|
|
32
|
+
resVal = resVal[currentPath];
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const currentObj = (0, exports.getIn)(obj, pathArray.slice(0, index + 1));
|
|
36
|
+
if (currentObj) {
|
|
37
|
+
resVal[currentPath] = (0, cloneDeep_1.default)(currentObj);
|
|
38
|
+
resVal = resVal[currentPath];
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
const nextPath = pathArray[index + 1];
|
|
42
|
+
resVal[currentPath] = +nextPath >= 0 ? [] : {};
|
|
43
|
+
resVal = resVal[currentPath];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if ((index === 0 ? obj : resVal)[pathArray[index]] === value) {
|
|
47
|
+
return obj;
|
|
48
|
+
}
|
|
49
|
+
if (value === undefined) {
|
|
50
|
+
delete resVal[pathArray[index]];
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
resVal[pathArray[index]] = value;
|
|
54
|
+
}
|
|
55
|
+
const result = Object.assign(Object.assign({}, obj), res);
|
|
56
|
+
if (index === 0 && value === undefined) {
|
|
57
|
+
delete result[pathArray[index]];
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
};
|
|
61
|
+
exports.setIn = setIn;
|
|
@@ -17,4 +17,3 @@ exports.getUniqueSamples = getUniqueSamples;
|
|
|
17
17
|
// spread all synonyms into string array ['car, automobile', 'plane, jet'] => ['car', 'automobile', 'plane', 'jet']
|
|
18
18
|
const getAllSamples = (inputs = []) => inputs.flatMap((input) => input.split(',')).filter((sample) => !!sample.trim());
|
|
19
19
|
exports.getAllSamples = getAllSamples;
|
|
20
|
-
//# sourceMappingURL=slot.js.map
|
|
@@ -5,4 +5,3 @@ const createTypeguardCreator = () => (values) => (value) => !!value && (Array.is
|
|
|
5
5
|
exports.createTypeguardCreator = createTypeguardCreator;
|
|
6
6
|
const createTypedTypeguardCreator = () => (values) => (value) => Array.isArray(values) ? values.includes(value.type) : value.type === values;
|
|
7
7
|
exports.createTypedTypeguardCreator = createTypedTypeguardCreator;
|
|
8
|
-
//# sourceMappingURL=typeguard.js.map
|