_cloneSet.js 676 B

12345678910111213141516171819202122
  1. import addSetEntry from './_addSetEntry.js';
  2. import arrayReduce from './_arrayReduce.js';
  3. import setToArray from './_setToArray.js';
  4. /** Used to compose bitmasks for cloning. */
  5. var CLONE_DEEP_FLAG = 1;
  6. /**
  7. * Creates a clone of `set`.
  8. *
  9. * @private
  10. * @param {Object} set The set 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 set.
  14. */
  15. function cloneSet(set, isDeep, cloneFunc) {
  16. var array = isDeep ? cloneFunc(setToArray(set), CLONE_DEEP_FLAG) : setToArray(set);
  17. return arrayReduce(array, addSetEntry, new set.constructor);
  18. }
  19. export default cloneSet;