deku 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +5 -0
- data/LICENSE +25 -0
- data/README.md +28 -0
- data/Rakefile +1 -0
- data/deku.gemspec +23 -0
- data/deps/node_modules/deku.js +2 -0
- data/deps/node_modules/deku/.editorconfig +16 -0
- data/deps/node_modules/deku/.zuul.yml +15 -0
- data/deps/node_modules/deku/History.md +290 -0
- data/deps/node_modules/deku/LICENSE.md +7 -0
- data/deps/node_modules/deku/Makefile +91 -0
- data/deps/node_modules/deku/README.md +293 -0
- data/deps/node_modules/deku/index.js +4072 -0
- data/deps/node_modules/deku/lib/application.js +85 -0
- data/deps/node_modules/deku/lib/index.js +28 -0
- data/deps/node_modules/deku/lib/render.js +1300 -0
- data/deps/node_modules/deku/lib/stringify.js +105 -0
- data/deps/node_modules/deku/lib/svg.js +107 -0
- data/deps/node_modules/deku/lib/utils.js +18 -0
- data/deps/node_modules/deku/lib/virtual.js +247 -0
- data/deps/node_modules/deku/node_modules/array-flatten/LICENSE +21 -0
- data/deps/node_modules/deku/node_modules/array-flatten/README.md +43 -0
- data/deps/node_modules/deku/node_modules/array-flatten/array-flatten.js +57 -0
- data/deps/node_modules/deku/node_modules/array-flatten/package.json +62 -0
- data/deps/node_modules/deku/node_modules/component-emitter/History.md +63 -0
- data/deps/node_modules/deku/node_modules/component-emitter/LICENSE +24 -0
- data/deps/node_modules/deku/node_modules/component-emitter/Readme.md +74 -0
- data/deps/node_modules/deku/node_modules/component-emitter/index.js +161 -0
- data/deps/node_modules/deku/node_modules/component-emitter/package.json +174 -0
- data/deps/node_modules/deku/node_modules/component-raf/.npmignore +2 -0
- data/deps/node_modules/deku/node_modules/component-raf/History.md +26 -0
- data/deps/node_modules/deku/node_modules/component-raf/Makefile +11 -0
- data/deps/node_modules/deku/node_modules/component-raf/Readme.md +46 -0
- data/deps/node_modules/deku/node_modules/component-raf/component.json +16 -0
- data/deps/node_modules/deku/node_modules/component-raf/example.html +43 -0
- data/deps/node_modules/deku/node_modules/component-raf/index.js +34 -0
- data/deps/node_modules/deku/node_modules/component-raf/package.json +164 -0
- data/deps/node_modules/deku/node_modules/component-type/.npmignore +3 -0
- data/deps/node_modules/deku/node_modules/component-type/Makefile +14 -0
- data/deps/node_modules/deku/node_modules/component-type/Readme.md +37 -0
- data/deps/node_modules/deku/node_modules/component-type/component.json +13 -0
- data/deps/node_modules/deku/node_modules/component-type/index.js +34 -0
- data/deps/node_modules/deku/node_modules/component-type/package.json +120 -0
- data/deps/node_modules/deku/node_modules/component-type/test/index.html +17 -0
- data/deps/node_modules/deku/node_modules/component-type/test/mocha.css +231 -0
- data/deps/node_modules/deku/node_modules/component-type/test/mocha.js +5340 -0
- data/deps/node_modules/deku/node_modules/component-type/test/tests.js +72 -0
- data/deps/node_modules/deku/node_modules/dom-pool/.npmignore +1 -0
- data/deps/node_modules/deku/node_modules/dom-pool/Pool.js +52 -0
- data/deps/node_modules/deku/node_modules/dom-pool/README.md +42 -0
- data/deps/node_modules/deku/node_modules/dom-pool/authors.txt +4 -0
- data/deps/node_modules/deku/node_modules/dom-pool/bower.json +26 -0
- data/deps/node_modules/deku/node_modules/dom-pool/package.json +46 -0
- data/deps/node_modules/deku/node_modules/dom-pool/tests.html +16 -0
- data/deps/node_modules/deku/node_modules/dom-pool/tests.js +102 -0
- data/deps/node_modules/deku/node_modules/dom-walk/.npmignore +3 -0
- data/deps/node_modules/deku/node_modules/dom-walk/LICENCE +19 -0
- data/deps/node_modules/deku/node_modules/dom-walk/Makefile +2 -0
- data/deps/node_modules/deku/node_modules/dom-walk/README.md +23 -0
- data/deps/node_modules/deku/node_modules/dom-walk/example/index.js +5 -0
- data/deps/node_modules/deku/node_modules/dom-walk/example/static/bundle.js +211 -0
- data/deps/node_modules/deku/node_modules/dom-walk/example/static/index.html +16 -0
- data/deps/node_modules/deku/node_modules/dom-walk/index.js +24 -0
- data/deps/node_modules/deku/node_modules/dom-walk/package.json +57 -0
- data/deps/node_modules/deku/node_modules/fast.js/.jshintignore +7 -0
- data/deps/node_modules/deku/node_modules/fast.js/.jshintrc +80 -0
- data/deps/node_modules/deku/node_modules/fast.js/.npmignore +6 -0
- data/deps/node_modules/deku/node_modules/fast.js/.travis.yml +3 -0
- data/deps/node_modules/deku/node_modules/fast.js/LICENSE.md +21 -0
- data/deps/node_modules/deku/node_modules/fast.js/README.md +552 -0
- data/deps/node_modules/deku/node_modules/fast.js/array/clone.js +21 -0
- data/deps/node_modules/deku/node_modules/fast.js/array/concat.js +32 -0
- data/deps/node_modules/deku/node_modules/fast.js/array/every.js +25 -0
- data/deps/node_modules/deku/node_modules/fast.js/array/fill.js +29 -0
- data/deps/node_modules/deku/node_modules/fast.js/array/filter.js +26 -0
- data/deps/node_modules/deku/node_modules/fast.js/array/forEach.js +21 -0
- data/deps/node_modules/deku/node_modules/fast.js/array/index.js +15 -0
- data/deps/node_modules/deku/node_modules/fast.js/array/indexOf.js +33 -0
- data/deps/node_modules/deku/node_modules/fast.js/array/lastIndexOf.js +29 -0
- data/deps/node_modules/deku/node_modules/fast.js/array/map.js +24 -0
- data/deps/node_modules/deku/node_modules/fast.js/array/pluck.js +24 -0
- data/deps/node_modules/deku/node_modules/fast.js/array/reduce.js +35 -0
- data/deps/node_modules/deku/node_modules/fast.js/array/reduceRight.js +35 -0
- data/deps/node_modules/deku/node_modules/fast.js/array/some.js +25 -0
- data/deps/node_modules/deku/node_modules/fast.js/bower.json +28 -0
- data/deps/node_modules/deku/node_modules/fast.js/clone.js +27 -0
- data/deps/node_modules/deku/node_modules/fast.js/dist/bench.html +15 -0
- data/deps/node_modules/deku/node_modules/fast.js/dist/bench.js +19900 -0
- data/deps/node_modules/deku/node_modules/fast.js/dist/fast.js +1450 -0
- data/deps/node_modules/deku/node_modules/fast.js/dist/fast.min.js +1 -0
- data/deps/node_modules/deku/node_modules/fast.js/filter.js +23 -0
- data/deps/node_modules/deku/node_modules/fast.js/forEach.js +22 -0
- data/deps/node_modules/deku/node_modules/fast.js/function/apply.js +19 -0
- data/deps/node_modules/deku/node_modules/fast.js/function/applyNoContext.js +29 -0
- data/deps/node_modules/deku/node_modules/fast.js/function/applyWithContext.js +29 -0
- data/deps/node_modules/deku/node_modules/fast.js/function/bind.js +71 -0
- data/deps/node_modules/deku/node_modules/fast.js/function/bindInternal3.js +11 -0
- data/deps/node_modules/deku/node_modules/fast.js/function/bindInternal4.js +11 -0
- data/deps/node_modules/deku/node_modules/fast.js/function/index.js +7 -0
- data/deps/node_modules/deku/node_modules/fast.js/function/partial.js +42 -0
- data/deps/node_modules/deku/node_modules/fast.js/function/partialConstructor.js +45 -0
- data/deps/node_modules/deku/node_modules/fast.js/function/try.js +35 -0
- data/deps/node_modules/deku/node_modules/fast.js/index.js +241 -0
- data/deps/node_modules/deku/node_modules/fast.js/map.js +23 -0
- data/deps/node_modules/deku/node_modules/fast.js/object/assign.js +34 -0
- data/deps/node_modules/deku/node_modules/fast.js/object/clone.js +25 -0
- data/deps/node_modules/deku/node_modules/fast.js/object/filter.js +28 -0
- data/deps/node_modules/deku/node_modules/fast.js/object/forEach.js +23 -0
- data/deps/node_modules/deku/node_modules/fast.js/object/index.js +11 -0
- data/deps/node_modules/deku/node_modules/fast.js/object/keys.js +17 -0
- data/deps/node_modules/deku/node_modules/fast.js/object/map.js +26 -0
- data/deps/node_modules/deku/node_modules/fast.js/object/reduce.js +37 -0
- data/deps/node_modules/deku/node_modules/fast.js/object/reduceRight.js +37 -0
- data/deps/node_modules/deku/node_modules/fast.js/object/values.js +20 -0
- data/deps/node_modules/deku/node_modules/fast.js/package.json +73 -0
- data/deps/node_modules/deku/node_modules/fast.js/reduce.js +24 -0
- data/deps/node_modules/deku/node_modules/fast.js/reduceRight.js +24 -0
- data/deps/node_modules/deku/node_modules/fast.js/string/index.js +3 -0
- data/deps/node_modules/deku/node_modules/fast.js/string/intern.js +56 -0
- data/deps/node_modules/deku/node_modules/get-uid/README.md +44 -0
- data/deps/node_modules/deku/node_modules/get-uid/index.js +6 -0
- data/deps/node_modules/deku/node_modules/get-uid/package.json +56 -0
- data/deps/node_modules/deku/node_modules/is-dom/HISTORY.md +2 -0
- data/deps/node_modules/deku/node_modules/is-dom/LICENSE +21 -0
- data/deps/node_modules/deku/node_modules/is-dom/README.md +32 -0
- data/deps/node_modules/deku/node_modules/is-dom/index.js +15 -0
- data/deps/node_modules/deku/node_modules/is-dom/package.json +62 -0
- data/deps/node_modules/deku/node_modules/object-path/.npmignore +7 -0
- data/deps/node_modules/deku/node_modules/object-path/.travis.yml +6 -0
- data/deps/node_modules/deku/node_modules/object-path/LICENSE +21 -0
- data/deps/node_modules/deku/node_modules/object-path/README.md +96 -0
- data/deps/node_modules/deku/node_modules/object-path/bower.json +17 -0
- data/deps/node_modules/deku/node_modules/object-path/component.json +22 -0
- data/deps/node_modules/deku/node_modules/object-path/index.js +269 -0
- data/deps/node_modules/deku/node_modules/object-path/package.json +89 -0
- data/deps/node_modules/deku/node_modules/object-path/test.js +510 -0
- data/deps/node_modules/deku/node_modules/per-frame/.npmignore +68 -0
- data/deps/node_modules/deku/node_modules/per-frame/History.md +32 -0
- data/deps/node_modules/deku/node_modules/per-frame/README.md +44 -0
- data/deps/node_modules/deku/node_modules/per-frame/component.json +13 -0
- data/deps/node_modules/deku/node_modules/per-frame/index.js +37 -0
- data/deps/node_modules/deku/node_modules/per-frame/package.json +143 -0
- data/deps/node_modules/deku/node_modules/per-frame/test/test.js +94 -0
- data/deps/node_modules/deku/node_modules/sliced/.npmignore +2 -0
- data/deps/node_modules/deku/node_modules/sliced/.travis.yml +4 -0
- data/deps/node_modules/deku/node_modules/sliced/History.md +30 -0
- data/deps/node_modules/deku/node_modules/sliced/LICENSE +22 -0
- data/deps/node_modules/deku/node_modules/sliced/Makefile +5 -0
- data/deps/node_modules/deku/node_modules/sliced/README.md +62 -0
- data/deps/node_modules/deku/node_modules/sliced/bench.js +95 -0
- data/deps/node_modules/deku/node_modules/sliced/component.json +14 -0
- data/deps/node_modules/deku/node_modules/sliced/index.js +1 -0
- data/deps/node_modules/deku/node_modules/sliced/lib/sliced.js +33 -0
- data/deps/node_modules/deku/node_modules/sliced/package.json +52 -0
- data/deps/node_modules/deku/node_modules/sliced/test/index.js +80 -0
- data/deps/node_modules/deku/package.json +67 -0
- data/lib/deku.rb +11 -0
- data/lib/deku/application.rb +16 -0
- data/lib/deku/component.rb +36 -0
- data/lib/deku/context.rb +38 -0
- data/lib/deku/element_node.rb +17 -0
- data/lib/deku/version.rb +4 -0
- metadata +278 -0
@@ -0,0 +1,89 @@
|
|
1
|
+
{
|
2
|
+
"name": "object-path",
|
3
|
+
"description": "Access deep properties using a path",
|
4
|
+
"version": "0.8.1",
|
5
|
+
"author": {
|
6
|
+
"name": "Mario Casciaro"
|
7
|
+
},
|
8
|
+
"homepage": "https://github.com/mariocasciaro/object-path",
|
9
|
+
"repository": {
|
10
|
+
"type": "git",
|
11
|
+
"url": "git://github.com/mariocasciaro/object-path.git"
|
12
|
+
},
|
13
|
+
"engines": {
|
14
|
+
"node": ">=0.8.0"
|
15
|
+
},
|
16
|
+
"devDependencies": {
|
17
|
+
"mocha": "~1.20.1",
|
18
|
+
"chai": "~1.9.1",
|
19
|
+
"mocha-lcov-reporter": "~0.0.1",
|
20
|
+
"coveralls": "~2.11.1",
|
21
|
+
"istanbul": "~0.3.0"
|
22
|
+
},
|
23
|
+
"scripts": {
|
24
|
+
"test": "node ./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha test.js --report html -- -R spec"
|
25
|
+
},
|
26
|
+
"testling": {
|
27
|
+
"browsers": {
|
28
|
+
"ie": [
|
29
|
+
8,
|
30
|
+
9
|
31
|
+
],
|
32
|
+
"firefox": [
|
33
|
+
10,
|
34
|
+
24
|
35
|
+
],
|
36
|
+
"chrome": [
|
37
|
+
30,
|
38
|
+
22
|
39
|
+
],
|
40
|
+
"safari": [
|
41
|
+
5,
|
42
|
+
6
|
43
|
+
],
|
44
|
+
"opera": [
|
45
|
+
15
|
46
|
+
],
|
47
|
+
"iphone": [
|
48
|
+
6
|
49
|
+
],
|
50
|
+
"android-browser": [
|
51
|
+
4.2
|
52
|
+
]
|
53
|
+
},
|
54
|
+
"harness": "mocha",
|
55
|
+
"files": "test.js"
|
56
|
+
},
|
57
|
+
"keywords": [
|
58
|
+
"deep",
|
59
|
+
"path",
|
60
|
+
"access",
|
61
|
+
"bean"
|
62
|
+
],
|
63
|
+
"license": "MIT",
|
64
|
+
"gitHead": "57e379d14a32cd04c597f63182e7d54b695f9415",
|
65
|
+
"bugs": {
|
66
|
+
"url": "https://github.com/mariocasciaro/object-path/issues"
|
67
|
+
},
|
68
|
+
"_id": "object-path@0.8.1",
|
69
|
+
"_shasum": "40691756e154372e55eef0f15f005e317e855c8c",
|
70
|
+
"_from": "object-path@>=0.8.1 <0.9.0",
|
71
|
+
"_npmVersion": "1.4.28",
|
72
|
+
"_npmUser": {
|
73
|
+
"name": "mariocasciaro",
|
74
|
+
"email": "contact@mariocasciaro.me"
|
75
|
+
},
|
76
|
+
"maintainers": [
|
77
|
+
{
|
78
|
+
"name": "mariocasciaro",
|
79
|
+
"email": "mariocasciaro@gmail.com"
|
80
|
+
}
|
81
|
+
],
|
82
|
+
"dist": {
|
83
|
+
"shasum": "40691756e154372e55eef0f15f005e317e855c8c",
|
84
|
+
"tarball": "http://registry.npmjs.org/object-path/-/object-path-0.8.1.tgz"
|
85
|
+
},
|
86
|
+
"directories": {},
|
87
|
+
"_resolved": "https://registry.npmjs.org/object-path/-/object-path-0.8.1.tgz",
|
88
|
+
"readme": "ERROR: No README data found!"
|
89
|
+
}
|
@@ -0,0 +1,510 @@
|
|
1
|
+
var expect = require('chai').expect,
|
2
|
+
objectPath = require('./index.js');
|
3
|
+
|
4
|
+
|
5
|
+
function getTestObj() {
|
6
|
+
return {
|
7
|
+
a: 'b',
|
8
|
+
b: {
|
9
|
+
c: [],
|
10
|
+
d: ['a', 'b'],
|
11
|
+
e: [{},{f: 'g'}],
|
12
|
+
f: 'i'
|
13
|
+
}
|
14
|
+
};
|
15
|
+
}
|
16
|
+
|
17
|
+
describe('get', function() {
|
18
|
+
it('should return the value under shallow object', function() {
|
19
|
+
var obj = getTestObj();
|
20
|
+
expect(objectPath.get(obj, 'a')).to.be.equal('b');
|
21
|
+
expect(objectPath.get(obj, ['a'])).to.be.equal('b');
|
22
|
+
});
|
23
|
+
|
24
|
+
it('should work with number path', function() {
|
25
|
+
var obj = getTestObj();
|
26
|
+
expect(objectPath.get(obj.b.d, 0)).to.be.equal('a');
|
27
|
+
expect(objectPath.get(obj.b, 0)).to.be.equal(void 0);
|
28
|
+
});
|
29
|
+
|
30
|
+
it('should return the value under deep object', function() {
|
31
|
+
var obj = getTestObj();
|
32
|
+
expect(objectPath.get(obj, 'b.f')).to.be.equal('i');
|
33
|
+
expect(objectPath.get(obj, ['b','f'])).to.be.equal('i');
|
34
|
+
});
|
35
|
+
|
36
|
+
it('should return the value under array', function() {
|
37
|
+
var obj = getTestObj();
|
38
|
+
expect(objectPath.get(obj, 'b.d.0')).to.be.equal('a');
|
39
|
+
expect(objectPath.get(obj, ['b','d',0])).to.be.equal('a');
|
40
|
+
});
|
41
|
+
|
42
|
+
it('should return the value under array deep', function() {
|
43
|
+
var obj = getTestObj();
|
44
|
+
expect(objectPath.get(obj, 'b.e.1.f')).to.be.equal('g');
|
45
|
+
expect(objectPath.get(obj, ['b','e',1,'f'])).to.be.equal('g');
|
46
|
+
});
|
47
|
+
|
48
|
+
it('should return undefined for missing values under object', function() {
|
49
|
+
var obj = getTestObj();
|
50
|
+
expect(objectPath.get(obj, 'a.b')).to.not.exist;
|
51
|
+
expect(objectPath.get(obj, ['a','b'])).to.not.exist;
|
52
|
+
});
|
53
|
+
|
54
|
+
it('should return undefined for missing values under array', function() {
|
55
|
+
var obj = getTestObj();
|
56
|
+
expect(objectPath.get(obj, 'b.d.5')).to.not.exist;
|
57
|
+
expect(objectPath.get(obj, ['b','d','5'])).to.not.exist;
|
58
|
+
});
|
59
|
+
|
60
|
+
it('should return the value under integer-like key', function() {
|
61
|
+
var obj = { '1a': 'foo' };
|
62
|
+
expect(objectPath.get(obj, '1a')).to.be.equal('foo');
|
63
|
+
expect(objectPath.get(obj, ['1a'])).to.be.equal('foo');
|
64
|
+
});
|
65
|
+
|
66
|
+
it('should return the default value when the key doesnt exist', function() {
|
67
|
+
var obj = { '1a': 'foo' };
|
68
|
+
expect(objectPath.get(obj, '1b', null)).to.be.equal(null);
|
69
|
+
expect(objectPath.get(obj, ['1b'], null)).to.be.equal(null);
|
70
|
+
});
|
71
|
+
|
72
|
+
it('should return the default value when path is empty', function() {
|
73
|
+
var obj = { '1a': 'foo' };
|
74
|
+
expect(objectPath.get(obj, '', null)).to.be.deep.equal({ '1a': 'foo' });
|
75
|
+
expect(objectPath.get(obj, [])).to.be.deep.equal({ '1a': 'foo' });
|
76
|
+
expect(objectPath.get({ }, ['1'])).to.be.equal(undefined);
|
77
|
+
});
|
78
|
+
|
79
|
+
it('should skip non own properties with isEmpty', function(){
|
80
|
+
var Base = function(enabled){ };
|
81
|
+
Base.prototype = {
|
82
|
+
one: {
|
83
|
+
two: true
|
84
|
+
}
|
85
|
+
};
|
86
|
+
var Extended = function(){
|
87
|
+
Base.call(this, true);
|
88
|
+
};
|
89
|
+
Extended.prototype = Object.create(Base.prototype);
|
90
|
+
|
91
|
+
var extended = new Extended();
|
92
|
+
|
93
|
+
expect(objectPath.get(extended, ['one','two'])).to.be.equal(undefined);
|
94
|
+
extended.enabled = true;
|
95
|
+
|
96
|
+
expect(objectPath.get(extended, 'enabled')).to.be.equal(true);
|
97
|
+
});
|
98
|
+
});
|
99
|
+
|
100
|
+
|
101
|
+
describe('set', function() {
|
102
|
+
it('should set value under shallow object', function() {
|
103
|
+
var obj = getTestObj();
|
104
|
+
objectPath.set(obj, 'c', {m: 'o'});
|
105
|
+
expect(obj).to.have.deep.property('c.m', 'o');
|
106
|
+
obj = getTestObj();
|
107
|
+
objectPath.set(obj, ['c'], {m: 'o'});
|
108
|
+
expect(obj).to.have.deep.property('c.m', 'o');
|
109
|
+
});
|
110
|
+
|
111
|
+
it('should set value using number path', function() {
|
112
|
+
var obj = getTestObj();
|
113
|
+
objectPath.set(obj.b.d, 0, 'o');
|
114
|
+
expect(obj).to.have.deep.property('b.d.0', 'o');
|
115
|
+
});
|
116
|
+
|
117
|
+
it('should set value under deep object', function() {
|
118
|
+
var obj = getTestObj();
|
119
|
+
objectPath.set(obj, 'b.c', 'o');
|
120
|
+
expect(obj).to.have.deep.property('b.c', 'o');
|
121
|
+
obj = getTestObj();
|
122
|
+
objectPath.set(obj, ['b','c'], 'o');
|
123
|
+
expect(obj).to.have.deep.property('b.c', 'o');
|
124
|
+
});
|
125
|
+
|
126
|
+
it('should set value under array', function() {
|
127
|
+
var obj = getTestObj();
|
128
|
+
objectPath.set(obj, 'b.e.1.g', 'f');
|
129
|
+
expect(obj).to.have.deep.property('b.e.1.g', 'f');
|
130
|
+
obj = getTestObj();
|
131
|
+
objectPath.set(obj, ['b','e',1,'g'], 'f');
|
132
|
+
expect(obj).to.have.deep.property('b.e.1.g', 'f');
|
133
|
+
});
|
134
|
+
|
135
|
+
it('should create intermediate objects', function() {
|
136
|
+
var obj = getTestObj();
|
137
|
+
objectPath.set(obj, 'c.d.e.f', 'l');
|
138
|
+
expect(obj).to.have.deep.property('c.d.e.f', 'l');
|
139
|
+
obj = getTestObj();
|
140
|
+
objectPath.set(obj, ['c','d','e','f'], 'l');
|
141
|
+
expect(obj).to.have.deep.property('c.d.e.f', 'l');
|
142
|
+
});
|
143
|
+
|
144
|
+
it('should create intermediate arrays', function() {
|
145
|
+
var obj = getTestObj();
|
146
|
+
objectPath.set(obj, 'c.0.1.m', 'l');
|
147
|
+
expect(obj.c).to.be.an('array');
|
148
|
+
expect(obj.c[0]).to.be.an('array');
|
149
|
+
expect(obj).to.have.deep.property('c.0.1.m', 'l');
|
150
|
+
obj = getTestObj();
|
151
|
+
objectPath.set(obj, ['c','0', 1,'m'], 'l');
|
152
|
+
expect(obj.c).to.be.an('object');
|
153
|
+
expect(obj.c[0]).to.be.an('array');
|
154
|
+
expect(obj).to.have.deep.property('c.0.1.m', 'l');
|
155
|
+
});
|
156
|
+
|
157
|
+
it('should set value under integer-like key', function() {
|
158
|
+
var obj = getTestObj();
|
159
|
+
objectPath.set(obj, '1a', 'foo');
|
160
|
+
expect(obj).to.have.deep.property('1a', 'foo');
|
161
|
+
obj = getTestObj();
|
162
|
+
objectPath.set(obj, ['1a'], 'foo');
|
163
|
+
expect(obj).to.have.deep.property('1a', 'foo');
|
164
|
+
});
|
165
|
+
|
166
|
+
it('should set value under empty array', function() {
|
167
|
+
var obj = [];
|
168
|
+
objectPath.set(obj, [0], 'foo');
|
169
|
+
expect(obj[0]).to.be.equal('foo');
|
170
|
+
obj = [];
|
171
|
+
objectPath.set(obj, '0', 'foo');
|
172
|
+
expect(obj[0]).to.be.equal('foo');
|
173
|
+
});
|
174
|
+
});
|
175
|
+
|
176
|
+
|
177
|
+
describe('push', function() {
|
178
|
+
it('should push value to existing array', function() {
|
179
|
+
var obj = getTestObj();
|
180
|
+
objectPath.push(obj, 'b.c', 'l');
|
181
|
+
expect(obj).to.have.deep.property('b.c.0', 'l');
|
182
|
+
obj = getTestObj();
|
183
|
+
objectPath.push(obj, ['b','c'], 'l');
|
184
|
+
expect(obj).to.have.deep.property('b.c.0', 'l');
|
185
|
+
});
|
186
|
+
|
187
|
+
it('should push value to new array', function() {
|
188
|
+
var obj = getTestObj();
|
189
|
+
objectPath.push(obj, 'b.h', 'l');
|
190
|
+
expect(obj).to.have.deep.property('b.h.0', 'l');
|
191
|
+
obj = getTestObj();
|
192
|
+
objectPath.push(obj, ['b','h'], 'l');
|
193
|
+
expect(obj).to.have.deep.property('b.h.0', 'l');
|
194
|
+
});
|
195
|
+
|
196
|
+
it('should push value to existing array using number path', function() {
|
197
|
+
var obj = getTestObj();
|
198
|
+
objectPath.push(obj.b.e, 0, 'l');
|
199
|
+
expect(obj).to.have.deep.property('b.e.0.0', 'l');
|
200
|
+
});
|
201
|
+
|
202
|
+
});
|
203
|
+
|
204
|
+
|
205
|
+
describe('ensureExists', function() {
|
206
|
+
it('should create the path if it does not exists', function() {
|
207
|
+
var obj = getTestObj();
|
208
|
+
var oldVal = objectPath.ensureExists(obj, 'b.g.1.l', 'test');
|
209
|
+
expect(oldVal).to.not.exist;
|
210
|
+
expect(obj).to.have.deep.property('b.g.1.l', 'test');
|
211
|
+
oldVal = objectPath.ensureExists(obj, 'b.g.1.l', 'test1');
|
212
|
+
expect(oldVal).to.be.equal('test');
|
213
|
+
expect(obj).to.have.deep.property('b.g.1.l', 'test');
|
214
|
+
});
|
215
|
+
|
216
|
+
|
217
|
+
it('should return the object if path is empty', function() {
|
218
|
+
var obj = getTestObj();
|
219
|
+
expect(objectPath.ensureExists(obj, [], 'test')).to.have.property('a', 'b');
|
220
|
+
});
|
221
|
+
|
222
|
+
it('Issue #26', function() {
|
223
|
+
var any = {};
|
224
|
+
objectPath.ensureExists(any, ['1','1'], {});
|
225
|
+
expect(any).to.be.an('object');
|
226
|
+
expect(any[1]).to.be.an('object');
|
227
|
+
expect(any[1][1]).to.be.an('object');
|
228
|
+
});
|
229
|
+
});
|
230
|
+
|
231
|
+
describe('coalesce', function(){
|
232
|
+
it('should return the first non-undefined value', function(){
|
233
|
+
var obj = {
|
234
|
+
should: {have: 'prop'}
|
235
|
+
};
|
236
|
+
|
237
|
+
expect(objectPath.coalesce(obj, [
|
238
|
+
'doesnt.exist',
|
239
|
+
['might','not','exist'],
|
240
|
+
'should.have'
|
241
|
+
])).to.equal('prop');
|
242
|
+
});
|
243
|
+
|
244
|
+
it('should work with falsy values (null, 0, \'\', false)', function(){
|
245
|
+
var obj = {
|
246
|
+
is: {
|
247
|
+
false: false,
|
248
|
+
null: null,
|
249
|
+
empty: '',
|
250
|
+
zero: 0
|
251
|
+
}
|
252
|
+
};
|
253
|
+
|
254
|
+
expect(objectPath.coalesce(obj, [
|
255
|
+
'doesnt.exist',
|
256
|
+
'is.zero'
|
257
|
+
])).to.equal(0);
|
258
|
+
|
259
|
+
expect(objectPath.coalesce(obj, [
|
260
|
+
'doesnt.exist',
|
261
|
+
'is.false'
|
262
|
+
])).to.equal(false);
|
263
|
+
|
264
|
+
expect(objectPath.coalesce(obj, [
|
265
|
+
'doesnt.exist',
|
266
|
+
'is.null'
|
267
|
+
])).to.equal(null);
|
268
|
+
|
269
|
+
expect(objectPath.coalesce(obj, [
|
270
|
+
'doesnt.exist',
|
271
|
+
'is.empty'
|
272
|
+
])).to.equal('');
|
273
|
+
});
|
274
|
+
|
275
|
+
it('returns defaultValue if no paths found', function(){
|
276
|
+
var obj = {
|
277
|
+
doesnt: 'matter'
|
278
|
+
};
|
279
|
+
|
280
|
+
expect(objectPath.coalesce(obj, ['some.inexistant','path',['on','object']], 'false')).to.equal('false');
|
281
|
+
});
|
282
|
+
});
|
283
|
+
|
284
|
+
describe('empty', function(){
|
285
|
+
it('should ignore invalid arguments safely', function(){
|
286
|
+
var obj = {};
|
287
|
+
expect(objectPath.empty()).to.equal(void 0);
|
288
|
+
expect(objectPath.empty(obj, 'path')).to.equal(void 0);
|
289
|
+
expect(objectPath.empty(obj, '')).to.equal(obj);
|
290
|
+
|
291
|
+
obj.path = true;
|
292
|
+
|
293
|
+
expect(objectPath.empty(obj, 'inexistant')).to.equal(obj);
|
294
|
+
});
|
295
|
+
|
296
|
+
it('should empty each path according to their types', function(){
|
297
|
+
function Instance(){
|
298
|
+
this.notOwn = true;
|
299
|
+
}
|
300
|
+
|
301
|
+
/*istanbul ignore next: not part of code */
|
302
|
+
Instance.prototype.test = function(){};
|
303
|
+
/*istanbul ignore next: not part of code */
|
304
|
+
Instance.prototype.arr = [];
|
305
|
+
|
306
|
+
var
|
307
|
+
obj = {
|
308
|
+
string: 'some string',
|
309
|
+
array: ['some','array',[1,2,3]],
|
310
|
+
number: 21,
|
311
|
+
boolean: true,
|
312
|
+
object: {
|
313
|
+
some:'property',
|
314
|
+
sub: {
|
315
|
+
'property': true
|
316
|
+
}
|
317
|
+
},
|
318
|
+
instance: new Instance()
|
319
|
+
};
|
320
|
+
|
321
|
+
/*istanbul ignore next: not part of code */
|
322
|
+
obj['function'] = function(){};
|
323
|
+
|
324
|
+
objectPath.empty(obj, ['array','2']);
|
325
|
+
expect(obj.array[2]).to.deep.equal([]);
|
326
|
+
|
327
|
+
objectPath.empty(obj, 'object.sub');
|
328
|
+
expect(obj.object.sub).to.deep.equal({});
|
329
|
+
|
330
|
+
objectPath.empty(obj, 'instance.test');
|
331
|
+
expect(obj.instance.test).to.equal(null);
|
332
|
+
expect(Instance.prototype.test).to.be.a('function');
|
333
|
+
|
334
|
+
objectPath.empty(obj, 'string');
|
335
|
+
objectPath.empty(obj, 'number');
|
336
|
+
objectPath.empty(obj, 'boolean');
|
337
|
+
objectPath.empty(obj, 'function');
|
338
|
+
objectPath.empty(obj, 'array');
|
339
|
+
objectPath.empty(obj, 'object');
|
340
|
+
objectPath.empty(obj, 'instance');
|
341
|
+
|
342
|
+
expect(obj.string).to.equal('');
|
343
|
+
expect(obj.array).to.deep.equal([]);
|
344
|
+
expect(obj.number).to.equal(0);
|
345
|
+
expect(obj.boolean).to.equal(false);
|
346
|
+
expect(obj.object).to.deep.equal({});
|
347
|
+
expect(obj.instance.notOwn).to.be.an('undefined');
|
348
|
+
expect(obj.instance.arr).to.be.an('array');
|
349
|
+
expect(obj['function']).to.equal(null);
|
350
|
+
});
|
351
|
+
});
|
352
|
+
|
353
|
+
describe('del', function(){
|
354
|
+
it('should return undefined on empty object', function(){
|
355
|
+
expect(objectPath.del({}, 'a')).to.equal(void 0);
|
356
|
+
});
|
357
|
+
|
358
|
+
it('should work with number path', function(){
|
359
|
+
var obj = getTestObj();
|
360
|
+
objectPath.del(obj.b.d, 1);
|
361
|
+
expect(obj.b.d).to.deep.equal(['a']);
|
362
|
+
});
|
363
|
+
|
364
|
+
it('should delete deep paths', function(){
|
365
|
+
var obj = getTestObj();
|
366
|
+
|
367
|
+
expect(objectPath.del(obj)).to.be.equal(obj);
|
368
|
+
|
369
|
+
objectPath.set(obj, 'b.g.1.0', 'test');
|
370
|
+
objectPath.set(obj, 'b.g.1.1', 'test');
|
371
|
+
objectPath.set(obj, 'b.h.az', 'test');
|
372
|
+
|
373
|
+
expect(obj).to.have.deep.property('b.g.1.0','test');
|
374
|
+
expect(obj).to.have.deep.property('b.g.1.1','test');
|
375
|
+
expect(obj).to.have.deep.property('b.h.az','test');
|
376
|
+
|
377
|
+
objectPath.del(obj, 'b.h.az');
|
378
|
+
expect(obj).to.not.have.deep.property('b.h.az');
|
379
|
+
expect(obj).to.have.deep.property('b.h');
|
380
|
+
|
381
|
+
objectPath.del(obj, 'b.g.1.1');
|
382
|
+
expect(obj).to.not.have.deep.property('b.g.1.1');
|
383
|
+
expect(obj).to.have.deep.property('b.g.1.0','test');
|
384
|
+
|
385
|
+
objectPath.del(obj, ['b','g','1','0']);
|
386
|
+
expect(obj).to.not.have.deep.property('b.g.1.0');
|
387
|
+
expect(obj).to.have.deep.property('b.g.1');
|
388
|
+
|
389
|
+
expect(objectPath.del(obj, ['b'])).to.not.have.deep.property('b.g');
|
390
|
+
expect(obj).to.be.deep.equal({'a':'b'});
|
391
|
+
});
|
392
|
+
|
393
|
+
it('should remove items from existing array', function(){
|
394
|
+
var obj = getTestObj();
|
395
|
+
|
396
|
+
objectPath.del(obj, 'b.d.0');
|
397
|
+
expect(obj.b.d).to.have.length(1);
|
398
|
+
expect(obj.b.d).to.be.deep.equal(['b']);
|
399
|
+
|
400
|
+
objectPath.del(obj, 'b.d.0');
|
401
|
+
expect(obj.b.d).to.have.length(0);
|
402
|
+
expect(obj.b.d).to.be.deep.equal([]);
|
403
|
+
});
|
404
|
+
|
405
|
+
it('should skip undefined paths', function(){
|
406
|
+
var obj = getTestObj();
|
407
|
+
|
408
|
+
expect(objectPath.del(obj, 'do.not.exist')).to.be.equal(obj);
|
409
|
+
expect(objectPath.del(obj, 'a.c')).to.be.equal('b');
|
410
|
+
});
|
411
|
+
});
|
412
|
+
|
413
|
+
describe('insert', function(){
|
414
|
+
it('should insert value into existing array', function(){
|
415
|
+
var obj = getTestObj();
|
416
|
+
|
417
|
+
objectPath.insert(obj, 'b.c', 'asdf');
|
418
|
+
expect(obj).to.have.deep.property('b.c.0', 'asdf');
|
419
|
+
expect(obj).to.not.have.deep.property('b.c.1');
|
420
|
+
});
|
421
|
+
|
422
|
+
it('should create intermediary array', function(){
|
423
|
+
var obj = getTestObj();
|
424
|
+
|
425
|
+
objectPath.insert(obj, 'b.c.0', 'asdf');
|
426
|
+
expect(obj).to.have.deep.property('b.c.0.0', 'asdf');
|
427
|
+
});
|
428
|
+
|
429
|
+
it('should insert in another index', function(){
|
430
|
+
var obj = getTestObj();
|
431
|
+
|
432
|
+
objectPath.insert(obj, 'b.d', 'asdf', 1);
|
433
|
+
expect(obj).to.have.deep.property('b.d.1', 'asdf');
|
434
|
+
expect(obj).to.have.deep.property('b.d.0', 'a');
|
435
|
+
expect(obj).to.have.deep.property('b.d.2', 'b');
|
436
|
+
});
|
437
|
+
|
438
|
+
it('should handle sparse array', function(){
|
439
|
+
var obj = getTestObj();
|
440
|
+
obj.b.d = new Array(4);
|
441
|
+
obj.b.d[0] = 'a';
|
442
|
+
obj.b.d[1] = 'b';
|
443
|
+
|
444
|
+
objectPath.insert(obj, 'b.d', 'asdf', 3);
|
445
|
+
expect(obj.b.d).to.have.members([
|
446
|
+
'a',
|
447
|
+
'b',
|
448
|
+
,
|
449
|
+
,
|
450
|
+
'asdf'
|
451
|
+
]);
|
452
|
+
});
|
453
|
+
});
|
454
|
+
|
455
|
+
describe('has', function () {
|
456
|
+
it('should return false for empty object', function () {
|
457
|
+
expect(objectPath.has({}, 'a')).to.be.false;
|
458
|
+
});
|
459
|
+
|
460
|
+
it('should return false for empty path', function () {
|
461
|
+
var obj = getTestObj();
|
462
|
+
expect(objectPath.has(obj, '')).to.be.false;
|
463
|
+
expect(objectPath.has(obj, [])).to.be.false;
|
464
|
+
expect(objectPath.has(obj, [''])).to.be.false;
|
465
|
+
});
|
466
|
+
|
467
|
+
it('should test under shallow object', function() {
|
468
|
+
var obj = getTestObj();
|
469
|
+
expect(objectPath.has(obj, 'a')).to.be.true;
|
470
|
+
expect(objectPath.has(obj, ['a'])).to.be.true;
|
471
|
+
expect(objectPath.has(obj, 'z')).to.be.false;
|
472
|
+
expect(objectPath.has(obj, ['z'])).to.be.false;
|
473
|
+
});
|
474
|
+
|
475
|
+
it('should work with number path', function() {
|
476
|
+
var obj = getTestObj();
|
477
|
+
expect(objectPath.has(obj.b.d, 0)).to.be.true;
|
478
|
+
expect(objectPath.has(obj.b, 0)).to.be.false;
|
479
|
+
expect(objectPath.has(obj.b.d, 10)).to.be.false;
|
480
|
+
expect(objectPath.has(obj.b, 10)).to.be.false;
|
481
|
+
});
|
482
|
+
|
483
|
+
it('should test under deep object', function() {
|
484
|
+
var obj = getTestObj();
|
485
|
+
expect(objectPath.has(obj, 'b.f')).to.be.true;
|
486
|
+
expect(objectPath.has(obj, ['b','f'])).to.be.true;
|
487
|
+
expect(objectPath.has(obj, 'b.g')).to.be.false;
|
488
|
+
expect(objectPath.has(obj, ['b','g'])).to.be.false;
|
489
|
+
});
|
490
|
+
|
491
|
+
it('should test value under array', function() {
|
492
|
+
var obj = getTestObj();
|
493
|
+
expect(objectPath.has(obj, 'b.d.0')).to.be.true;
|
494
|
+
expect(objectPath.has(obj, ['b','d',0])).to.be.true;
|
495
|
+
});
|
496
|
+
|
497
|
+
it('should test the value under array deep', function() {
|
498
|
+
var obj = getTestObj();
|
499
|
+
expect(objectPath.has(obj, 'b.e.1.f')).to.be.true;
|
500
|
+
expect(objectPath.has(obj, ['b','e',1,'f'])).to.be.true;
|
501
|
+
expect(objectPath.has(obj, 'b.e.1.f.g.h.i')).to.be.false;
|
502
|
+
expect(objectPath.has(obj, ['b','e',1,'f','g','h','i'])).to.be.false;
|
503
|
+
});
|
504
|
+
|
505
|
+
it('should test the value under integer-like key', function() {
|
506
|
+
var obj = { '1a': 'foo' };
|
507
|
+
expect(objectPath.has(obj, '1a')).to.be.true;
|
508
|
+
expect(objectPath.has(obj, ['1a'])).to.be.true;
|
509
|
+
});
|
510
|
+
});
|