.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / core-js / internals / map-upsert.js
1 'use strict';
2 var anObject = require('../internals/an-object');
3
4 // `Map.prototype.upsert` method
5 // https://github.com/thumbsupep/proposal-upsert
6 module.exports = function upsert(key, updateFn /* , insertFn */) {
7   var map = anObject(this);
8   var insertFn = arguments.length > 2 ? arguments[2] : undefined;
9   var value;
10   if (typeof updateFn != 'function' && typeof insertFn != 'function') {
11     throw TypeError('At least one callback required');
12   }
13   if (map.has(key)) {
14     value = map.get(key);
15     if (typeof updateFn == 'function') {
16       value = updateFn(value);
17       map.set(key, value);
18     }
19   } else if (typeof insertFn == 'function') {
20     value = insertFn();
21     map.set(key, value);
22   } return value;
23 };