@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
|
@@ -13,4 +13,3 @@ export const VALID_SAMPLE_CHARACTERS_WITHOUT_CURLY_BRACES_OR_SPACES = `${VALID_S
|
|
|
13
13
|
export const VALID_SAMPLE_CHARACTERS = `${VALID_SAMPLE_CHARACTERS_WITHOUT_CURLY_BRACES_OR_SPACES} \\[\\]`;
|
|
14
14
|
// TYLER: lmao I decompiled the ADC front end source code so these regexes are good as it gets 👌
|
|
15
15
|
export const VALID_SAMPLE_UTTERANCE = `[^${VALID_SAMPLE_CHARACTERS}|]`;
|
|
16
|
-
//# sourceMappingURL=regexp.js.map
|
package/build/esm/index.js
CHANGED
package/build/esm/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/esm/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 {};
|
package/build/esm/utils/array.js
CHANGED
|
@@ -37,23 +37,29 @@ export const separate = (items, predicate) => items.reduce(([passAcc, failAcc],
|
|
|
37
37
|
}
|
|
38
38
|
return [passAcc, failAcc];
|
|
39
39
|
}, [[], []]);
|
|
40
|
-
export const
|
|
40
|
+
export const createEntries = (array, getKey = (value) => value) => array.map((item) => [getKey(item), item]);
|
|
41
|
+
export const createMap = (array, getKey = (value) => value) => Object.fromEntries(createEntries(array, getKey));
|
|
41
42
|
export const findUnion = (lhs, rhs) => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
// using sets instead of arrays since .has is O(1)
|
|
44
|
+
const lSet = new Set(lhs);
|
|
45
|
+
const rSet = new Set(rhs);
|
|
46
|
+
const unionSet = new Set([...lhs, ...rhs]);
|
|
47
|
+
const result = { rhsOnly: [], lhsOnly: [], union: [] };
|
|
48
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
49
|
+
for (const item of unionSet) {
|
|
50
|
+
if (lSet.has(item)) {
|
|
51
|
+
if (rSet.has(item)) {
|
|
52
|
+
result.union.push(item);
|
|
47
53
|
}
|
|
48
54
|
else {
|
|
49
|
-
|
|
55
|
+
result.lhsOnly.push(item);
|
|
50
56
|
}
|
|
51
57
|
}
|
|
52
58
|
else {
|
|
53
|
-
|
|
59
|
+
result.rhsOnly.push(item);
|
|
54
60
|
}
|
|
55
|
-
|
|
56
|
-
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
57
63
|
};
|
|
58
64
|
export const diff = (lhs, rhs) => {
|
|
59
65
|
const { lhsOnly, rhsOnly } = findUnion(lhs, rhs);
|
|
@@ -90,4 +96,3 @@ export const filterAndGetLastRemovedValue = (list, filter) => {
|
|
|
90
96
|
return [filteredList, lastItem];
|
|
91
97
|
};
|
|
92
98
|
export const inferUnion = (array) => array;
|
|
93
|
-
//# 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,3 +1,4 @@
|
|
|
1
|
+
export const isFunction = (value) => typeof value === 'function';
|
|
1
2
|
export const compose = (...transforms) => (value) => {
|
|
2
3
|
if (transforms.length === 1) {
|
|
3
4
|
return transforms[0](value);
|
|
@@ -7,8 +8,7 @@ export const compose = (...transforms) => (value) => {
|
|
|
7
8
|
}
|
|
8
9
|
return transforms.reduceRight((acc, transform) => transform(acc), value);
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
-
export const noop = () => { };
|
|
11
|
+
export const noop = () => undefined;
|
|
12
12
|
export const identity = (value) => value;
|
|
13
13
|
export const stringify = (value) => (typeof value === 'string' ? value : String(value));
|
|
14
14
|
export const chain = (...fns) => (...args) => {
|
|
@@ -49,4 +49,3 @@ export const withEffect = (callback) => (value) => {
|
|
|
49
49
|
callback(value);
|
|
50
50
|
return value;
|
|
51
51
|
};
|
|
52
|
-
//# sourceMappingURL=functional.js.map
|
package/build/esm/utils/id.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import ObjectId from 'bson-objectid';
|
|
2
2
|
import cuid from 'cuid';
|
|
3
|
-
import deepMap from '
|
|
4
|
-
import deepMapKeys from 'deep-map-keys';
|
|
3
|
+
import { deepMap, deepMapKeys } from './object';
|
|
5
4
|
export { cuid };
|
|
6
5
|
export const objectID = () => new ObjectId().toHexString();
|
|
7
6
|
export const remapObjectIDs = (object, lookupMap) => {
|
|
@@ -14,4 +13,3 @@ export const remapObjectIDs = (object, lookupMap) => {
|
|
|
14
13
|
};
|
|
15
14
|
return deepMapKeys(deepMap(object, mapping), mapping);
|
|
16
15
|
};
|
|
17
|
-
//# sourceMappingURL=id.js.map
|
package/build/esm/utils/index.js
CHANGED
|
@@ -3,4 +3,3 @@ export const NON_ALPHANUMERIC_REGEXP = /\W/g;
|
|
|
3
3
|
export const convertToWord = (value) => numberToWords.toWords(value).replace(NON_ALPHANUMERIC_REGEXP, ' ');
|
|
4
4
|
export const isInRange = (target, min, max) => target >= min && target <= max;
|
|
5
5
|
export const clamp = (value, min, max) => Math.max(Math.min(value, max), min);
|
|
6
|
-
//# sourceMappingURL=number.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,53 @@
|
|
|
1
|
+
export const selectField = (field) => (obj) => obj[field];
|
|
2
|
+
export const selectID = selectField('id');
|
|
3
|
+
export const selectKey = selectField('key');
|
|
4
|
+
export const selectValue = selectField('value');
|
|
5
|
+
export const isObject = (obj) => obj !== null && typeof obj === 'object';
|
|
6
|
+
export const hasProperty = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
|
|
7
|
+
export const omit = (obj, keys) => {
|
|
8
|
+
const newObj = Object.assign({}, obj);
|
|
9
|
+
if (keys.length === 0) {
|
|
10
|
+
return newObj;
|
|
11
|
+
}
|
|
12
|
+
if (keys.length === 1) {
|
|
13
|
+
delete newObj[keys[0]];
|
|
14
|
+
return newObj;
|
|
15
|
+
}
|
|
16
|
+
if (keys.length === 2) {
|
|
17
|
+
delete newObj[keys[0]];
|
|
18
|
+
delete newObj[keys[1]];
|
|
19
|
+
return newObj;
|
|
20
|
+
}
|
|
21
|
+
return keys.reduce((acc, key) => {
|
|
22
|
+
delete acc[key];
|
|
23
|
+
return acc;
|
|
24
|
+
}, newObj);
|
|
25
|
+
};
|
|
26
|
+
export const pick = (obj, keys) => {
|
|
27
|
+
if (keys.length === 0) {
|
|
28
|
+
return {};
|
|
29
|
+
}
|
|
30
|
+
if (keys.length === 1) {
|
|
31
|
+
return { [keys[0]]: obj[keys[0]] };
|
|
32
|
+
}
|
|
33
|
+
if (keys.length === 2) {
|
|
34
|
+
return { [keys[0]]: obj[keys[0]], [keys[1]]: obj[keys[1]] };
|
|
35
|
+
}
|
|
36
|
+
return keys.reduce((acc, key) => Object.assign(acc, { [key]: obj[key] }), {});
|
|
37
|
+
};
|
|
38
|
+
export const pickBy = (obj, predicate) => Object.entries(obj).reduce((acc, [key, value]) => {
|
|
39
|
+
if (predicate(key, value)) {
|
|
40
|
+
acc[key] = value;
|
|
41
|
+
}
|
|
42
|
+
return acc;
|
|
43
|
+
}, {});
|
|
44
|
+
export const omitBy = (obj, predicate) => Object.entries(obj).reduce((acc, [key, value]) => {
|
|
45
|
+
if (predicate(key, value)) {
|
|
46
|
+
delete acc[key];
|
|
47
|
+
}
|
|
48
|
+
return acc;
|
|
49
|
+
}, Object.assign({}, obj));
|
|
50
|
+
/**
|
|
51
|
+
* @deprecated use pickBy instead
|
|
52
|
+
*/
|
|
53
|
+
export const filterEntries = 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,71 @@
|
|
|
1
|
+
import { isObject } from './common';
|
|
2
|
+
export const deepMap = (object, mapFunction, options = {}) => {
|
|
3
|
+
const cache = new WeakMap();
|
|
4
|
+
const mapArray = (arr) => {
|
|
5
|
+
if (cache.has(arr)) {
|
|
6
|
+
return cache.get(arr);
|
|
7
|
+
}
|
|
8
|
+
const result = options.inPlace ? arr : [];
|
|
9
|
+
cache.set(arr, result);
|
|
10
|
+
const { length } = arr;
|
|
11
|
+
for (let index = 0; index < length; index++) {
|
|
12
|
+
result[index] = map(arr[index], index);
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
};
|
|
16
|
+
const mapObject = (obj) => {
|
|
17
|
+
if (cache.has(obj)) {
|
|
18
|
+
return cache.get(obj);
|
|
19
|
+
}
|
|
20
|
+
const result = options.inPlace ? obj : {};
|
|
21
|
+
cache.set(obj, result);
|
|
22
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
23
|
+
for (const key of Object.keys(obj)) {
|
|
24
|
+
result[key] = map(obj[key], key);
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
const map = (value, key) => {
|
|
29
|
+
if (Array.isArray(value))
|
|
30
|
+
return mapArray(value);
|
|
31
|
+
if (isObject(value))
|
|
32
|
+
return mapObject(value);
|
|
33
|
+
return mapFunction(value, key);
|
|
34
|
+
};
|
|
35
|
+
return map(object);
|
|
36
|
+
};
|
|
37
|
+
export const deepMapKeys = (object, mapFunction) => {
|
|
38
|
+
const cache = new WeakMap();
|
|
39
|
+
const mapArray = (arr) => {
|
|
40
|
+
if (cache.has(arr)) {
|
|
41
|
+
return cache.get(arr);
|
|
42
|
+
}
|
|
43
|
+
const result = [];
|
|
44
|
+
cache.set(arr, result);
|
|
45
|
+
const { length } = arr;
|
|
46
|
+
for (let i = 0; i < length; i++) {
|
|
47
|
+
result.push(map(arr[i]));
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
};
|
|
51
|
+
const mapObject = (obj) => {
|
|
52
|
+
if (cache.has(obj)) {
|
|
53
|
+
return cache.get(obj);
|
|
54
|
+
}
|
|
55
|
+
const result = {};
|
|
56
|
+
cache.set(obj, result);
|
|
57
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
58
|
+
for (const key of Object.keys(obj)) {
|
|
59
|
+
result[mapFunction(key, obj[key])] = map(obj[key]);
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
};
|
|
63
|
+
const map = (value) => {
|
|
64
|
+
if (Array.isArray(value))
|
|
65
|
+
return mapArray(value);
|
|
66
|
+
if (isObject(value))
|
|
67
|
+
return mapObject(value);
|
|
68
|
+
return value;
|
|
69
|
+
};
|
|
70
|
+
return map(object);
|
|
71
|
+
};
|
|
@@ -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,32 @@
|
|
|
1
|
+
import _transform from 'lodash/transform';
|
|
2
|
+
import { isObject } from './common';
|
|
3
|
+
const defaultCompare = (left, right) => left === right;
|
|
4
|
+
export const getDiff = (object, base, compare = defaultCompare) => {
|
|
5
|
+
const changes = (object, base) => _transform(object, (result, value, key) => {
|
|
6
|
+
var _a;
|
|
7
|
+
if (!compare(value, base[key])) {
|
|
8
|
+
if (isObject(value) && isObject(base[key])) {
|
|
9
|
+
// eslint-disable-next-line no-param-reassign
|
|
10
|
+
result[key] = changes(value, base[key]);
|
|
11
|
+
if (Object.keys((_a = result[key]) !== null && _a !== void 0 ? _a : {}).length === 0) {
|
|
12
|
+
// eslint-disable-next-line no-param-reassign
|
|
13
|
+
delete result[key];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
// eslint-disable-next-line no-param-reassign
|
|
18
|
+
result[key] = value;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
return changes(object, base);
|
|
23
|
+
};
|
|
24
|
+
export const getTopLevelDiff = (object, base, compare = defaultCompare) => {
|
|
25
|
+
const changes = (object, base) => _transform(object, (result, value, key) => {
|
|
26
|
+
if (!compare(value, base[key])) {
|
|
27
|
+
// eslint-disable-next-line no-param-reassign
|
|
28
|
+
result[key] = value;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return changes(object, base);
|
|
32
|
+
};
|
|
@@ -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,52 @@
|
|
|
1
|
+
import _cloneDeep from 'lodash/cloneDeep';
|
|
2
|
+
import _toPath from 'lodash/toPath';
|
|
3
|
+
export const getKeys = (obj) => Object.keys(obj);
|
|
4
|
+
export const getIn = (rawObj, key, def, index = 0) => {
|
|
5
|
+
const path = _toPath(key);
|
|
6
|
+
let obj = rawObj;
|
|
7
|
+
let i = index;
|
|
8
|
+
if (path.length === 1) {
|
|
9
|
+
return obj[path[0]];
|
|
10
|
+
}
|
|
11
|
+
while (obj && i < path.length) {
|
|
12
|
+
obj = obj[path[i++]];
|
|
13
|
+
}
|
|
14
|
+
return obj === undefined ? def : obj;
|
|
15
|
+
};
|
|
16
|
+
export const setIn = (obj, path, value) => {
|
|
17
|
+
const res = {};
|
|
18
|
+
const pathArray = _toPath(path);
|
|
19
|
+
let resVal = res;
|
|
20
|
+
let index = 0;
|
|
21
|
+
for (; index < pathArray.length - 1; index++) {
|
|
22
|
+
const currentPath = pathArray[index];
|
|
23
|
+
if (resVal[currentPath]) {
|
|
24
|
+
resVal = resVal[currentPath];
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const currentObj = getIn(obj, pathArray.slice(0, index + 1));
|
|
28
|
+
if (currentObj) {
|
|
29
|
+
resVal[currentPath] = _cloneDeep(currentObj);
|
|
30
|
+
resVal = resVal[currentPath];
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
const nextPath = pathArray[index + 1];
|
|
34
|
+
resVal[currentPath] = +nextPath >= 0 ? [] : {};
|
|
35
|
+
resVal = resVal[currentPath];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if ((index === 0 ? obj : resVal)[pathArray[index]] === value) {
|
|
39
|
+
return obj;
|
|
40
|
+
}
|
|
41
|
+
if (value === undefined) {
|
|
42
|
+
delete resVal[pathArray[index]];
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
resVal[pathArray[index]] = value;
|
|
46
|
+
}
|
|
47
|
+
const result = Object.assign(Object.assign({}, obj), res);
|
|
48
|
+
if (index === 0 && value === undefined) {
|
|
49
|
+
delete result[pathArray[index]];
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
};
|
package/build/esm/utils/slot.js
CHANGED
|
@@ -8,4 +8,3 @@ export const addPrebuiltEntities = (entities, prebuiltEntities) => entities.map(
|
|
|
8
8
|
export const getUniqueSamples = (input) => _uniqBy(input.split(','), (sample) => sample.toLowerCase());
|
|
9
9
|
// spread all synonyms into string array ['car, automobile', 'plane, jet'] => ['car', 'automobile', 'plane', 'jet']
|
|
10
10
|
export const getAllSamples = (inputs = []) => inputs.flatMap((input) => input.split(',')).filter((sample) => !!sample.trim());
|
|
11
|
-
//# sourceMappingURL=slot.js.map
|
package/build/esm/utils/time.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
export const createTypeguardCreator = () => (values) => (value) => !!value && (Array.isArray(values) ? values.includes(value) : values === value);
|
|
2
2
|
export const createTypedTypeguardCreator = () => (values) => (value) => Array.isArray(values) ? values.includes(value.type) : value.type === values;
|
|
3
|
-
//# sourceMappingURL=typeguard.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voiceflow/common",
|
|
3
3
|
"description": "Junk drawer of utility functions",
|
|
4
|
-
"version": "7.
|
|
4
|
+
"version": "7.22.1",
|
|
5
5
|
"author": "Voiceflow",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/voiceflow/libs/issues"
|
|
@@ -11,10 +11,7 @@
|
|
|
11
11
|
"bson-objectid": "^2.0.1",
|
|
12
12
|
"crypto-js": "^4.1.1",
|
|
13
13
|
"cuid": "^2.1.8",
|
|
14
|
-
"dayjs": "
|
|
15
|
-
"deep-map": "2.0.0",
|
|
16
|
-
"deep-map-keys": "2.0.1",
|
|
17
|
-
"es6-weak-map": "2.0.3",
|
|
14
|
+
"dayjs": "1.10.7",
|
|
18
15
|
"lodash": "^4.17.21",
|
|
19
16
|
"murmurhash-wasm": "^1.3.0",
|
|
20
17
|
"number-to-words": "^1.2.4",
|
|
@@ -37,6 +34,7 @@
|
|
|
37
34
|
"mocha": "9.1.3",
|
|
38
35
|
"nyc": "^15.1.0",
|
|
39
36
|
"rimraf": "^3.0.2",
|
|
37
|
+
"sinon": "^10.0.0",
|
|
40
38
|
"ts-mocha": "^8.0.0",
|
|
41
39
|
"ts-node": "10.5.0",
|
|
42
40
|
"tsconfig-paths": "3.12.0",
|
|
@@ -78,5 +76,5 @@
|
|
|
78
76
|
"test:single": "NODE_ENV=test ts-mocha --paths --config config/tests/mocharc.yml",
|
|
79
77
|
"test:unit": "NODE_ENV=test nyc --report-dir=nyc_coverage_unit ts-mocha --paths --config config/tests/mocharc.yml 'tests/**/*.unit.ts'"
|
|
80
78
|
},
|
|
81
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "6f4ffd66f86bd1888f89fa1f44b431386544ccf0"
|
|
82
80
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"environment.js","sourceRoot":"","sources":["../../../src/constants/environment.ts"],"names":[],"mappings":";;;AAAA,IAAY,WAQX;AARD,WAAY,WAAW;IACrB,wCAAyB,CAAA;IACzB,0CAA2B,CAAA;IAC3B,8BAAe,CAAA;IACf,0BAAW,CAAA;IACX,4BAAa,CAAA;IACb,8EAA8E;IAC9E,kCAAmB,CAAA;AACrB,CAAC,EARW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAQtB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/constants/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gDAA8B;AAC9B,2CAAyB;AACzB,2CAAyB;AACzB,4CAA0B;AAC1B,yCAAuB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"intent.js","sourceRoot":"","sources":["../../../src/constants/intent.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"regexp.js","sourceRoot":"","sources":["../../../src/constants/regexp.ts"],"names":[],"mappings":";;;AAAa,QAAA,YAAY,GAAG,IAAI,CAAC;AAEpB,QAAA,WAAW,GAAG,wCAAwC,CAAC;AAEvD,QAAA,kBAAkB,GAAG,QAAQ,CAAC;AAE9B,QAAA,wBAAwB,GAAG,eAAe,CAAC;AAE3C,QAAA,eAAe,GAAG,QAAQ,CAAC;AAExC,0FAA0F;AAC7E,QAAA,qBAAqB,GAAG,GAAG,uBAAe,wBAAwB,CAAC;AAEhF,0EAA0E;AAC1E,qDAAqD;AACrD,kFAAkF;AACrE,QAAA,sBAAsB,GAAG,GAAG,6BAAqB,0GAA0G,CAAC;AAE5J,QAAA,sDAAsD,GAAG,GAAG,8BAAsB,QAAQ,CAAC;AAE3F,QAAA,uBAAuB,GAAG,GAAG,8DAAsD,SAAS,CAAC;AAE1G,iGAAiG;AACpF,QAAA,sBAAsB,GAAG,KAAK,+BAAuB,IAAI,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../../src/constants/runtime.ts"],"names":[],"mappings":";;;AAAa,QAAA,YAAY,GAAG,KAAK,CAAC"}
|