immutable
Advanced tools
Comparing version 0.8.0-SNAPSHOT to 0.8.0
{ | ||
"name": "immutable", | ||
"description": "immutable data-structures in javascript.", | ||
"version": "0.8.0-SNAPSHOT", | ||
"version": "0.8.0", | ||
"main": "src/immutable.js", | ||
@@ -14,3 +14,4 @@ "scripts": { | ||
"dependencies": { | ||
"string-hash": "1.1.0" | ||
"string-hash": "1.1.0", | ||
"persistent-hash-trie": "0.2.x" | ||
}, | ||
@@ -17,0 +18,0 @@ "devDependencies": { |
'use strict' | ||
var u = require('./util') | ||
var h = require('./ht') | ||
var object = require('./object') | ||
var p = require('persistent-hash-trie') | ||
@@ -13,3 +13,3 @@ var secret = {} | ||
var store = h.Trie({}) | ||
var store = p.Trie({}) | ||
@@ -20,3 +20,3 @@ this['-data'] = function(s, data){ | ||
} | ||
return attrs ? this.set(attrs) : this | ||
return attrs ? this.assoc(attrs) : this | ||
} | ||
@@ -29,13 +29,10 @@ | ||
// stealing from object | ||
get: object.prototype.get, | ||
"delete": object.prototype.remove, | ||
remove: object.prototype.remove, | ||
set: function(k, v){ | ||
assoc: function(k, v){ | ||
if ( typeof k === 'object' && typeof k !== null ) { | ||
var keys = Object.keys(k) | ||
return keys.reduce(function(object, key){ return object.set(key, k[key]) }, this) | ||
return keys.reduce(function(object, key){ return object.assoc(key, k[key]) }, this) | ||
} | ||
var t = h.set(this['-data'](secret), h.path(k), k, v) | ||
var t = p.assoc(this['-data'](secret), k, v) | ||
var ret = new array() | ||
@@ -49,4 +46,9 @@ ret['-data'](secret, t) | ||
dissoc: object.prototype.dissoc, | ||
get: object.prototype.get, | ||
has: object.prototype.has, | ||
transient: function(){ | ||
return u.extend([], h.transient(this['-data'](secret))) | ||
return u.extend([], p.transient(this['-data'](secret))) | ||
}, | ||
@@ -53,0 +55,0 @@ push: function(){ |
'use strict' | ||
var h = require('./ht') | ||
var p = require('persistent-hash-trie') | ||
@@ -10,3 +10,3 @@ var secret = {} | ||
var store = h.Trie({}) | ||
var store = p.Trie() | ||
@@ -19,3 +19,3 @@ this['-data'] = function(s, data){ | ||
Object.freeze(this) | ||
return attrs ? this.set(attrs) : this | ||
return attrs ? this.assoc(attrs) : this | ||
} | ||
@@ -26,8 +26,8 @@ | ||
set: function(k, v){ | ||
assoc: function(k, v){ | ||
if ( typeof k === 'object' && typeof k !== null ) { | ||
var keys = Object.keys(k) | ||
return keys.reduce(function(object, key){ return object.set(key, k[key]) }, this) | ||
return keys.reduce(function(object, key){ return object.assoc(key, k[key]) }, this) | ||
} | ||
var t = h.set(this['-data'](secret), h.path(k), k, v) | ||
var t = p.assoc(this['-data'](secret), k, v) | ||
var ret = new object() | ||
@@ -38,22 +38,22 @@ ret['-data'](secret, t) | ||
dissoc: function(k){ | ||
var t = p.dissoc(this['-data'](secret), k) | ||
var ret = new object() | ||
ret['-data'](secret, t) | ||
return ret | ||
}, | ||
get: function(k){ | ||
k = k.toString() | ||
return h.get(this['-data'](secret), h.path(k), k) | ||
return p.get(this['-data'](secret), k) | ||
}, | ||
transient: function(){ | ||
return h.transient(this['-data'](secret)) | ||
}, | ||
has: function(k){ | ||
return h.has(this['-data'](secret), h.path(k), k) | ||
return p.has(this['-data'](secret), k) | ||
}, | ||
remove: function(k){ | ||
var t = h.remove(this['-data'](secret), h.path(k), k) | ||
var ret = new object() | ||
ret['-data'](secret, t) | ||
return ret | ||
transient: function(){ | ||
return p.transient(this['-data'](secret)) | ||
} | ||
} | ||
object.prototype['delete'] = object.prototype.remove | ||
@@ -10,9 +10,2 @@ var a = require('assert'), | ||
// test('it is frozen', function(){ | ||
// var arr = p.array([]) | ||
// arr.x = 4 | ||
// a.equal(arr.x, undefined) | ||
// }) | ||
test('-data is a function', function(){ | ||
@@ -28,8 +21,8 @@ var arr = p.array([]) | ||
a.equal(arr.get, object.get) | ||
a.equal(arr.remove, object.remove) | ||
a.equal(arr['delete'], object['delete']) | ||
a.equal(arr.has, object.has) | ||
a.equal(arr.dissoc, object.dissoc) | ||
}) | ||
test('array.set returns array', function(){ | ||
var arr = p.array().set(1, '2').set({ x: 3 }).set([1, 2, 3]) | ||
test('array.assoc returns array', function(){ | ||
var arr = p.array().assoc(1, '2').assoc({ x: 3 }).assoc([1, 2, 3]) | ||
@@ -119,3 +112,3 @@ a.ok(arr instanceof p.array) | ||
arr = arr.set(100, 3) | ||
arr = arr.assoc(100, 3) | ||
a.equal(arr.length, 101) | ||
@@ -122,0 +115,0 @@ }) |
@@ -39,5 +39,5 @@ var a = require('assert') | ||
test('object.set(k, v)', function(){ | ||
test('object.assoc(k, v)', function(){ | ||
var o = p.object(), | ||
o2 = o.set('x', 3) | ||
o2 = o.assoc('x', 3) | ||
@@ -47,5 +47,5 @@ a.notEqual(o, o2) | ||
test('object.set', function(){ | ||
test('object.assoc', function(){ | ||
var o1 = p.object({ 'x': 3 }), | ||
o2 = o1.set('y', 3).set({ 'z': 3 }) | ||
o2 = o1.assoc('y', 3).assoc({ 'z': 3 }) | ||
@@ -62,3 +62,3 @@ a.ok(o1.has('x')) | ||
test('object.get', function(){ | ||
var o = p.object().set('x', 3) | ||
var o = p.object().assoc('x', 3) | ||
@@ -70,3 +70,3 @@ a.equal(o.get('x'), 3) | ||
test('object.has', function(){ | ||
var o = p.object().set('x', 3) | ||
var o = p.object().assoc('x', 3) | ||
@@ -77,5 +77,5 @@ a.ok(o.has('x')) | ||
test('object.remove', function(){ | ||
var o1 = p.object().set('x', 3), | ||
o2 = o1.remove('x') | ||
test('object.dissoc', function(){ | ||
var o1 = p.object().assoc('x', 3), | ||
o2 = o1.dissoc('x') | ||
@@ -86,5 +86,5 @@ a.ok(o1.has('x')) | ||
test('object.delete alias for object.remove', function(){ | ||
test('object.delete NOT alias for object.dissoc', function(){ | ||
var o = p.object() | ||
a.equal(o.delete, o.remove) | ||
a.equal(o.delete, undefined) | ||
}) | ||
@@ -106,40 +106,1 @@ | ||
}) | ||
// suite('hammer test') | ||
// test('set, get, transient and remove', function(){ | ||
// var range = function(s, e){ | ||
// var a = [] | ||
// for ( var i = s; i < e; i += 1 ) a.push(i) | ||
// return a | ||
// } | ||
// var alpha = 'abcdefghijklmnopqrstuvwxyz'.split('') | ||
// var randNth = function(a){ return a[Math.floor(Math.random() * a.length)] } | ||
// var vals = range(0, 10000).map(function(i){ var o = {}; o[i] = randNth(alpha); return o }) | ||
// var o = vals.reduce(function(o, v){ | ||
// return o.set(v) | ||
// }, p.object()) | ||
// var t = o.transient() | ||
// // check all values are stored, both in the object and the transient | ||
// vals.forEach(function(val){ | ||
// var k = Object.keys(val)[0] | ||
// var v = val[k] | ||
// a.equal(o.get(k), v) | ||
// a.equal(o.has(k), true) | ||
// a.equal(t[k], v) | ||
// }) | ||
// // 'empty' the object | ||
// var empty = vals.reduce(function(o, val){ | ||
// var k = Object.keys(val)[0] | ||
// return o.remove(k) | ||
// }, o) | ||
// a.equal(Object.keys(empty.transient()), 0) | ||
// }) |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 5 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
1
1
15092
2
10
352
+ Addedpersistent-hash-trie@0.2.x
+ Addedpersistent-hash-trie@0.2.4(transitive)