_cloneMap.js 676 B

12345678910111213141516171819202122
  1. import addMapEntry from './_addMapEntry.js';
  2. import arrayReduce from './_arrayReduce.js';
  3. import mapToArray from './_mapToArray.js';
  4. /** Used to compose bitmasks for cloning. */
  5. var CLONE_DEEP_FLAG = 1;
  6. /**
  7. * Creates a clone of `map`.
  8. *
  9. * @private
  10. * @param {Object} map The map to clone.
  11. * @param {Function} cloneFunc The function to clone values.
  12. * @param {boolean} [isDeep] Specify a deep clone.
  13. * @returns {Object} Returns the cloned map.
  14. */
  15. function cloneMap(map, isDeep, cloneFunc) {
  16. var array = isDeep ? cloneFunc(mapToArray(map), CLONE_DEEP_FLAG) : mapToArray(map);
  17. return arrayReduce(array, addMapEntry, new map.constructor);
  18. }
  19. export default cloneMap;