@voiceflow/common 7.23.0 → 7.24.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.
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* If the key does not exist, insert the default value into the map and return that value.
|
|
4
|
-
*/
|
|
5
|
-
export declare const getOrDefault: <K, V>(map: Map<K, V>, key: K, defaultValue: V) => V;
|
|
1
|
+
export declare function getOrDefault<K, V>(map: Map<K, V>, key: K, defaultValue: V): V;
|
|
2
|
+
export declare function getOrDefault<K, V>(map: Map<K, V>, key: K, getDefaultValue: () => V): V;
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getOrDefault = void 0;
|
|
4
|
+
const functional_1 = require("./functional");
|
|
4
5
|
/**
|
|
5
6
|
* Retrieve the value at the given key inside the map.
|
|
6
7
|
* If the key does not exist, insert the default value into the map and return that value.
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
|
+
function getOrDefault(map, key, defaultValue) {
|
|
9
10
|
if (!map.has(key)) {
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
const value = (0, functional_1.isFunction)(defaultValue) ? defaultValue() : defaultValue;
|
|
12
|
+
map.set(key, value);
|
|
13
|
+
return value;
|
|
12
14
|
}
|
|
13
15
|
return map.get(key);
|
|
14
|
-
}
|
|
16
|
+
}
|
|
15
17
|
exports.getOrDefault = getOrDefault;
|
package/build/esm/utils/map.d.ts
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* If the key does not exist, insert the default value into the map and return that value.
|
|
4
|
-
*/
|
|
5
|
-
export declare const getOrDefault: <K, V>(map: Map<K, V>, key: K, defaultValue: V) => V;
|
|
1
|
+
export declare function getOrDefault<K, V>(map: Map<K, V>, key: K, defaultValue: V): V;
|
|
2
|
+
export declare function getOrDefault<K, V>(map: Map<K, V>, key: K, getDefaultValue: () => V): V;
|
package/build/esm/utils/map.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import { isFunction } from './functional';
|
|
1
2
|
/**
|
|
2
3
|
* Retrieve the value at the given key inside the map.
|
|
3
4
|
* If the key does not exist, insert the default value into the map and return that value.
|
|
4
5
|
*/
|
|
5
|
-
export
|
|
6
|
+
export function getOrDefault(map, key, defaultValue) {
|
|
6
7
|
if (!map.has(key)) {
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
const value = isFunction(defaultValue) ? defaultValue() : defaultValue;
|
|
9
|
+
map.set(key, value);
|
|
10
|
+
return value;
|
|
9
11
|
}
|
|
10
12
|
return map.get(key);
|
|
11
|
-
}
|
|
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.24.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": "193c9abcd22354535987a5c1adc379f339877785"
|
|
80
80
|
}
|