forked from dawidd6/action-download-artifact
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot.js
More file actions
155 lines (138 loc) · 3.62 KB
/
Copy pathdot.js
File metadata and controls
155 lines (138 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
'use strict'
require('should')
var Dot = require('../index')
var pkg = require('./fixtures/package.json')
describe('dot():', function () {
var obj
// Dot.useBrackets = false;
beforeEach(function () {
obj = {
id: 'my-id',
nes: {
ted: {
value: true
}
},
other: {
nested: {
stuff: 5
}
},
nested: {
array: [
{
with: 'object1'
},
{
and: 'object2'
}
]
},
some: {
array: ['A', 'B']
},
ehrm: 123,
dates: {
first: new Date('Mon Oct 13 2014 00:00:00 GMT+0100 (BST)')
},
arrays: [
[
[
{
all: [
[
{
the: [
'way',
['down']
]
}
]
]
}
]
]
]
}
})
it('Should be able to convert to dotted-key/value pairs', function () {
var expected = {
id: 'my-id',
'nes.ted.value': true,
'other.nested.stuff': 5,
'nested.array[0].with': 'object1',
'nested.array[1].and': 'object2',
'some.array[0]': 'A',
'some.array[1]': 'B',
ehrm: 123,
'dates.first': new Date('Mon Oct 13 2014 00:00:00 GMT+0100 (BST)'),
'arrays[0][0][0].all[0][0].the[0]': 'way',
'arrays[0][0][0].all[0][0].the[1][0]': 'down'
}
Dot.dot(obj).should.eql(expected)
})
it('dot() should equal object()', function () {
Dot.object(Dot.dot(pkg)).should.eql(pkg)
})
it('keepArray prevents arrays from being dotted', function () {
var expected = {
id: 'my-id',
'nes.ted.value': true,
'other.nested.stuff': 5,
'nested.array': [{
with: 'object1'
}, {
and: 'object2'
}],
'some.array': ['A', 'B'],
ehrm: 123,
'dates.first': new Date('Mon Oct 13 2014 00:00:00 GMT+0100 (BST)'),
arrays: JSON.parse(JSON.stringify(obj.arrays))
}
Dot.keepArray = true
Dot.dot(obj).should.eql(expected)
Dot.keepArray = false
})
it('useBrackets wrap indexes with brackets', function () {
var expected = {
id: 'my-id',
'nes.ted.value': true,
'other.nested.stuff': 5,
'nested.array[0].with': 'object1',
'nested.array[1].and': 'object2',
'some.array[0]': 'A',
'some.array[1]': 'B',
ehrm: 123,
'dates.first': new Date('Mon Oct 13 2014 00:00:00 GMT+0100 (BST)'),
'arrays[0][0][0].all[0][0].the[0]': 'way',
'arrays[0][0][0].all[0][0].the[1][0]': 'down'
}
Dot.dot(obj).should.eql(expected)
})
it('useBrackets wrap indexes without brackets', function () {
var expected = {
id: 'my-id',
'nes.ted.value': true,
'other.nested.stuff': 5,
'nested.array.0.with': 'object1',
'nested.array.1.and': 'object2',
'some.array.0': 'A',
'some.array.1': 'B',
ehrm: 123,
'dates.first': new Date('Mon Oct 13 2014 00:00:00 GMT+0100 (BST)'),
'arrays.0.0.0.all.0.0.the.0': 'way',
'arrays.0.0.0.all.0.0.the.1.0': 'down'
}
Dot.useBrackets = false
Dot.dot(obj).should.eql(expected)
Dot.useBrackets = true
})
it('Always keeps empty arrays', function () {
Dot.dot({ hello: [] }).should.eql({ hello: [] })
Dot.dot({ hello: { world: [] } }).should.eql({ 'hello.world': [] })
})
it('Always keeps empty objects', function () {
Dot.dot({ hello: {} }).should.eql({ hello: {} })
Dot.dot({ hello: { world: {} } }).should.eql({ 'hello.world': {} })
})
})