source: imaps-frontend/node_modules/core-js/internals/map-upsert.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 995 bytes
Line 
1'use strict';
2var call = require('../internals/function-call');
3var aCallable = require('../internals/a-callable');
4var isCallable = require('../internals/is-callable');
5var anObject = require('../internals/an-object');
6
7var $TypeError = TypeError;
8
9// `Map.prototype.upsert` method
10// https://github.com/tc39/proposal-upsert
11module.exports = function upsert(key, updateFn /* , insertFn */) {
12 var map = anObject(this);
13 var get = aCallable(map.get);
14 var has = aCallable(map.has);
15 var set = aCallable(map.set);
16 var insertFn = arguments.length > 2 ? arguments[2] : undefined;
17 var value;
18 if (!isCallable(updateFn) && !isCallable(insertFn)) {
19 throw new $TypeError('At least one callback required');
20 }
21 if (call(has, map, key)) {
22 value = call(get, map, key);
23 if (isCallable(updateFn)) {
24 value = updateFn(value);
25 call(set, map, key, value);
26 }
27 } else if (isCallable(insertFn)) {
28 value = insertFn();
29 call(set, map, key, value);
30 } return value;
31};
Note: See TracBrowser for help on using the repository browser.