UNPKG

815 BJavaScriptView Raw
1'use strict';
2var $ = require('../internals/export');
3var IS_PURE = require('../internals/is-pure');
4var anObject = require('../internals/an-object');
5var aFunction = require('../internals/a-function');
6
7// `Set.prototype.update` method
8// https://github.com/tc39/proposal-collection-methods
9$({ target: 'Map', proto: true, real: true, forced: IS_PURE }, {
10 update: function update(key, callback /* , thunk */) {
11 var map = anObject(this);
12 var length = arguments.length;
13 aFunction(callback);
14 var isPresentInMap = map.has(key);
15 if (!isPresentInMap && length < 3) {
16 throw TypeError('Updating absent value');
17 }
18 var value = isPresentInMap ? map.get(key) : aFunction(length > 2 ? arguments[2] : undefined)(key, map);
19 map.set(key, callback(value, key, map));
20 return map;
21 }
22});