Socket
Socket
Sign inDemoInstall

immutable

Package Overview
Dependencies
2
Maintainers
1
Versions
101
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.0 to 1.2.0

2

package.json
{
"name": "immutable",
"description": "efficient immutable data-structures in javascript.",
"version": "1.1.0",
"version": "1.2.0",
"main": "src/immutable.js",

@@ -6,0 +6,0 @@ "keywords": [

@@ -5,2 +5,3 @@ 'use strict';

var util = require('./util')
var object = require('./object')

@@ -150,4 +151,6 @@ // exported constructor

return seed
}
},
}
// value equality!
equal: object.prototype.equal
}

@@ -130,3 +130,20 @@ 'use strict';

}, new object())
},
// value equality!
equal: function(val1){
var val2 = this
if ( val1 === val2 ) return true;
if ( !val1 || !val1.immutable ) return false;
var equal = function(v1, v2){
if ( v1.equal ) return v1.equal(v2)
else return v1 === v2
}
var equal1 = val1.every(function(v, k){ return equal(v, val2.get(k)) })
var equal2 = val2.every(function(v, k){ return equal(v, val1.get(k)) })
return equal1 && equal2
}
}

@@ -275,2 +275,56 @@ var a = require('assert')

describe('equal', function(){
it('should return false if the value is not an immutable object', function(){
var arr = im.array()
a.equal(arr.equal({}), false)
a.equal(arr.equal(1), false)
a.equal(arr.equal('a'), false)
a.equal(arr.equal(null), false)
a.equal(arr.equal(undefined), false)
})
it('should equal itself', function(){
var arr = im.array()
a.equal(arr.equal(arr), true)
})
it('should make two empty objects equal', function(){
a.equal(im.array().equal(im.array()), true)
})
it('should return false for two structurally different objects', function(){
var o1 = im.array([1, 2, 3])
var o2 = im.array([1, 2, 3, 4])
a.equal(o1.equal(o2), false)
})
it('should return true for two structurally equal objects', function(){
var o1 = im.array([1, 2, 3, 4])
var o2 = im.array([1, 2, 3, 4])
a.equal(o1.equal(o2), true)
})
it('should return false for two different mutable objects as properties', function(){
var o1 = im.array([{}])
var o2 = im.array([{}])
a.equal(o1.equal(o2), false)
})
it('should recurse with equal', function(){
var val1 = im.object({ x: 1 })
var val2 = im.object({ x: 1 })
var o1 = im.array([val1])
var o2 = im.array([val2])
a.equal(o1.equal(o2), true)
})
})
})

@@ -261,2 +261,56 @@ var a = require('assert')

})
describe('equal', function(){
it('should return false if the value is not an immutable object', function(){
var obj = im.object()
a.equal(obj.equal({}), false)
a.equal(obj.equal(1), false)
a.equal(obj.equal('a'), false)
a.equal(obj.equal(null), false)
a.equal(obj.equal(undefined), false)
})
it('should equal itself', function(){
var obj = im.object()
a.equal(obj.equal(obj), true)
})
it('should make two empty objects equal', function(){
a.equal(im.object().equal(im.object()), true)
})
it('should return false for two structurally different objects', function(){
var o1 = im.object({ x: 3 })
var o2 = im.object({ y: 3 })
a.equal(o1.equal(o2), false)
})
it('should return true for two structurally equal objects', function(){
var o1 = im.object({ x: 3 })
var o2 = im.object({ x: 3 })
a.equal(o1.equal(o2), true)
})
it('should return false for two different mutable objects as properties', function(){
var o1 = im.object({ x: {} })
var o2 = im.object({ x: {} })
a.equal(o1.equal(o2), false)
})
it('should recurse with equal', function(){
var val1 = im.object({ x: 1 })
var val2 = im.object({ x: 1 })
var o1 = im.object({ x: val1 })
var o2 = im.object({ x: val2 })
a.equal(o1.equal(o2), true)
})
})
})

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc