Sha256: 37cde300d3b21d32a87f34f80a51e00656c04b66aba829140a114c426f431937
Contents?: true
Size: 721 Bytes
Versions: 19
Compression:
Stored size: 721 Bytes
Contents
'use strict'; var anObject = require('../internals/an-object'); // `Map.prototype.upsert` method // https://github.com/thumbsupep/proposal-upsert module.exports = function upsert(key, updateFn /* , insertFn */) { var map = anObject(this); var insertFn = arguments.length > 2 ? arguments[2] : undefined; var value; if (typeof updateFn != 'function' && typeof insertFn != 'function') { throw TypeError('At least one callback required'); } if (map.has(key)) { value = map.get(key); if (typeof updateFn == 'function') { value = updateFn(value); map.set(key, value); } } else if (typeof insertFn == 'function') { value = insertFn(); map.set(key, value); } return value; };
Version data entries
19 entries across 18 versions & 7 rubygems