+2
-1
| { | ||
| "name": "planet" | ||
| , "version": "0.14.6" | ||
| , "version": "0.14.7" | ||
| , "author": "Enrique Erne (http://mild.ch/)" | ||
@@ -27,2 +27,3 @@ , "description": "collaboratively edit anything" | ||
| , "optimist": ">= 0.6.0" | ||
| , "tool": "1.0.0" | ||
| } | ||
@@ -29,0 +30,0 @@ , "devDependencies": { |
+4
-4
| var Emitter = require('events').EventEmitter, | ||
| set = require('./lib/util').set, | ||
| get = require('./lib/util').get, | ||
| merge = require('./lib/util').merge, | ||
| isArray = require('./lib/util').isArray; | ||
| set = require('tool').set, | ||
| get = require('tool').get, | ||
| merge = require('tool').merge, | ||
| isArray = require('tool').isArray; | ||
@@ -7,0 +7,0 @@ |
+2
-1
@@ -423,3 +423,4 @@ # Planet | ||
| - [Socket.IO](http://socket.io/) 0.9.x | ||
| - Optimist 0.4.x | ||
| - [Optimist](https://npmjs.org/package/optimist) 0.6.x | ||
| - [Tool](https://github.com/thisconnect/tool) 1.0.0 | ||
-64
| var isArray = Array.isArray || function(o){ | ||
| return toString.call(o) === '[object Array]'; | ||
| }; | ||
| var utils = module.exports = { | ||
| isArray: isArray, | ||
| setCharAt: function(s, i, chars){ | ||
| return s.substr(0, i) + chars + s.substr(i + chars.length); | ||
| }, | ||
| merge: function merge(o1, o2){ | ||
| for (var p in o2) { | ||
| o1[p] = ( | ||
| o1[p] != null | ||
| && o2[p] != null | ||
| && !isArray(o1[p]) | ||
| && !isArray(o2[p]) | ||
| && typeof o1[p] == 'object' | ||
| && typeof o2[p] == 'object' | ||
| ) ? merge(o1[p], o2[p]) : o2[p]; | ||
| } | ||
| return o1; | ||
| }, | ||
| get: function(o, path){ | ||
| for (var i = 0, l = path.length; i < l; i++){ | ||
| // setup test for this | ||
| if (hasOwnProperty.call(o, path[i])) o = o[path[i]]; | ||
| else return o[path[i]]; | ||
| } | ||
| return o; | ||
| }, | ||
| set: function(o, path, value){ | ||
| path = path.slice(0); | ||
| var key = path.pop(), | ||
| len = path.length, | ||
| i = 0, | ||
| current; | ||
| if (!(/^(string|number)$/.test(typeof key))) return null; | ||
| while (len--){ | ||
| current = path[i++]; | ||
| if (typeof o[current] == 'string' | ||
| && typeof key == 'number' | ||
| && typeof value != 'object' | ||
| ){ | ||
| value = utils.setCharAt(o[current], key, value); | ||
| key = current; | ||
| break; | ||
| } | ||
| o = current in o ? o[current] : (o[current] = {}); | ||
| // setup test for this | ||
| // o = hasOwnProperty.call(o, current) ? o[current] : (o[current] = {}); | ||
| } | ||
| o[key] = value; | ||
| return o; | ||
| } | ||
| }; |
| var expect = require('expect.js'); | ||
| var merge = require('../../lib/util').merge; | ||
| describe('Planet Utils: Merge', function(){ | ||
| it('should be a function', function(){ | ||
| expect(merge).to.be.a('function'); | ||
| }); | ||
| it('should merge objects', function(){ | ||
| var r1 = merge({a: 0}, {a: 1}), | ||
| r2 = merge({a: 1}, {a: 0}); | ||
| expect(r1).to.eql({a: 1}); | ||
| expect(r2).to.eql({a: 0}); | ||
| }); | ||
| it('should merge objects with different keys', function(){ | ||
| var r1 = merge({a: 0}, {b: 1}), | ||
| r2 = merge({a: 1}, {b: 0}); | ||
| expect(r1).to.eql({a: 0, b: 1}); | ||
| expect(r2).to.eql({a: 1, b: 0}); | ||
| }); | ||
| it('should merge objects with different and indentical keys', function(){ | ||
| var r = merge({a: 1, b: 1}, {a: 0, c: 2}); | ||
| expect(r).to.eql({a: 0, b: 1, c: 2}); | ||
| }); | ||
| it('should merge empty objects', function(){ | ||
| var r1 = merge({a: 0}, {}), | ||
| r2 = merge({}, {a: 0}); | ||
| expect(r1).to.eql({a: 0}); | ||
| expect(r2).to.eql({a: 0}); | ||
| }); | ||
| it('should merge properties with a value of null', function(){ | ||
| var r1 = merge({a: 0}, {a: null}), | ||
| r2 = merge({a: null}, {a: 0}); | ||
| expect(r1).to.eql({a: null}); | ||
| expect(r2).to.eql({a: 0}); | ||
| }); | ||
| it('should merge properties with a value of false', function(){ | ||
| var r1 = merge({a: false}, {a: null}), | ||
| r2 = merge({a: null}, {a: false}); | ||
| expect(r1).to.eql({a: null}); | ||
| expect(r2).to.eql({a: false}); | ||
| }); | ||
| // Arrays | ||
| it('should treat arrays as values', function(){ | ||
| var r1 = merge({a: [2]}, {a: 1}), | ||
| r2 = merge({a: 1}, {a: [2]}); | ||
| expect(r1).to.eql({a: 1}); | ||
| expect(r2).to.eql({a: [2]}); | ||
| }); | ||
| it('should differenciate between arrays and objects', function(){ | ||
| var r1 = merge({a: [1, 2]}, {a: {b: 3}}), | ||
| r2 = merge({a: {b: 3}}, {a: [1, 2]}); | ||
| expect(r1).to.eql({a: {b: 3}}); | ||
| expect(r2).to.eql({a: [1, 2]}); | ||
| }); | ||
| it('should not merge arrays', function(){ | ||
| var r1 = merge({a: [1, 2]}, {a: [3]}), | ||
| r2 = merge({a: [3]}, {a: [1, 2]}); | ||
| expect(r1).to.eql({a: [3]}); | ||
| expect(r2).to.eql({a: [1, 2]}); | ||
| }); | ||
| // Nesting | ||
| it('should merge nested objects', function(){ | ||
| var r1 = merge({a: 1}, {a: {b: 2}}), | ||
| r2 = merge({a: {b: 2}}, {a: 1}); | ||
| expect(r1).to.eql({a: {b: 2}}); | ||
| expect(r2).to.eql({a: 1}); | ||
| }); | ||
| it('should deep merge', function(){ | ||
| var r = merge({a: {b: 2}}, {a: {c: 3}}); | ||
| expect(r).to.eql({a: {b: 2, c: 3}}); | ||
| }); | ||
| it('should deep merge with empty objects', function(){ | ||
| var r1 = merge({a: {b: 2}}, {a: {}}), | ||
| r2 = merge({a: {}}, {a: {b: 2}}); | ||
| expect(r1).to.eql({a: {b: 2}}); | ||
| expect(r2).to.eql({a: {b: 2}}); | ||
| }); | ||
| it('should treat empty objects as values', function(){ | ||
| var r1 = merge({a: 0}, {a: {}}), | ||
| r2 = merge({a: {}}, {a: 0}); | ||
| expect(r1).to.eql({a: {}}); | ||
| expect(r2).to.eql({a: 0}); | ||
| }); | ||
| it('should merge deeper', function(){ | ||
| var o1 = {c: {c1: null, c2: false, c3: {cc1: 'o1cc1', cc2: 'o1cc2' }}}, | ||
| o2 = {c: {c1: false, c2: null, c3: {cc1: 'o2cc1', cc3: 'o2cc3' }}}, | ||
| e = {c: {c1: false, c2: null, c3: {cc1: 'o2cc1', cc2: 'o1cc2', cc3: 'o2cc3'}}}; | ||
| var r = merge(o1, o2); | ||
| expect(r).to.eql(e); | ||
| }); | ||
| it('should merge deeper II', function(){ | ||
| var o1 = {c: {c1: null, c2: false, c3: {cc1: 'o1cc1', cc2: 'o1cc2' }}}, | ||
| o2 = {c: {c1: false, c2: null, c3: {cc1: 'o2cc1', cc3: 'o2cc3' }}}, | ||
| e = {c: {c1: null, c2: false, c3: {cc1: 'o1cc1', cc3: 'o2cc3', cc2: 'o1cc2'}}}; | ||
| var r = merge(o2, o1); | ||
| expect(r).to.eql(e); | ||
| }); | ||
| }); |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
426
0.24%394757
-1.15%3
50%43
-4.44%9640
-1.54%+ Added
+ Added