UNPKG

@voiceflow/common

Version:

Junk drawer of utility functions

14 lines (13 loc) 444 B
import { isFunction } from './functional.js'; /** * 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 function getOrDefault(map, key, defaultValue) { if (!map.has(key)) { const value = isFunction(defaultValue) ? defaultValue() : defaultValue; map.set(key, value); return value; } return map.get(key); }