Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

esnext.map.update.js 922B

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