Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

copykitten

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

copykitten - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

15

copykitten.js

@@ -44,2 +44,13 @@ (function (global, factory) {

function deepMerge(a, b) {
props(b).forEach(function (k) {
if (typeof a[k] === 'object' && typeof b[k] === 'object') {
a[k] = a[k].deepMerge(b[k]);
}
else {
a[k] = b[k];
}
});
}
function thaw(source, constructor) {

@@ -73,2 +84,6 @@ return merge(new (constructor || source.constructor), source);

FrozenObject.prototype.deepMerge = updater(function (obj) {
deepMerge(this, obj);
});
FrozenObject.prototype.thaw = function () {

@@ -75,0 +90,0 @@ return thaw(this, Object);

2

package.json
{
"name": "copykitten",
"version": "0.0.4",
"version": "0.0.5",
"description": "Tiny immutable JSON data structures",

@@ -5,0 +5,0 @@ "scripts": {

@@ -43,3 +43,4 @@ # copykitten.js

* [remove(key)](#FrozenObject_remove)
* [merge(props)](#FrozenObject_props)
* [merge(props)](#FrozenObject_merge)
* [deepMerge(props)](#FrozenObject_deepMerge)
* [update(f)](#FrozenObject_update)

@@ -156,2 +157,17 @@ * [thaw()](#FrozenObject_thaw)

<a name="FrozenObject_deepMerge"></a>
#### deepMerge(props)
Like [merge(props)](#FrozenObject_merge) but will recursively merge
nested objects.
```javascript
var a = copykitten.toImmutable({animal: {name: 'Kitten'}});
var b = a.deepMerge({animal: {status: 'hungry'}});
// a is now {animal: {name: 'Kitten'}}
// b is now {animal: {name: 'Kitten', status: 'hungry'}}
```
<a name="FrozenObject_update"></a>

@@ -158,0 +174,0 @@

@@ -166,2 +166,41 @@ var assert = (typeof chai === 'undefined') ?

test('deepMerge', function () {
"use strict";
var obj = copykitten.toImmutable({
title: 'test',
meta: {
author: {
name: 'foo',
role: 'user'
}
}
});
var obj2 = obj.deepMerge({
meta: {
author: {
id: 123,
role: 'admin'
},
date: 'today'
},
other: {
something: 'else'
}
});
assert.deepEqual(JSON.parse(JSON.stringify(obj2)), {
title: 'test',
meta: {
author: {
id: 123,
role: 'admin',
name: 'foo'
},
date: 'today'
},
other: {
something: 'else'
}
});
});
test('JSON.stringify', function () {

@@ -168,0 +207,0 @@ var obj = copykitten.toImmutable({

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc