index.mjs 605 B

12345678910111213141516171819202122232425262728
  1. export function klona(val) {
  2. var k, out, tmp;
  3. if (Array.isArray(val)) {
  4. out = Array(k=val.length);
  5. while (k--) out[k] = (tmp=val[k]) && typeof tmp === 'object' ? klona(tmp) : tmp;
  6. return out;
  7. }
  8. if (Object.prototype.toString.call(val) === '[object Object]') {
  9. out = {}; // null
  10. for (k in val) {
  11. if (k === '__proto__') {
  12. Object.defineProperty(out, k, {
  13. value: klona(val[k]),
  14. configurable: true,
  15. enumerable: true,
  16. writable: true,
  17. });
  18. } else {
  19. out[k] = (tmp=val[k]) && typeof tmp === 'object' ? klona(tmp) : tmp;
  20. }
  21. }
  22. return out;
  23. }
  24. return val;
  25. }