assign-deep.js 843 B

123456789101112131415161718192021222324252627
  1. "use strict";
  2. module.exports = function (t, a) {
  3. var o1 = { a: 1, b: 2 }, o2 = { b: 3, c: 4 };
  4. a(t(o1, o2), o1, "Returns self");
  5. a.deep(o1, { a: 1, b: 3, c: 4 }, "Single: content");
  6. a.deep(t({}, o1, o2), { a: 1, b: 3, c: 4 }, "Multi argument");
  7. var obj1 = { foo: { bar: 3, marko: true } }
  8. , obj2 = { foo: { elo: 12, marko: false }, miszka: [23] };
  9. var copyObj1 = JSON.parse(JSON.stringify(obj1)), copyObj2 = JSON.parse(JSON.stringify(obj2));
  10. a.deep(t({}, obj1, obj2), { foo: { bar: 3, marko: false, elo: 12 }, miszka: [23] });
  11. // Ensure it's side effects free
  12. a.deep(obj1, copyObj1);
  13. a.deep(obj2, copyObj2);
  14. obj1 = [{ foo: "bar" }];
  15. var assignedObj = [];
  16. t(assignedObj, obj1);
  17. a.deep(assignedObj, [{ foo: "bar" }]);
  18. // Ensure array items are copied and not passed
  19. a.not(assignedObj[0], obj1[0]);
  20. a(t(true), true);
  21. };