| Server IP : 107.13.46.68 / Your IP : 216.73.216.232 Web Server : Apache/2.4.58 (Ubuntu) System : Linux mariOS 6.8.0-51-generic #52-Ubuntu SMP PREEMPT_DYNAMIC Thu Dec 5 13:09:44 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /usr/share/nodejs/get-value/ |
Upload File : |
/*!
* get-value <https://github.com/jonschlinkert/get-value>
*
* Copyright (c) 2014-2018, Jon Schlinkert.
* Released under the MIT License.
*/
const isObject = require('isobject');
module.exports = function(target, path, options) {
if (!isObject(options)) {
options = { default: options };
}
if (!isValidObject(target)) {
return typeof options.default !== 'undefined' ? options.default : target;
}
if (typeof path === 'number') {
path = String(path);
}
const isArray = Array.isArray(path);
const isString = typeof path === 'string';
const splitChar = options.separator || '.';
const joinChar = options.joinChar || (typeof splitChar === 'string' ? splitChar : '.');
if (!isString && !isArray) {
return target;
}
if (isString && path in target) {
return isValid(path, target, options) ? target[path] : options.default;
}
let segs = isArray ? path : split(path, splitChar, options);
let len = segs.length;
let idx = 0;
do {
let prop = segs[idx];
if (typeof prop === 'number') {
prop = String(prop);
}
while (prop && prop.slice(-1) === '\\') {
prop = join([prop.slice(0, -1), segs[++idx] || ''], joinChar, options);
}
if (prop in target) {
if (!isValid(prop, target, options)) {
return options.default;
}
target = target[prop];
} else {
let hasProp = false;
let n = idx + 1;
while (n < len) {
prop = join([prop, segs[n++]], joinChar, options);
if ((hasProp = prop in target)) {
if (!isValid(prop, target, options)) {
return options.default;
}
target = target[prop];
idx = n - 1;
break;
}
}
if (!hasProp) {
return options.default;
}
}
} while (++idx < len && isValidObject(target));
if (idx === len) {
return target;
}
return options.default;
};
function join(segs, joinChar, options) {
if (typeof options.join === 'function') {
return options.join(segs);
}
return segs[0] + joinChar + segs[1];
}
function split(path, splitChar, options) {
if (typeof options.split === 'function') {
return options.split(path);
}
return path.split(splitChar);
}
function isValid(key, target, options) {
if (typeof options.isValid === 'function') {
return options.isValid(key, target);
}
return true;
}
function isValidObject(val) {
return isObject(val) || Array.isArray(val) || typeof val === 'function';
}