1
1
/* eslint strict:off */
2
+ /* eslint no-var: off */
3
+ /* eslint no-redeclare: off */
2
4
3
- const stringToParts = require ( './stringToParts' ) ;
5
+ var stringToParts = require ( './stringToParts' ) ;
4
6
5
7
// These properties are special and can open client libraries to security
6
8
// issues
7
- const ignoreProperties = [ '__proto__' , 'constructor' , 'prototype' ] ;
9
+ var ignoreProperties = [ '__proto__' , 'constructor' , 'prototype' ] ;
8
10
9
11
/**
10
12
* Returns the value of object `o` at the given `path`.
@@ -35,7 +37,7 @@ const ignoreProperties = ['__proto__', 'constructor', 'prototype'];
35
37
*/
36
38
37
39
exports . get = function ( path , o , special , map ) {
38
- let lookup ;
40
+ var lookup ;
39
41
40
42
if ( 'function' == typeof special ) {
41
43
if ( special . length < 2 ) {
@@ -49,23 +51,23 @@ exports.get = function(path, o, special, map) {
49
51
50
52
map || ( map = K ) ;
51
53
52
- const parts = 'string' == typeof path
54
+ var parts = 'string' == typeof path
53
55
? stringToParts ( path )
54
56
: path ;
55
57
56
58
if ( ! Array . isArray ( parts ) ) {
57
59
throw new TypeError ( 'Invalid `path`. Must be either string or array' ) ;
58
60
}
59
61
60
- let obj = o ,
62
+ var obj = o ,
61
63
part ;
62
64
63
- for ( let i = 0 ; i < parts . length ; ++ i ) {
65
+ for ( var i = 0 ; i < parts . length ; ++ i ) {
64
66
part = parts [ i ] ;
65
67
66
68
if ( Array . isArray ( obj ) && ! / ^ \d + $ / . test ( part ) ) {
67
69
// reading a property from the array items
68
- const paths = parts . slice ( i ) ;
70
+ var paths = parts . slice ( i ) ;
69
71
70
72
// Need to `concat()` to avoid `map()` calling a constructor of an array
71
73
// subclass
@@ -79,7 +81,7 @@ exports.get = function(path, o, special, map) {
79
81
if ( lookup ) {
80
82
obj = lookup ( obj , part ) ;
81
83
} else {
82
- const _from = special && obj [ special ] ? obj [ special ] : obj ;
84
+ var _from = special && obj [ special ] ? obj [ special ] : obj ;
83
85
obj = _from instanceof Map ?
84
86
_from . get ( part ) :
85
87
_from [ part ] ;
@@ -99,17 +101,17 @@ exports.get = function(path, o, special, map) {
99
101
*/
100
102
101
103
exports . has = function ( path , o ) {
102
- const parts = typeof path === 'string' ?
104
+ var parts = typeof path === 'string' ?
103
105
stringToParts ( path ) :
104
106
path ;
105
107
106
108
if ( ! Array . isArray ( parts ) ) {
107
109
throw new TypeError ( 'Invalid `path`. Must be either string or array' ) ;
108
110
}
109
111
110
- const len = parts . length ;
111
- let cur = o ;
112
- for ( let i = 0 ; i < len ; ++ i ) {
112
+ var len = parts . length ;
113
+ var cur = o ;
114
+ for ( var i = 0 ; i < len ; ++ i ) {
113
115
if ( cur == null || typeof cur !== 'object' || ! ( parts [ i ] in cur ) ) {
114
116
return false ;
115
117
}
@@ -127,17 +129,17 @@ exports.has = function(path, o) {
127
129
*/
128
130
129
131
exports . unset = function ( path , o ) {
130
- const parts = typeof path === 'string' ?
132
+ var parts = typeof path === 'string' ?
131
133
stringToParts ( path ) :
132
134
path ;
133
135
134
136
if ( ! Array . isArray ( parts ) ) {
135
137
throw new TypeError ( 'Invalid `path`. Must be either string or array' ) ;
136
138
}
137
139
138
- const len = parts . length ;
139
- let cur = o ;
140
- for ( let i = 0 ; i < len ; ++ i ) {
140
+ var len = parts . length ;
141
+ var cur = o ;
142
+ for ( var i = 0 ; i < len ; ++ i ) {
141
143
if ( cur == null || typeof cur !== 'object' || ! ( parts [ i ] in cur ) ) {
142
144
return false ;
143
145
}
@@ -166,7 +168,7 @@ exports.unset = function(path, o) {
166
168
*/
167
169
168
170
exports . set = function ( path , val , o , special , map , _copying ) {
169
- let lookup ;
171
+ var lookup ;
170
172
171
173
if ( 'function' == typeof special ) {
172
174
if ( special . length < 2 ) {
@@ -180,7 +182,7 @@ exports.set = function(path, val, o, special, map, _copying) {
180
182
181
183
map || ( map = K ) ;
182
184
183
- const parts = 'string' == typeof path
185
+ var parts = 'string' == typeof path
184
186
? stringToParts ( path )
185
187
: path ;
186
188
@@ -190,7 +192,7 @@ exports.set = function(path, val, o, special, map, _copying) {
190
192
191
193
if ( null == o ) return ;
192
194
193
- for ( let i = 0 ; i < parts . length ; ++ i ) {
195
+ for ( var i = 0 ; i < parts . length ; ++ i ) {
194
196
// Silently ignore any updates to `__proto__`, these are potentially
195
197
// dangerous if using mpath with unsanitized data.
196
198
if ( ignoreProperties . indexOf ( parts [ i ] ) !== - 1 ) {
@@ -203,12 +205,11 @@ exports.set = function(path, val, o, special, map, _copying) {
203
205
// the array to the one by one to matching positions of the
204
206
// current array. Unless the user explicitly opted out by passing
205
207
// false, see Automattic/mongoose#6273
206
- const copy = _copying || ( / \$ / . test ( path ) && _copying !== false ) ;
207
- let obj = o ;
208
- let part ;
209
- const len = parts . length - 1 ;
208
+ var copy = _copying || ( / \$ / . test ( path ) && _copying !== false ) ,
209
+ obj = o ,
210
+ part ;
210
211
211
- for ( let i = 0 ; i < len ; ++ i ) {
212
+ for ( var i = 0 , len = parts . length - 1 ; i < len ; ++ i ) {
212
213
part = parts [ i ] ;
213
214
214
215
if ( '$' == part ) {
@@ -220,14 +221,14 @@ exports.set = function(path, val, o, special, map, _copying) {
220
221
}
221
222
222
223
if ( Array . isArray ( obj ) && ! / ^ \d + $ / . test ( part ) ) {
223
- const paths = parts . slice ( i ) ;
224
+ var paths = parts . slice ( i ) ;
224
225
if ( ! copy && Array . isArray ( val ) ) {
225
- for ( let j = 0 ; j < obj . length && j < val . length ; ++ j ) {
226
+ for ( var j = 0 ; j < obj . length && j < val . length ; ++ j ) {
226
227
// assignment of single values of array
227
228
exports . set ( paths , val [ j ] , obj [ j ] , special || lookup , map , copy ) ;
228
229
}
229
230
} else {
230
- for ( let j = 0 ; j < obj . length ; ++ j ) {
231
+ for ( var j = 0 ; j < obj . length ; ++ j ) {
231
232
// assignment of entire value
232
233
exports . set ( paths , val , obj [ j ] , special || lookup , map , copy ) ;
233
234
}
@@ -238,7 +239,7 @@ exports.set = function(path, val, o, special, map, _copying) {
238
239
if ( lookup ) {
239
240
obj = lookup ( obj , part ) ;
240
241
} else {
241
- const _to = special && obj [ special ] ? obj [ special ] : obj ;
242
+ var _to = special && obj [ special ] ? obj [ special ] : obj ;
242
243
obj = _to instanceof Map ?
243
244
_to . get ( part ) :
244
245
_to [ part ] ;
@@ -261,8 +262,8 @@ exports.set = function(path, val, o, special, map, _copying) {
261
262
if ( ! copy && Array . isArray ( val ) ) {
262
263
_setArray ( obj , val , part , lookup , special , map ) ;
263
264
} else {
264
- for ( let j = 0 ; j < obj . length ; ++ j ) {
265
- let item = obj [ j ] ;
265
+ for ( var j = 0 ; j < obj . length ; ++ j ) {
266
+ var item = obj [ j ] ;
266
267
if ( item ) {
267
268
if ( lookup ) {
268
269
lookup ( item , part , map ( val ) ) ;
@@ -289,8 +290,8 @@ exports.set = function(path, val, o, special, map, _copying) {
289
290
*/
290
291
291
292
function _setArray ( obj , val , part , lookup , special , map ) {
292
- for ( let j = 0 ; j < obj . length && j < val . length ; ++ j ) {
293
- let item = obj [ j ] ;
293
+ for ( var item , j = 0 ; j < obj . length && j < val . length ; ++ j ) {
294
+ item = obj [ j ] ;
294
295
if ( Array . isArray ( item ) && Array . isArray ( val [ j ] ) ) {
295
296
_setArray ( item , val [ j ] , part , lookup , special , map ) ;
296
297
} else if ( item ) {
@@ -310,4 +311,4 @@ function _setArray(obj, val, part, lookup, special, map) {
310
311
311
312
function K ( v ) {
312
313
return v ;
313
- }
314
+ }
0 commit comments