@voiceflow/common
Advanced tools
Comparing version 7.23.0 to 7.24.0
@@ -1,5 +0,2 @@ | ||
/** | ||
* Retrieve the value at the given key inside the map. | ||
* If the key does not exist, insert the default value into the map and return that value. | ||
*/ | ||
export declare const getOrDefault: <K, V>(map: Map<K, V>, key: K, defaultValue: V) => V; | ||
export declare function getOrDefault<K, V>(map: Map<K, V>, key: K, defaultValue: V): V; | ||
export declare function getOrDefault<K, V>(map: Map<K, V>, key: K, getDefaultValue: () => V): V; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getOrDefault = void 0; | ||
const functional_1 = require("./functional"); | ||
/** | ||
@@ -8,9 +9,10 @@ * Retrieve the value at the given key inside the map. | ||
*/ | ||
const getOrDefault = (map, key, defaultValue) => { | ||
function getOrDefault(map, key, defaultValue) { | ||
if (!map.has(key)) { | ||
map.set(key, defaultValue); | ||
return defaultValue; | ||
const value = (0, functional_1.isFunction)(defaultValue) ? defaultValue() : defaultValue; | ||
map.set(key, value); | ||
return value; | ||
} | ||
return map.get(key); | ||
}; | ||
} | ||
exports.getOrDefault = getOrDefault; |
@@ -1,5 +0,2 @@ | ||
/** | ||
* Retrieve the value at the given key inside the map. | ||
* If the key does not exist, insert the default value into the map and return that value. | ||
*/ | ||
export declare const getOrDefault: <K, V>(map: Map<K, V>, key: K, defaultValue: V) => V; | ||
export declare function getOrDefault<K, V>(map: Map<K, V>, key: K, defaultValue: V): V; | ||
export declare function getOrDefault<K, V>(map: Map<K, V>, key: K, getDefaultValue: () => V): V; |
@@ -0,1 +1,2 @@ | ||
import { isFunction } from './functional'; | ||
/** | ||
@@ -5,8 +6,9 @@ * Retrieve the value at the given key inside the map. | ||
*/ | ||
export const getOrDefault = (map, key, defaultValue) => { | ||
export function getOrDefault(map, key, defaultValue) { | ||
if (!map.has(key)) { | ||
map.set(key, defaultValue); | ||
return defaultValue; | ||
const value = isFunction(defaultValue) ? defaultValue() : defaultValue; | ||
map.set(key, value); | ||
return value; | ||
} | ||
return map.get(key); | ||
}; | ||
} |
{ | ||
"name": "@voiceflow/common", | ||
"description": "Junk drawer of utility functions", | ||
"version": "7.23.0", | ||
"version": "7.24.0", | ||
"author": "Voiceflow", | ||
@@ -79,3 +79,3 @@ "bugs": { | ||
}, | ||
"gitHead": "8a42f59e14588817d901cee1d3545040eefa2dee" | ||
"gitHead": "193c9abcd22354535987a5c1adc379f339877785" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
254968
7257