Cleanup
This commit is contained in:
58
node_modules/mpath/lib/index.js
generated
vendored
58
node_modules/mpath/lib/index.js
generated
vendored
@@ -1,3 +1,9 @@
|
||||
/* eslint strict:off */
|
||||
/* eslint no-var: off */
|
||||
/* eslint no-redeclare: off */
|
||||
|
||||
var stringToParts = require('./stringToParts');
|
||||
|
||||
// These properties are special and can open client libraries to security
|
||||
// issues
|
||||
var ignoreProperties = ['__proto__', 'constructor', 'prototype'];
|
||||
@@ -30,7 +36,7 @@ var ignoreProperties = ['__proto__', 'constructor', 'prototype'];
|
||||
* @param {Function} [map] Optional function which receives each individual found value. The value returned from `map` is used in the original values place.
|
||||
*/
|
||||
|
||||
exports.get = function (path, o, special, map) {
|
||||
exports.get = function(path, o, special, map) {
|
||||
var lookup;
|
||||
|
||||
if ('function' == typeof special) {
|
||||
@@ -46,18 +52,21 @@ exports.get = function (path, o, special, map) {
|
||||
map || (map = K);
|
||||
|
||||
var parts = 'string' == typeof path
|
||||
? path.split('.')
|
||||
: path
|
||||
? stringToParts(path)
|
||||
: path;
|
||||
|
||||
if (!Array.isArray(parts)) {
|
||||
throw new TypeError('Invalid `path`. Must be either string or array');
|
||||
}
|
||||
|
||||
var obj = o
|
||||
, part;
|
||||
var obj = o,
|
||||
part;
|
||||
|
||||
for (var i = 0; i < parts.length; ++i) {
|
||||
part = parts[i];
|
||||
if (typeof parts[i] !== 'string' && typeof parts[i] !== 'number') {
|
||||
throw new TypeError('Each segment of path to `get()` must be a string or number, got ' + typeof parts[i]);
|
||||
}
|
||||
|
||||
if (Array.isArray(obj) && !/^\d+$/.test(part)) {
|
||||
// reading a property from the array items
|
||||
@@ -65,7 +74,7 @@ exports.get = function (path, o, special, map) {
|
||||
|
||||
// Need to `concat()` to avoid `map()` calling a constructor of an array
|
||||
// subclass
|
||||
return [].concat(obj).map(function (item) {
|
||||
return [].concat(obj).map(function(item) {
|
||||
return item
|
||||
? exports.get(paths, item, special || lookup, map)
|
||||
: map(undefined);
|
||||
@@ -94,9 +103,9 @@ exports.get = function (path, o, special, map) {
|
||||
* @param {Object} o
|
||||
*/
|
||||
|
||||
exports.has = function (path, o) {
|
||||
exports.has = function(path, o) {
|
||||
var parts = typeof path === 'string' ?
|
||||
path.split('.') :
|
||||
stringToParts(path) :
|
||||
path;
|
||||
|
||||
if (!Array.isArray(parts)) {
|
||||
@@ -106,6 +115,9 @@ exports.has = function (path, o) {
|
||||
var len = parts.length;
|
||||
var cur = o;
|
||||
for (var i = 0; i < len; ++i) {
|
||||
if (typeof parts[i] !== 'string' && typeof parts[i] !== 'number') {
|
||||
throw new TypeError('Each segment of path to `has()` must be a string or number, got ' + typeof parts[i]);
|
||||
}
|
||||
if (cur == null || typeof cur !== 'object' || !(parts[i] in cur)) {
|
||||
return false;
|
||||
}
|
||||
@@ -122,9 +134,9 @@ exports.has = function (path, o) {
|
||||
* @param {Object} o
|
||||
*/
|
||||
|
||||
exports.unset = function (path, o) {
|
||||
exports.unset = function(path, o) {
|
||||
var parts = typeof path === 'string' ?
|
||||
path.split('.') :
|
||||
stringToParts(path) :
|
||||
path;
|
||||
|
||||
if (!Array.isArray(parts)) {
|
||||
@@ -137,6 +149,9 @@ exports.unset = function (path, o) {
|
||||
if (cur == null || typeof cur !== 'object' || !(parts[i] in cur)) {
|
||||
return false;
|
||||
}
|
||||
if (typeof parts[i] !== 'string' && typeof parts[i] !== 'number') {
|
||||
throw new TypeError('Each segment of path to `unset()` must be a string or number, got ' + typeof parts[i]);
|
||||
}
|
||||
// Disallow any updates to __proto__ or special properties.
|
||||
if (ignoreProperties.indexOf(parts[i]) !== -1) {
|
||||
return false;
|
||||
@@ -161,7 +176,7 @@ exports.unset = function (path, o) {
|
||||
* @param {Function} [map] Optional function which is passed each individual value before setting it. The value returned from `map` is used in the original values place.
|
||||
*/
|
||||
|
||||
exports.set = function (path, val, o, special, map, _copying) {
|
||||
exports.set = function(path, val, o, special, map, _copying) {
|
||||
var lookup;
|
||||
|
||||
if ('function' == typeof special) {
|
||||
@@ -177,8 +192,8 @@ exports.set = function (path, val, o, special, map, _copying) {
|
||||
map || (map = K);
|
||||
|
||||
var parts = 'string' == typeof path
|
||||
? path.split('.')
|
||||
: path
|
||||
? stringToParts(path)
|
||||
: path;
|
||||
|
||||
if (!Array.isArray(parts)) {
|
||||
throw new TypeError('Invalid `path`. Must be either string or array');
|
||||
@@ -187,6 +202,9 @@ exports.set = function (path, val, o, special, map, _copying) {
|
||||
if (null == o) return;
|
||||
|
||||
for (var i = 0; i < parts.length; ++i) {
|
||||
if (typeof parts[i] !== 'string' && typeof parts[i] !== 'number') {
|
||||
throw new TypeError('Each segment of path to `set()` must be a string or number, got ' + typeof parts[i]);
|
||||
}
|
||||
// Silently ignore any updates to `__proto__`, these are potentially
|
||||
// dangerous if using mpath with unsanitized data.
|
||||
if (ignoreProperties.indexOf(parts[i]) !== -1) {
|
||||
@@ -199,9 +217,9 @@ exports.set = function (path, val, o, special, map, _copying) {
|
||||
// the array to the one by one to matching positions of the
|
||||
// current array. Unless the user explicitly opted out by passing
|
||||
// false, see Automattic/mongoose#6273
|
||||
var copy = _copying || (/\$/.test(path) && _copying !== false)
|
||||
, obj = o
|
||||
, part
|
||||
var copy = _copying || (/\$/.test(path) && _copying !== false),
|
||||
obj = o,
|
||||
part;
|
||||
|
||||
for (var i = 0, len = parts.length - 1; i < len; ++i) {
|
||||
part = parts[i];
|
||||
@@ -257,7 +275,7 @@ exports.set = function (path, val, o, special, map, _copying) {
|
||||
_setArray(obj, val, part, lookup, special, map);
|
||||
} else {
|
||||
for (var j = 0; j < obj.length; ++j) {
|
||||
item = obj[j];
|
||||
var item = obj[j];
|
||||
if (item) {
|
||||
if (lookup) {
|
||||
lookup(item, part, map(val));
|
||||
@@ -277,7 +295,7 @@ exports.set = function (path, val, o, special, map, _copying) {
|
||||
obj[part] = map(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*!
|
||||
* Recursively set nested arrays
|
||||
@@ -303,6 +321,6 @@ function _setArray(obj, val, part, lookup, special, map) {
|
||||
* Returns the value passed to it.
|
||||
*/
|
||||
|
||||
function K (v) {
|
||||
function K(v) {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user