Skip to content

Commit f050c3a

Browse files
committed
fix: use var instead of let/const for Node.js 4.x support
1 parent e3bdd36 commit f050c3a

File tree

1 file changed

+34
-33
lines changed

1 file changed

+34
-33
lines changed

lib/index.js

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
/* eslint strict:off */
2+
/* eslint no-var: off */
3+
/* eslint no-redeclare: off */
24

3-
const stringToParts = require('./stringToParts');
5+
var stringToParts = require('./stringToParts');
46

57
// These properties are special and can open client libraries to security
68
// issues
7-
const ignoreProperties = ['__proto__', 'constructor', 'prototype'];
9+
var ignoreProperties = ['__proto__', 'constructor', 'prototype'];
810

911
/**
1012
* Returns the value of object `o` at the given `path`.
@@ -35,7 +37,7 @@ const ignoreProperties = ['__proto__', 'constructor', 'prototype'];
3537
*/
3638

3739
exports.get = function(path, o, special, map) {
38-
let lookup;
40+
var lookup;
3941

4042
if ('function' == typeof special) {
4143
if (special.length < 2) {
@@ -49,23 +51,23 @@ exports.get = function(path, o, special, map) {
4951

5052
map || (map = K);
5153

52-
const parts = 'string' == typeof path
54+
var parts = 'string' == typeof path
5355
? stringToParts(path)
5456
: path;
5557

5658
if (!Array.isArray(parts)) {
5759
throw new TypeError('Invalid `path`. Must be either string or array');
5860
}
5961

60-
let obj = o,
62+
var obj = o,
6163
part;
6264

63-
for (let i = 0; i < parts.length; ++i) {
65+
for (var i = 0; i < parts.length; ++i) {
6466
part = parts[i];
6567

6668
if (Array.isArray(obj) && !/^\d+$/.test(part)) {
6769
// reading a property from the array items
68-
const paths = parts.slice(i);
70+
var paths = parts.slice(i);
6971

7072
// Need to `concat()` to avoid `map()` calling a constructor of an array
7173
// subclass
@@ -79,7 +81,7 @@ exports.get = function(path, o, special, map) {
7981
if (lookup) {
8082
obj = lookup(obj, part);
8183
} else {
82-
const _from = special && obj[special] ? obj[special] : obj;
84+
var _from = special && obj[special] ? obj[special] : obj;
8385
obj = _from instanceof Map ?
8486
_from.get(part) :
8587
_from[part];
@@ -99,17 +101,17 @@ exports.get = function(path, o, special, map) {
99101
*/
100102

101103
exports.has = function(path, o) {
102-
const parts = typeof path === 'string' ?
104+
var parts = typeof path === 'string' ?
103105
stringToParts(path) :
104106
path;
105107

106108
if (!Array.isArray(parts)) {
107109
throw new TypeError('Invalid `path`. Must be either string or array');
108110
}
109111

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) {
113115
if (cur == null || typeof cur !== 'object' || !(parts[i] in cur)) {
114116
return false;
115117
}
@@ -127,17 +129,17 @@ exports.has = function(path, o) {
127129
*/
128130

129131
exports.unset = function(path, o) {
130-
const parts = typeof path === 'string' ?
132+
var parts = typeof path === 'string' ?
131133
stringToParts(path) :
132134
path;
133135

134136
if (!Array.isArray(parts)) {
135137
throw new TypeError('Invalid `path`. Must be either string or array');
136138
}
137139

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) {
141143
if (cur == null || typeof cur !== 'object' || !(parts[i] in cur)) {
142144
return false;
143145
}
@@ -166,7 +168,7 @@ exports.unset = function(path, o) {
166168
*/
167169

168170
exports.set = function(path, val, o, special, map, _copying) {
169-
let lookup;
171+
var lookup;
170172

171173
if ('function' == typeof special) {
172174
if (special.length < 2) {
@@ -180,7 +182,7 @@ exports.set = function(path, val, o, special, map, _copying) {
180182

181183
map || (map = K);
182184

183-
const parts = 'string' == typeof path
185+
var parts = 'string' == typeof path
184186
? stringToParts(path)
185187
: path;
186188

@@ -190,7 +192,7 @@ exports.set = function(path, val, o, special, map, _copying) {
190192

191193
if (null == o) return;
192194

193-
for (let i = 0; i < parts.length; ++i) {
195+
for (var i = 0; i < parts.length; ++i) {
194196
// Silently ignore any updates to `__proto__`, these are potentially
195197
// dangerous if using mpath with unsanitized data.
196198
if (ignoreProperties.indexOf(parts[i]) !== -1) {
@@ -203,12 +205,11 @@ exports.set = function(path, val, o, special, map, _copying) {
203205
// the array to the one by one to matching positions of the
204206
// current array. Unless the user explicitly opted out by passing
205207
// 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;
210211

211-
for (let i = 0; i < len; ++i) {
212+
for (var i = 0, len = parts.length - 1; i < len; ++i) {
212213
part = parts[i];
213214

214215
if ('$' == part) {
@@ -220,14 +221,14 @@ exports.set = function(path, val, o, special, map, _copying) {
220221
}
221222

222223
if (Array.isArray(obj) && !/^\d+$/.test(part)) {
223-
const paths = parts.slice(i);
224+
var paths = parts.slice(i);
224225
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) {
226227
// assignment of single values of array
227228
exports.set(paths, val[j], obj[j], special || lookup, map, copy);
228229
}
229230
} else {
230-
for (let j = 0; j < obj.length; ++j) {
231+
for (var j = 0; j < obj.length; ++j) {
231232
// assignment of entire value
232233
exports.set(paths, val, obj[j], special || lookup, map, copy);
233234
}
@@ -238,7 +239,7 @@ exports.set = function(path, val, o, special, map, _copying) {
238239
if (lookup) {
239240
obj = lookup(obj, part);
240241
} else {
241-
const _to = special && obj[special] ? obj[special] : obj;
242+
var _to = special && obj[special] ? obj[special] : obj;
242243
obj = _to instanceof Map ?
243244
_to.get(part) :
244245
_to[part];
@@ -261,8 +262,8 @@ exports.set = function(path, val, o, special, map, _copying) {
261262
if (!copy && Array.isArray(val)) {
262263
_setArray(obj, val, part, lookup, special, map);
263264
} 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];
266267
if (item) {
267268
if (lookup) {
268269
lookup(item, part, map(val));
@@ -289,8 +290,8 @@ exports.set = function(path, val, o, special, map, _copying) {
289290
*/
290291

291292
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];
294295
if (Array.isArray(item) && Array.isArray(val[j])) {
295296
_setArray(item, val[j], part, lookup, special, map);
296297
} else if (item) {
@@ -310,4 +311,4 @@ function _setArray(obj, val, part, lookup, special, map) {
310311

311312
function K(v) {
312313
return v;
313-
}
314+
}

0 commit comments

Comments
 (0)