dot-object 2.1.3 → 2.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/test/dot.js DELETED
@@ -1,155 +0,0 @@
1
- 'use strict'
2
-
3
- require('should')
4
- var Dot = require('../index')
5
- var pkg = require('./fixtures/package.json')
6
-
7
- describe('dot():', function () {
8
- var obj
9
-
10
- // Dot.useBrackets = false;
11
-
12
- beforeEach(function () {
13
- obj = {
14
- id: 'my-id',
15
- nes: {
16
- ted: {
17
- value: true
18
- }
19
- },
20
- other: {
21
- nested: {
22
- stuff: 5
23
- }
24
- },
25
- nested: {
26
- array: [
27
- {
28
- with: 'object1'
29
- },
30
- {
31
- and: 'object2'
32
- }
33
- ]
34
- },
35
- some: {
36
- array: ['A', 'B']
37
- },
38
- ehrm: 123,
39
- dates: {
40
- first: new Date('Mon Oct 13 2014 00:00:00 GMT+0100 (BST)')
41
- },
42
- arrays: [
43
- [
44
- [
45
- {
46
- all: [
47
- [
48
- {
49
- the: [
50
- 'way',
51
- ['down']
52
- ]
53
- }
54
- ]
55
- ]
56
- }
57
- ]
58
- ]
59
- ]
60
- }
61
- })
62
-
63
- it('Should be able to convert to dotted-key/value pairs', function () {
64
- var expected = {
65
- id: 'my-id',
66
- 'nes.ted.value': true,
67
- 'other.nested.stuff': 5,
68
- 'nested.array[0].with': 'object1',
69
- 'nested.array[1].and': 'object2',
70
- 'some.array[0]': 'A',
71
- 'some.array[1]': 'B',
72
- ehrm: 123,
73
- 'dates.first': new Date('Mon Oct 13 2014 00:00:00 GMT+0100 (BST)'),
74
- 'arrays[0][0][0].all[0][0].the[0]': 'way',
75
- 'arrays[0][0][0].all[0][0].the[1][0]': 'down'
76
- }
77
-
78
- Dot.dot(obj).should.eql(expected)
79
- })
80
-
81
- it('dot() should equal object()', function () {
82
- Dot.object(Dot.dot(pkg)).should.eql(pkg)
83
- })
84
-
85
- it('keepArray prevents arrays from being dotted', function () {
86
- var expected = {
87
- id: 'my-id',
88
- 'nes.ted.value': true,
89
- 'other.nested.stuff': 5,
90
- 'nested.array': [{
91
- with: 'object1'
92
- }, {
93
- and: 'object2'
94
- }],
95
- 'some.array': ['A', 'B'],
96
- ehrm: 123,
97
- 'dates.first': new Date('Mon Oct 13 2014 00:00:00 GMT+0100 (BST)'),
98
- arrays: JSON.parse(JSON.stringify(obj.arrays))
99
- }
100
-
101
- Dot.keepArray = true
102
-
103
- Dot.dot(obj).should.eql(expected)
104
-
105
- Dot.keepArray = false
106
- })
107
-
108
- it('useBrackets wrap indexes with brackets', function () {
109
- var expected = {
110
- id: 'my-id',
111
- 'nes.ted.value': true,
112
- 'other.nested.stuff': 5,
113
- 'nested.array[0].with': 'object1',
114
- 'nested.array[1].and': 'object2',
115
- 'some.array[0]': 'A',
116
- 'some.array[1]': 'B',
117
- ehrm: 123,
118
- 'dates.first': new Date('Mon Oct 13 2014 00:00:00 GMT+0100 (BST)'),
119
- 'arrays[0][0][0].all[0][0].the[0]': 'way',
120
- 'arrays[0][0][0].all[0][0].the[1][0]': 'down'
121
- }
122
-
123
- Dot.dot(obj).should.eql(expected)
124
- })
125
-
126
- it('useBrackets wrap indexes without brackets', function () {
127
- var expected = {
128
- id: 'my-id',
129
- 'nes.ted.value': true,
130
- 'other.nested.stuff': 5,
131
- 'nested.array.0.with': 'object1',
132
- 'nested.array.1.and': 'object2',
133
- 'some.array.0': 'A',
134
- 'some.array.1': 'B',
135
- ehrm: 123,
136
- 'dates.first': new Date('Mon Oct 13 2014 00:00:00 GMT+0100 (BST)'),
137
- 'arrays.0.0.0.all.0.0.the.0': 'way',
138
- 'arrays.0.0.0.all.0.0.the.1.0': 'down'
139
- }
140
-
141
- Dot.useBrackets = false
142
- Dot.dot(obj).should.eql(expected)
143
- Dot.useBrackets = true
144
- })
145
-
146
- it('Always keeps empty arrays', function () {
147
- Dot.dot({ hello: [] }).should.eql({ hello: [] })
148
- Dot.dot({ hello: { world: [] } }).should.eql({ 'hello.world': [] })
149
- })
150
-
151
- it('Always keeps empty objects', function () {
152
- Dot.dot({ hello: {} }).should.eql({ hello: {} })
153
- Dot.dot({ hello: { world: {} } }).should.eql({ 'hello.world': {} })
154
- })
155
- })
@@ -1,46 +0,0 @@
1
- {
2
- "name": "dot-object",
3
- "description": "dot-object makes it possible to transform and read (JSON) objects using dot notation.",
4
- "version": "1.1.0",
5
- "author": {
6
- "name": "Rob Halff",
7
- "email": "rob.halff@gmail.com"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "git://github.com/rhalff/dot-object.git"
12
- },
13
- "bugs": {
14
- "url": "https://github.com/rhalff/dot-object/issues"
15
- },
16
- "main": "index",
17
- "bin": "./bin/dot-object",
18
- "scripts": {
19
- "test": "gulp test"
20
- },
21
- "devDependencies": {
22
- "gulp": "^3.9.0",
23
- "gulp-beautify": "^1.1.2",
24
- "gulp-headerfooter": "^1.0.3",
25
- "gulp-jscs": "^2.0.0",
26
- "gulp-jshint": "^1.11.2",
27
- "gulp-mocha": "^2.1.3",
28
- "gulp-rename": "^1.2.2",
29
- "gulp-uglify": "^1.2.0",
30
- "gulp-util": "^3.0.6",
31
- "jscs": "^2.0.0",
32
- "jscs-jsdoc": "1.1.0",
33
- "mocha": "2.x.x"
34
- },
35
- "keywords": [
36
- "json",
37
- "filter",
38
- "transform",
39
- "dot notation",
40
- "dot"
41
- ],
42
- "dependencies": {
43
- "commander": "^2.8.1",
44
- "glob": "^5.0.14"
45
- }
46
- }
package/test/merge.js DELETED
@@ -1,96 +0,0 @@
1
- 'use strict'
2
-
3
- require('should')
4
- var Dot = require('../index')
5
-
6
- describe('Should be able to merge:', function () {
7
- it('to property', function () {
8
- var link = {
9
- other: {
10
- three: 'Three Things',
11
- four: 'Four Things'
12
- },
13
- things: {
14
- one: 'One Thing',
15
- two: 'Two Things'
16
- }
17
- }
18
-
19
- var expected = {
20
- things: {
21
- one: 'One Thing',
22
- two: 'Two Things',
23
- three: 'Three Things',
24
- four: 'Four Things'
25
- }
26
- }
27
-
28
- Dot.move('other', 'things', link, true)
29
-
30
- link.should.eql(expected)
31
- })
32
-
33
- it('to nested property', function () {
34
- var link = {
35
- other: {
36
- three: 'Three Things',
37
- four: 'Four Things'
38
- },
39
- things: {
40
- one: 'One Thing',
41
- two: 'Two Things',
42
- target: {
43
- im: 'already here'
44
- }
45
- }
46
- }
47
-
48
- var expected = {
49
- things: {
50
- one: 'One Thing',
51
- two: 'Two Things',
52
- target: {
53
- im: 'already here',
54
- three: 'Three Things',
55
- four: 'Four Things'
56
- }
57
- }
58
- }
59
-
60
- Dot.move('other', 'things.target', link, true)
61
-
62
- link.should.eql(expected)
63
- })
64
-
65
- it('array to array', function () {
66
- var link = {
67
- other: [
68
- 'Three Things',
69
- 'Four Things'
70
- ],
71
- things: {
72
- one: 'One Thing',
73
- two: 'Two Things',
74
- target: [
75
- 'already here'
76
- ]
77
- }
78
- }
79
-
80
- var expected = {
81
- things: {
82
- one: 'One Thing',
83
- two: 'Two Things',
84
- target: [
85
- 'already here',
86
- 'Three Things',
87
- 'Four Things'
88
- ]
89
- }
90
- }
91
-
92
- Dot.move('other', 'things.target', link, true)
93
-
94
- link.should.eql(expected)
95
- })
96
- })
package/test/move.js DELETED
@@ -1,70 +0,0 @@
1
- 'use strict'
2
-
3
- require('should')
4
- var Dot = require('../index')
5
-
6
- describe('Move test:', function () {
7
- it('Should be able to move properties', function () {
8
- var link = {
9
- id: '527423a65e380f0000588e47',
10
- source: '526dd5c6b4c4aa8770000001',
11
- target: '527402d6b15d1800008755cf',
12
- out: 'github',
13
- in: 'in'
14
- }
15
-
16
- var expected = {
17
- id: '527423a65e380f0000588e47',
18
- source: { id: '526dd5c6b4c4aa8770000001', port: 'github' },
19
- target: { id: '527402d6b15d1800008755cf', port: 'in' }
20
- }
21
-
22
- Dot.move('source', 'source.id', link)
23
- Dot.move('out', 'source.port', link)
24
- Dot.move('target', 'target.id', link)
25
- Dot.move('in', 'target.port', link)
26
-
27
- link.should.eql(expected)
28
- })
29
-
30
- it('Undefined properties should be ignored', function () {
31
- var link = {
32
- source: '526dd5c6b4c4aa8770000001',
33
- target: '527402d6b15d1800008755cf',
34
- out: 'github',
35
- in: 'in'
36
- }
37
-
38
- var expected = {
39
- source: { id: '526dd5c6b4c4aa8770000001' },
40
- target: { port: 'in' },
41
- out: 'github'
42
- }
43
-
44
- Dot.move('source', 'source.id', link)
45
- Dot.move('out.er.nope', 'source.port', link)
46
- Dot.move('target.bla.di.bla', 'target.id', link)
47
- Dot.move('in', 'target.port', link)
48
-
49
- link.should.eql(expected)
50
- })
51
-
52
- it('Should process modifiers', function () {
53
- var link = {
54
- source: 'one',
55
- target: 'two'
56
- }
57
-
58
- var expected = {
59
- source: { id: 'ONE' },
60
- target: { port: 'TWO' }
61
- }
62
-
63
- function up (val) { return val.toUpperCase() }
64
-
65
- Dot.move('source', 'source.id', link, up)
66
- Dot.move('target', 'target.port', link, up)
67
-
68
- link.should.eql(expected)
69
- })
70
- })
package/test/override.js DELETED
@@ -1,93 +0,0 @@
1
- 'use strict'
2
-
3
- require('should')
4
- var _s = require('underscore.string')
5
- var Dot = require('../index')
6
-
7
- describe('Override test:', function () {
8
- it('Redefinition should _not_ fail if override is true', function () {
9
- var dot = new Dot('.', true)
10
-
11
- var obj = {
12
- some: 'value',
13
- already: 'set'
14
- }
15
-
16
- dot.str('already.new', 'value', obj)
17
-
18
- obj.should.eql({
19
- some: 'value',
20
- already: { new: 'value' }
21
- })
22
- })
23
-
24
- it('Redefinition should _not_ fail if override is true (2)', function () {
25
- var dot = new Dot('.', true)
26
-
27
- var obj = {
28
- some: 'value',
29
- already: 'set'
30
- }
31
-
32
- dot.str('already.new', 'value', obj)
33
- dot.str('some', 'new_value', obj)
34
-
35
- obj.should.eql({
36
- some: 'new_value',
37
- already: { new: 'value' }
38
- })
39
- })
40
-
41
- it('Allow override even when target is non-empty object',
42
- function () {
43
- var obj = {
44
- sample: {
45
- dotted: {
46
- bar: {
47
- baz: 'baz'
48
- }
49
- }
50
- }
51
- }
52
-
53
- Dot.override = true
54
-
55
- Dot.str('sample.dotted.bar', { baz: 'boom' }, obj)
56
-
57
- Dot.override = false
58
-
59
- obj.should.eql({
60
- sample: {
61
- dotted: {
62
- bar: {
63
- baz: 'boom'
64
- }
65
- }
66
- }
67
- })
68
- }
69
- )
70
-
71
- it('should process non dot notation value with modifier if override is true',
72
- function () {
73
- var dot = new Dot('.', true)
74
-
75
- var row = {
76
- title: 'my page',
77
- slug: 'My Page'
78
- }
79
-
80
- var mods = {
81
- title: _s.titleize,
82
- slug: _s.slugify
83
- }
84
-
85
- dot.object(row, mods)
86
-
87
- row.should.eql({
88
- title: 'My Page',
89
- slug: 'my-page'
90
- })
91
- }
92
- )
93
- })
package/test/pick.js DELETED
@@ -1,134 +0,0 @@
1
- 'use strict'
2
-
3
- /* jshint -W030 */
4
-
5
- require('should')
6
- var Dot = require('../index')
7
-
8
- describe('Pick:', function () {
9
- it('Should be able to pick a value', function () {
10
- var obj = {
11
- some: 'value',
12
- already: 'set'
13
- }
14
-
15
- var val = Dot.pick('some', obj)
16
-
17
- val.should.eql('value')
18
- })
19
-
20
- it('Should be able to pick dotted value', function () {
21
- var obj = {
22
- some: {
23
- other: 'value'
24
- }
25
- }
26
-
27
- var val = Dot.pick('some.other', obj)
28
-
29
- val.should.eql('value')
30
- })
31
-
32
- it('Should be able to pick null properties', function () {
33
- var obj = {
34
- some: null
35
- }
36
-
37
- var val = Dot.pick('some', obj)
38
-
39
- ;(val === null).should.equal(true)
40
- })
41
-
42
- it('Should return undefined when picking an non-existing value', function () {
43
- var obj = {
44
- some: null
45
- }
46
-
47
- var val = Dot.pick('other', obj)
48
-
49
- ;(val === undefined).should.equal(true)
50
- })
51
-
52
- it('Should return undefined when picking an non-existing dotted value',
53
- function () {
54
- var obj = {
55
- some: null
56
- }
57
-
58
- var val = Dot.pick('some.other', obj)
59
-
60
- ;(val === undefined).should.equal(true)
61
- }
62
- )
63
-
64
- it("Should check down the object's prototype chain", function () {
65
- var obj = {
66
- some: {
67
- other: 'value'
68
- }
69
- }
70
-
71
- var objIns = Object.create(obj)
72
-
73
- objIns.should.have.property('some')
74
-
75
- var val = Dot.pick('some.other', objIns)
76
- val.should.be.instanceOf(String)
77
- })
78
-
79
- it('Should be able to delete picked value', function () {
80
- var obj = {
81
- some: {
82
- other: 'value',
83
- foo: 'bar'
84
- }
85
- }
86
-
87
- var val = Dot.pick('some.foo', obj, true)
88
-
89
- val.should.eql('bar')
90
- obj.should.eql({
91
- some: {
92
- other: 'value'
93
- }
94
- })
95
- })
96
-
97
- it('Should be able to delete picked array value', function () {
98
- var obj = {
99
- some: {
100
- other: 'value',
101
- arrayItems: ['foo', 'bar', 'baz']
102
- }
103
- }
104
-
105
- var val = Dot.pick('some.arrayItems[1]', obj, true)
106
-
107
- val.should.eql('bar')
108
- obj.should.eql({
109
- some: {
110
- other: 'value',
111
- arrayItems: ['foo', , 'baz'] /* eslint-disable-line no-sparse-arrays */
112
- }
113
- })
114
- })
115
-
116
- it('Should be able to delete picked array value and reindex', function () {
117
- var obj = {
118
- some: {
119
- other: 'value',
120
- arrayItems: ['foo', 'bar', 'baz']
121
- }
122
- }
123
-
124
- var val = Dot.pick('some.arrayItems[1]', obj, true, true)
125
-
126
- val.should.eql('bar')
127
- obj.should.eql({
128
- some: {
129
- other: 'value',
130
- arrayItems: ['foo', 'baz']
131
- }
132
- })
133
- })
134
- })
package/test/remove.js DELETED
@@ -1,80 +0,0 @@
1
- 'use strict'
2
-
3
- require('should')
4
- var Dot = require('../index')
5
-
6
- describe('Remove/del:', function () {
7
- var obj
8
- var expected
9
-
10
- beforeEach(function () {
11
- obj = {
12
- id: 'my-id',
13
- nes: {
14
- ted: {
15
- gone: 'value',
16
- still: 'there'
17
- }
18
- },
19
- ehrm: 123
20
- }
21
-
22
- expected = {
23
- id: 'my-id',
24
- nes: {
25
- ted: {
26
- still: 'there'
27
- }
28
- }
29
- }
30
- })
31
-
32
- it('Should be able to remove() properties', function () {
33
- Dot.remove('ehrm', obj).should.equal(123)
34
- Dot.remove('nes.ted.gone', obj).should.equal('value')
35
- obj.should.eql(expected)
36
- })
37
-
38
- it('Should be able to use del() alias', function () {
39
- Dot.del('ehrm', obj).should.equal(123)
40
- Dot.del('nes.ted.gone', obj).should.equal('value')
41
- obj.should.eql(expected)
42
- })
43
-
44
- it('Should be able to remove() array item and reindex array', function () {
45
- var obj = {
46
- some: {
47
- other: 'value',
48
- arrayItems: ['foo', 'bar', 'baz']
49
- }
50
- }
51
-
52
- var val = Dot.remove('some.arrayItems[1]', obj, true, true)
53
-
54
- val.should.eql('bar')
55
- obj.should.eql({
56
- some: {
57
- other: 'value',
58
- arrayItems: ['foo', 'baz']
59
- }
60
- })
61
- })
62
-
63
- it('Should be handle being told to reindex an object by ignoring reindex rule', function () {
64
- var obj = {
65
- some: {
66
- other: 'value',
67
- arrayItems: ['foo', 'bar', 'baz']
68
- }
69
- }
70
-
71
- var val = Dot.remove('some.other', obj, true, true)
72
-
73
- val.should.eql('value')
74
- obj.should.eql({
75
- some: {
76
- arrayItems: ['foo', 'bar', 'baz']
77
- }
78
- })
79
- })
80
- })