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/CHANGELOG.md +7 -1
- package/README.md +27 -0
- package/dist/dot-object.js +1 -1
- package/dist/dot-object.min.js +1 -1
- package/index.js +1 -1
- package/package.json +13 -10
- package/bower.json +0 -35
- package/gulpfile.js +0 -59
- package/src/dot-object.js +0 -583
- package/src/footer.tpl +0 -13
- package/src/header.tpl +0 -1
- package/test/_process.js +0 -125
- package/test/array_notation.js +0 -176
- package/test/copy.js +0 -86
- package/test/data/array_deep_bug.json +0 -30
- package/test/data/array_deep_bug2.json +0 -19
- package/test/data/empty_array.json +0 -43
- package/test/data/empty_object.json +0 -23
- package/test/data/index.js +0 -8
- package/test/data/object_deep_numeric_keys.json +0 -30
- package/test/data/object_deep_numeric_keys2.json +0 -20
- package/test/dot-json.js +0 -215
- package/test/dot.js +0 -155
- package/test/fixtures/package.json +0 -46
- package/test/merge.js +0 -96
- package/test/move.js +0 -70
- package/test/override.js +0 -93
- package/test/pick.js +0 -134
- package/test/remove.js +0 -80
- package/test/str.js +0 -63
- package/test/test_data.js +0 -42
- package/test/test_transforms.js +0 -28
- package/test/transfer.js +0 -81
- package/test/transforms/contact.json +0 -26
- package/test/transforms/twitter.json +0 -174
- package/test/useArray.js +0 -68
package/test/str.js
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
'use strict'
|
2
|
-
|
3
|
-
require('should')
|
4
|
-
var Dot = require('../index')
|
5
|
-
|
6
|
-
describe('str:', function () {
|
7
|
-
it('can set root property', function () {
|
8
|
-
Dot.str('b', 2, {
|
9
|
-
a: 1
|
10
|
-
}).should.deepEqual({
|
11
|
-
a: 1,
|
12
|
-
b: 2
|
13
|
-
})
|
14
|
-
})
|
15
|
-
|
16
|
-
it('can set nested property', function () {
|
17
|
-
Dot.str('b.a', 2, {
|
18
|
-
a: 1
|
19
|
-
}).should.deepEqual({
|
20
|
-
a: 1,
|
21
|
-
b: {
|
22
|
-
a: 2
|
23
|
-
}
|
24
|
-
})
|
25
|
-
})
|
26
|
-
|
27
|
-
it('can set nested with array notation', function () {
|
28
|
-
var obj = {
|
29
|
-
a: 1
|
30
|
-
}
|
31
|
-
Dot.str('object.fields[0].subfield', 'value', obj)
|
32
|
-
Dot.str('object.fields[1].subfield', 'value1', obj)
|
33
|
-
|
34
|
-
obj.should.deepEqual({
|
35
|
-
a: 1,
|
36
|
-
object: {
|
37
|
-
fields: [
|
38
|
-
{
|
39
|
-
subfield: 'value'
|
40
|
-
},
|
41
|
-
{
|
42
|
-
subfield: 'value1'
|
43
|
-
}
|
44
|
-
]
|
45
|
-
}
|
46
|
-
})
|
47
|
-
})
|
48
|
-
|
49
|
-
it('can set root level property regardless whether override is set', function () {
|
50
|
-
Dot.str('a', 'b', {
|
51
|
-
a: 1
|
52
|
-
}).should.deepEqual({
|
53
|
-
a: 'b'
|
54
|
-
})
|
55
|
-
})
|
56
|
-
|
57
|
-
it('cannot set __proto__ property', function () {
|
58
|
-
(() => Dot.str('__proto__.toString', 'hi', {})).should.throw(
|
59
|
-
/Refusing to update/
|
60
|
-
);
|
61
|
-
({}.toString().should.deepEqual('[object Object]'))
|
62
|
-
})
|
63
|
-
})
|
package/test/test_data.js
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
'use strict'
|
2
|
-
|
3
|
-
require('should')
|
4
|
-
var Dot = require('../index')
|
5
|
-
|
6
|
-
var testData = require('./data')
|
7
|
-
|
8
|
-
function singleTest (dot, input, expected) {
|
9
|
-
dot.object(input)
|
10
|
-
JSON.stringify(input).should.eql(JSON.stringify(expected))
|
11
|
-
}
|
12
|
-
|
13
|
-
describe('Test Data:', function () {
|
14
|
-
var dot = new Dot()
|
15
|
-
function testIt (test) {
|
16
|
-
it(test.name, function () {
|
17
|
-
if (test.options) {
|
18
|
-
Object.keys(test.options).forEach(function (name) {
|
19
|
-
dot[name] = test.options[name]
|
20
|
-
})
|
21
|
-
}
|
22
|
-
|
23
|
-
if (Array.isArray(test.input)) {
|
24
|
-
if (
|
25
|
-
!Array.isArray(test.expected) ||
|
26
|
-
test.input.length !== test.expected.length
|
27
|
-
) {
|
28
|
-
throw Error('Input and Expected tests length must be the same')
|
29
|
-
}
|
30
|
-
test.expected.forEach((expected, i) => {
|
31
|
-
singleTest(dot, test.input[i], expected)
|
32
|
-
})
|
33
|
-
} else {
|
34
|
-
singleTest(dot, test.input, test.expected)
|
35
|
-
}
|
36
|
-
})
|
37
|
-
}
|
38
|
-
|
39
|
-
// note with object() it is possible to cleanup, with del it is not.
|
40
|
-
|
41
|
-
testData.forEach(testIt)
|
42
|
-
})
|
package/test/test_transforms.js
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
'use strict'
|
2
|
-
|
3
|
-
require('should')
|
4
|
-
var Dot = require('../index')
|
5
|
-
|
6
|
-
var testData = [
|
7
|
-
require('./transforms/twitter'),
|
8
|
-
require('./transforms/contact')
|
9
|
-
]
|
10
|
-
|
11
|
-
describe('Test Transforms:', function () {
|
12
|
-
var dot = new Dot()
|
13
|
-
function testIt (test) {
|
14
|
-
it(test.name, function () {
|
15
|
-
if (test.options) {
|
16
|
-
Object.keys(test.options).forEach(function (name) {
|
17
|
-
dot[name] = test.options[name]
|
18
|
-
})
|
19
|
-
}
|
20
|
-
var tgt1 = {}
|
21
|
-
var tgt2 = dot.transform(test.transform, test.input, tgt1)
|
22
|
-
JSON.stringify(tgt1).should.eql(JSON.stringify(test.expected))
|
23
|
-
JSON.stringify(tgt2).should.eql(JSON.stringify(test.expected))
|
24
|
-
})
|
25
|
-
}
|
26
|
-
|
27
|
-
testData.forEach(testIt)
|
28
|
-
})
|
package/test/transfer.js
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
'use strict'
|
2
|
-
|
3
|
-
require('should')
|
4
|
-
var Dot = require('../index')
|
5
|
-
|
6
|
-
describe('Transfer:', function () {
|
7
|
-
it('Should be able to transfer properties', function () {
|
8
|
-
var src = {
|
9
|
-
name: 'John',
|
10
|
-
stuff: {
|
11
|
-
phone: {
|
12
|
-
brand: 'iphone',
|
13
|
-
version: 6
|
14
|
-
}
|
15
|
-
}
|
16
|
-
}
|
17
|
-
|
18
|
-
var tgt = {
|
19
|
-
name: 'Brandon'
|
20
|
-
}
|
21
|
-
|
22
|
-
var srcExpected = { name: 'John', stuff: {} }
|
23
|
-
|
24
|
-
var tgtExpected = {
|
25
|
-
name: 'Brandon',
|
26
|
-
wanna: {
|
27
|
-
haves: {
|
28
|
-
phone: {
|
29
|
-
brand: 'iphone',
|
30
|
-
version: 6
|
31
|
-
}
|
32
|
-
}
|
33
|
-
}
|
34
|
-
}
|
35
|
-
|
36
|
-
Dot.transfer('stuff.phone', 'wanna.haves.phone', src, tgt)
|
37
|
-
|
38
|
-
src.should.eql(srcExpected)
|
39
|
-
tgt.should.eql(tgtExpected)
|
40
|
-
})
|
41
|
-
|
42
|
-
it('Should process modifiers', function () {
|
43
|
-
var up = function (val) {
|
44
|
-
val.brand = val.brand.toUpperCase()
|
45
|
-
return val
|
46
|
-
}
|
47
|
-
|
48
|
-
var src = {
|
49
|
-
name: 'John',
|
50
|
-
stuff: {
|
51
|
-
phone: {
|
52
|
-
brand: 'iphone',
|
53
|
-
version: 6
|
54
|
-
}
|
55
|
-
}
|
56
|
-
}
|
57
|
-
|
58
|
-
var tgt = {
|
59
|
-
name: 'Brandon'
|
60
|
-
}
|
61
|
-
|
62
|
-
var srcExpected = { name: 'John', stuff: {} }
|
63
|
-
|
64
|
-
var tgtExpected = {
|
65
|
-
name: 'Brandon',
|
66
|
-
wanna: {
|
67
|
-
haves: {
|
68
|
-
phone: {
|
69
|
-
brand: 'IPHONE',
|
70
|
-
version: 6
|
71
|
-
}
|
72
|
-
}
|
73
|
-
}
|
74
|
-
}
|
75
|
-
|
76
|
-
Dot.transfer('stuff.phone', 'wanna.haves.phone', src, tgt, up)
|
77
|
-
|
78
|
-
src.should.eql(srcExpected)
|
79
|
-
tgt.should.eql(tgtExpected)
|
80
|
-
})
|
81
|
-
})
|
@@ -1,26 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"name": "Contact Transform",
|
3
|
-
"input": {
|
4
|
-
"id": 1,
|
5
|
-
"contact": {
|
6
|
-
"firstName": "John",
|
7
|
-
"lastName": "Doe",
|
8
|
-
"email": "example@test.com"
|
9
|
-
}
|
10
|
-
},
|
11
|
-
"transform": {
|
12
|
-
"id": "nr",
|
13
|
-
"contact.firstName": "name.first",
|
14
|
-
"contact.lastName": "name.last",
|
15
|
-
"contact.email": "email"
|
16
|
-
},
|
17
|
-
"expected": {
|
18
|
-
"nr": 1,
|
19
|
-
"name": {
|
20
|
-
"first": "John",
|
21
|
-
"last": "Doe"
|
22
|
-
},
|
23
|
-
"email": "example@test.com"
|
24
|
-
}
|
25
|
-
}
|
26
|
-
|
@@ -1,174 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"name": "Twitter Transform",
|
3
|
-
"input": {
|
4
|
-
"text": "RT @PostGradProblem: In preparation for the NFL lockout, I will be spending twice as much time analyzing my fantasy baseball team during ...",
|
5
|
-
"truncated": true,
|
6
|
-
"in_reply_to_user_id": null,
|
7
|
-
"in_reply_to_status_id": null,
|
8
|
-
"favorited": false,
|
9
|
-
"source": "<a href=\"http://twitter.com/\" rel=\"nofollow\">Twitter for iPhone</a>",
|
10
|
-
"in_reply_to_screen_name": null,
|
11
|
-
"in_reply_to_status_id_str": null,
|
12
|
-
"id_str": "54691802283900928",
|
13
|
-
"entities": {
|
14
|
-
"user_mentions": [
|
15
|
-
{
|
16
|
-
"indices": [
|
17
|
-
3,
|
18
|
-
19
|
19
|
-
],
|
20
|
-
"screen_name": "PostGradProblem",
|
21
|
-
"id_str": "271572434",
|
22
|
-
"name": "PostGradProblems",
|
23
|
-
"id": 271572434
|
24
|
-
}
|
25
|
-
],
|
26
|
-
"urls": [
|
27
|
-
|
28
|
-
],
|
29
|
-
"hashtags": [
|
30
|
-
|
31
|
-
]
|
32
|
-
},
|
33
|
-
"contributors": null,
|
34
|
-
"retweeted": false,
|
35
|
-
"in_reply_to_user_id_str": null,
|
36
|
-
"place": null,
|
37
|
-
"retweet_count": 4,
|
38
|
-
"created_at": "Sun Apr 03 23:48:36 +0000 2011",
|
39
|
-
"retweeted_status": {
|
40
|
-
"text": "In preparation for the NFL lockout, I will be spending twice as much time analyzing my fantasy baseball team during company time. #PGP",
|
41
|
-
"truncated": false,
|
42
|
-
"in_reply_to_user_id": null,
|
43
|
-
"in_reply_to_status_id": null,
|
44
|
-
"favorited": false,
|
45
|
-
"source": "<a href=\"http://www.hootsuite.com\" rel=\"nofollow\">HootSuite</a>",
|
46
|
-
"in_reply_to_screen_name": null,
|
47
|
-
"in_reply_to_status_id_str": null,
|
48
|
-
"id_str": "54640519019642881",
|
49
|
-
"entities": {
|
50
|
-
"user_mentions": [
|
51
|
-
|
52
|
-
],
|
53
|
-
"urls": [
|
54
|
-
|
55
|
-
],
|
56
|
-
"hashtags": [
|
57
|
-
{
|
58
|
-
"text": "PGP",
|
59
|
-
"indices": [
|
60
|
-
130,
|
61
|
-
134
|
62
|
-
]
|
63
|
-
}
|
64
|
-
]
|
65
|
-
},
|
66
|
-
"contributors": null,
|
67
|
-
"retweeted": false,
|
68
|
-
"in_reply_to_user_id_str": null,
|
69
|
-
"place": null,
|
70
|
-
"retweet_count": 4,
|
71
|
-
"created_at": "Sun Apr 03 20:24:49 +0000 2011",
|
72
|
-
"user": {
|
73
|
-
"notifications": null,
|
74
|
-
"profile_use_background_image": true,
|
75
|
-
"statuses_count": 31,
|
76
|
-
"profile_background_color": "C0DEED",
|
77
|
-
"followers_count": 3066,
|
78
|
-
"profile_image_url": "http://a2.twimg.com/profile_images/1285770264/PGP_normal.jpg",
|
79
|
-
"listed_count": 6,
|
80
|
-
"profile_background_image_url": "http://a3.twimg.com/a/1301071706/images/themes/theme1/bg.png",
|
81
|
-
"description": "",
|
82
|
-
"screen_name": "PostGradProblem",
|
83
|
-
"default_profile": true,
|
84
|
-
"verified": false,
|
85
|
-
"time_zone": null,
|
86
|
-
"profile_text_color": "333333",
|
87
|
-
"is_translator": false,
|
88
|
-
"profile_sidebar_fill_color": "DDEEF6",
|
89
|
-
"location": "",
|
90
|
-
"id_str": "271572434",
|
91
|
-
"default_profile_image": false,
|
92
|
-
"profile_background_tile": false,
|
93
|
-
"lang": "en",
|
94
|
-
"friends_count": 21,
|
95
|
-
"protected": false,
|
96
|
-
"favourites_count": 0,
|
97
|
-
"created_at": "Thu Mar 24 19:45:44 +0000 2011",
|
98
|
-
"profile_link_color": "0084B4",
|
99
|
-
"name": "PostGradProblems",
|
100
|
-
"show_all_inline_media": false,
|
101
|
-
"follow_request_sent": null,
|
102
|
-
"geo_enabled": false,
|
103
|
-
"profile_sidebar_border_color": "C0DEED",
|
104
|
-
"url": null,
|
105
|
-
"id": 271572434,
|
106
|
-
"contributors_enabled": false,
|
107
|
-
"following": null,
|
108
|
-
"utc_offset": null
|
109
|
-
},
|
110
|
-
"id": 54640519019642880,
|
111
|
-
"coordinates": null,
|
112
|
-
"geo": null
|
113
|
-
},
|
114
|
-
"user": {
|
115
|
-
"notifications": null,
|
116
|
-
"profile_use_background_image": true,
|
117
|
-
"statuses_count": 351,
|
118
|
-
"profile_background_color": "C0DEED",
|
119
|
-
"followers_count": 48,
|
120
|
-
"profile_image_url": "http://a1.twimg.com/profile_images/455128973/gCsVUnofNqqyd6tdOGevROvko1_500_normal.jpg",
|
121
|
-
"listed_count": 0,
|
122
|
-
"profile_background_image_url": "http://a3.twimg.com/a/1300479984/images/themes/theme1/bg.png",
|
123
|
-
"description": "watcha doin in my waters?",
|
124
|
-
"screen_name": "OldGREG85",
|
125
|
-
"default_profile": true,
|
126
|
-
"verified": false,
|
127
|
-
"time_zone": "Hawaii",
|
128
|
-
"profile_text_color": "333333",
|
129
|
-
"is_translator": false,
|
130
|
-
"profile_sidebar_fill_color": "DDEEF6",
|
131
|
-
"location": "Texas",
|
132
|
-
"id_str": "80177619",
|
133
|
-
"default_profile_image": false,
|
134
|
-
"profile_background_tile": false,
|
135
|
-
"lang": "en",
|
136
|
-
"friends_count": 81,
|
137
|
-
"protected": false,
|
138
|
-
"favourites_count": 0,
|
139
|
-
"created_at": "Tue Oct 06 01:13:17 +0000 2009",
|
140
|
-
"profile_link_color": "0084B4",
|
141
|
-
"name": "GG",
|
142
|
-
"show_all_inline_media": false,
|
143
|
-
"follow_request_sent": null,
|
144
|
-
"geo_enabled": false,
|
145
|
-
"profile_sidebar_border_color": "C0DEED",
|
146
|
-
"url": null,
|
147
|
-
"id": 80177619,
|
148
|
-
"contributors_enabled": false,
|
149
|
-
"following": null,
|
150
|
-
"utc_offset": -36000
|
151
|
-
},
|
152
|
-
"id": 54691802283900930,
|
153
|
-
"coordinates": null,
|
154
|
-
"geo": null
|
155
|
-
},
|
156
|
-
"transform": {
|
157
|
-
"text": "content",
|
158
|
-
"created_at": "time",
|
159
|
-
"user.location": "location",
|
160
|
-
"user.favourites_count": "stats.favs",
|
161
|
-
"user.followers_count": "stats.followers",
|
162
|
-
"user.statuses_count": "stats.statuses"
|
163
|
-
},
|
164
|
-
"expected": {
|
165
|
-
"content": "RT @PostGradProblem: In preparation for the NFL lockout, I will be spending twice as much time analyzing my fantasy baseball team during ...",
|
166
|
-
"time": "Sun Apr 03 23:48:36 +0000 2011",
|
167
|
-
"location": "Texas",
|
168
|
-
"stats": {
|
169
|
-
"favs": 0,
|
170
|
-
"followers": 48,
|
171
|
-
"statuses": 351
|
172
|
-
}
|
173
|
-
}
|
174
|
-
}
|
package/test/useArray.js
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
'use strict'
|
2
|
-
|
3
|
-
require('should')
|
4
|
-
var Dot = require('../index')
|
5
|
-
|
6
|
-
describe('useArray:', function () {
|
7
|
-
var dotObject, arrayObject, object
|
8
|
-
var arrayObjectExpected, objectExpected, dotObjectExpected
|
9
|
-
|
10
|
-
beforeEach(function () {
|
11
|
-
dotObject = {
|
12
|
-
'a.0': 'value'
|
13
|
-
}
|
14
|
-
dotObjectExpected = {
|
15
|
-
'a.0': 'value'
|
16
|
-
}
|
17
|
-
arrayObject = {
|
18
|
-
a: ['value']
|
19
|
-
}
|
20
|
-
arrayObjectExpected = {
|
21
|
-
a: ['value']
|
22
|
-
}
|
23
|
-
object = {
|
24
|
-
a: {
|
25
|
-
0: 'value'
|
26
|
-
}
|
27
|
-
}
|
28
|
-
objectExpected = {
|
29
|
-
a: {
|
30
|
-
0: 'value'
|
31
|
-
}
|
32
|
-
}
|
33
|
-
})
|
34
|
-
|
35
|
-
it('default is using array ', function () {
|
36
|
-
var dotLocal = require('../index')
|
37
|
-
arrayObjectExpected.should.eql(dotLocal.object(dotObject))
|
38
|
-
})
|
39
|
-
it('Should convert dot using arrays ', function () {
|
40
|
-
Dot.useArray = true
|
41
|
-
arrayObjectExpected.should.eql(Dot.object(dotObject))
|
42
|
-
})
|
43
|
-
it('Should convert dot not using arrays ', function () {
|
44
|
-
Dot.useArray = false
|
45
|
-
objectExpected.should.eql(Dot.object(dotObject))
|
46
|
-
})
|
47
|
-
it('Should convert object using arrays ', function () {
|
48
|
-
Dot.useArray = true
|
49
|
-
arrayObjectExpected.should.eql(Dot.object(dotObject))
|
50
|
-
})
|
51
|
-
it('Should convert dot using arrays and convert back equals source', function () {
|
52
|
-
Dot.useArray = true
|
53
|
-
Dot.useBrackets = false
|
54
|
-
dotObjectExpected.should.eql(Dot.dot(Dot.object(dotObject)))
|
55
|
-
})
|
56
|
-
it('Should convert object using arrays and convert back equals source', function () {
|
57
|
-
Dot.useArray = true
|
58
|
-
arrayObjectExpected.should.eql(Dot.object(Dot.dot(object)))
|
59
|
-
})
|
60
|
-
it('Should convert dot not using arrays and convert back equals source', function () {
|
61
|
-
Dot.useArray = false
|
62
|
-
dotObjectExpected.should.eql(Dot.dot(Dot.object(dotObject)))
|
63
|
-
})
|
64
|
-
it('Should convert object not using arrays and convert back equals source', function () {
|
65
|
-
Dot.useArray = false
|
66
|
-
objectExpected.should.eql(Dot.object(Dot.dot(arrayObject)))
|
67
|
-
})
|
68
|
-
})
|