@voiceflow/common 7.22.1 → 7.25.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/build/common/utils/array.d.ts +1 -0
- package/build/common/utils/array.js +3 -1
- package/build/common/utils/index.d.ts +1 -0
- package/build/common/utils/index.js +2 -1
- package/build/common/utils/map.d.ts +2 -0
- package/build/common/utils/map.js +17 -0
- package/build/esm/utils/array.d.ts +1 -0
- package/build/esm/utils/array.js +1 -0
- package/build/esm/utils/index.d.ts +1 -0
- package/build/esm/utils/index.js +1 -0
- package/build/esm/utils/map.d.ts +2 -0
- package/build/esm/utils/map.js +13 -0
- package/package.json +2 -2
|
@@ -36,4 +36,5 @@ export declare const isNotNullish: <T>(value: T) => value is NonNullable<T>;
|
|
|
36
36
|
export declare const filterOutNullish: <T>(items: readonly T[]) => NonNullable<T>[];
|
|
37
37
|
export declare const filterAndGetLastRemovedValue: <T>(list: T[], filter: (item: T) => boolean) => [T[], T | null];
|
|
38
38
|
export declare const inferUnion: <T extends ArrayLike<unknown>>(array: T) => import("../types").SafeArray<T[number], T>;
|
|
39
|
+
export declare const toArray: <T>(valueOrArray: T | T[]) => T[];
|
|
39
40
|
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.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;
|
|
3
|
+
exports.toArray = 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)]);
|
|
@@ -123,3 +123,5 @@ const filterAndGetLastRemovedValue = (list, filter) => {
|
|
|
123
123
|
exports.filterAndGetLastRemovedValue = filterAndGetLastRemovedValue;
|
|
124
124
|
const inferUnion = (array) => array;
|
|
125
125
|
exports.inferUnion = inferUnion;
|
|
126
|
+
const toArray = (valueOrArray) => (Array.isArray(valueOrArray) ? valueOrArray : [valueOrArray]);
|
|
127
|
+
exports.toArray = toArray;
|
|
@@ -4,6 +4,7 @@ export * as functional from './functional';
|
|
|
4
4
|
export { generate, generateHash } from './generate';
|
|
5
5
|
export * as id from './id';
|
|
6
6
|
export * as intent from './intent';
|
|
7
|
+
export * as map from './map';
|
|
7
8
|
export * as mathjs from './mathjs';
|
|
8
9
|
export * as normalized from './normalized';
|
|
9
10
|
export * as number from './number';
|
|
@@ -22,7 +22,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
22
22
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.variables = exports.typeguard = exports.timezones = exports.time = exports.string = exports.slot = exports.protocol = exports.promise = exports.object = exports.number = exports.normalized = exports.mathjs = exports.intent = exports.id = exports.generateHash = exports.generate = exports.functional = exports.emails = exports.array = void 0;
|
|
25
|
+
exports.variables = exports.typeguard = exports.timezones = exports.time = exports.string = exports.slot = exports.protocol = exports.promise = exports.object = exports.number = exports.normalized = exports.mathjs = exports.map = exports.intent = exports.id = exports.generateHash = exports.generate = exports.functional = exports.emails = exports.array = void 0;
|
|
26
26
|
exports.array = __importStar(require("./array"));
|
|
27
27
|
exports.emails = __importStar(require("./emails"));
|
|
28
28
|
exports.functional = __importStar(require("./functional"));
|
|
@@ -31,6 +31,7 @@ Object.defineProperty(exports, "generate", { enumerable: true, get: function ()
|
|
|
31
31
|
Object.defineProperty(exports, "generateHash", { enumerable: true, get: function () { return generate_1.generateHash; } });
|
|
32
32
|
exports.id = __importStar(require("./id"));
|
|
33
33
|
exports.intent = __importStar(require("./intent"));
|
|
34
|
+
exports.map = __importStar(require("./map"));
|
|
34
35
|
exports.mathjs = __importStar(require("./mathjs"));
|
|
35
36
|
exports.normalized = __importStar(require("./normalized"));
|
|
36
37
|
exports.number = __importStar(require("./number"));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOrDefault = void 0;
|
|
4
|
+
const functional_1 = require("./functional");
|
|
5
|
+
/**
|
|
6
|
+
* Retrieve the value at the given key inside the map.
|
|
7
|
+
* If the key does not exist, insert the default value into the map and return that value.
|
|
8
|
+
*/
|
|
9
|
+
function getOrDefault(map, key, defaultValue) {
|
|
10
|
+
if (!map.has(key)) {
|
|
11
|
+
const value = (0, functional_1.isFunction)(defaultValue) ? defaultValue() : defaultValue;
|
|
12
|
+
map.set(key, value);
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
return map.get(key);
|
|
16
|
+
}
|
|
17
|
+
exports.getOrDefault = getOrDefault;
|
|
@@ -36,4 +36,5 @@ export declare const isNotNullish: <T>(value: T) => value is NonNullable<T>;
|
|
|
36
36
|
export declare const filterOutNullish: <T>(items: readonly T[]) => NonNullable<T>[];
|
|
37
37
|
export declare const filterAndGetLastRemovedValue: <T>(list: T[], filter: (item: T) => boolean) => [T[], T | null];
|
|
38
38
|
export declare const inferUnion: <T extends ArrayLike<unknown>>(array: T) => import("../types").SafeArray<T[number], T>;
|
|
39
|
+
export declare const toArray: <T>(valueOrArray: T | T[]) => T[];
|
|
39
40
|
export {};
|
package/build/esm/utils/array.js
CHANGED
|
@@ -4,6 +4,7 @@ export * as functional from './functional';
|
|
|
4
4
|
export { generate, generateHash } from './generate';
|
|
5
5
|
export * as id from './id';
|
|
6
6
|
export * as intent from './intent';
|
|
7
|
+
export * as map from './map';
|
|
7
8
|
export * as mathjs from './mathjs';
|
|
8
9
|
export * as normalized from './normalized';
|
|
9
10
|
export * as number from './number';
|
package/build/esm/utils/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export * as functional from './functional';
|
|
|
4
4
|
export { generate, generateHash } from './generate';
|
|
5
5
|
export * as id from './id';
|
|
6
6
|
export * as intent from './intent';
|
|
7
|
+
export * as map from './map';
|
|
7
8
|
export * as mathjs from './mathjs';
|
|
8
9
|
export * as normalized from './normalized';
|
|
9
10
|
export * as number from './number';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isFunction } from './functional';
|
|
2
|
+
/**
|
|
3
|
+
* Retrieve the value at the given key inside the map.
|
|
4
|
+
* If the key does not exist, insert the default value into the map and return that value.
|
|
5
|
+
*/
|
|
6
|
+
export function getOrDefault(map, key, defaultValue) {
|
|
7
|
+
if (!map.has(key)) {
|
|
8
|
+
const value = isFunction(defaultValue) ? defaultValue() : defaultValue;
|
|
9
|
+
map.set(key, value);
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
return map.get(key);
|
|
13
|
+
}
|
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.25.0",
|
|
5
5
|
"author": "Voiceflow",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/voiceflow/libs/issues"
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
"test:single": "NODE_ENV=test ts-mocha --paths --config config/tests/mocharc.yml",
|
|
77
77
|
"test:unit": "NODE_ENV=test nyc --report-dir=nyc_coverage_unit ts-mocha --paths --config config/tests/mocharc.yml 'tests/**/*.unit.ts'"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "667df22d884b655813e09d2fc6ca0adfb3463a8a"
|
|
80
80
|
}
|