UNPKG

hierarchy-js

Version:

Elegant and lightweight library for working with data structures

21 lines (16 loc) 827 B
'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; var createCopy = function createCopy(item) { if (!item || (typeof item === 'undefined' ? 'undefined' : _typeof(item)) !== 'object') return item; var accumulator = Array.isArray(item) ? [] : {}; return iterator(item, accumulator, createCopy); }; var iterator = function iterator(iterable, accumulator, callback) { for (var key in iterable) { if (iterable.hasOwnProperty(key)) { accumulator[key] = callback(iterable[key]); } } return accumulator; }; module.exports = { createCopy: createCopy, iterator: iterator };