UNPKG

@voiceflow/common

Version:

Junk drawer of utility functions

18 lines (17 loc) 600 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getOrDefault = void 0; const functional_1 = require("./functional"); /** * 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. */ function getOrDefault(map, key, defaultValue) { if (!map.has(key)) { const value = (0, functional_1.isFunction)(defaultValue) ? defaultValue() : defaultValue; map.set(key, value); return value; } return map.get(key); } exports.getOrDefault = getOrDefault;