Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

get-value

Package Overview
Dependencies
Maintainers
2
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-value - npm Package Compare versions

Comparing version 2.0.6 to 3.0.0

README.md

113

index.js
/*!
* get-value <https://github.com/jonschlinkert/get-value>
*
* Copyright (c) 2014-2015, Jon Schlinkert.
* Licensed under the MIT License.
* Copyright (c) 2014-2018, Jon Schlinkert.
* Released under the MIT License.
*/
module.exports = function(obj, prop, a, b, c) {
if (!isObject(obj) || !prop) {
return obj;
const isObject = require('isobject');
module.exports = function(target, path, options) {
if (!isObject(options)) {
options = { default: options };
}
prop = toString(prop);
if (!isValidObject(target)) {
return options.default != null ? options.default : target;
}
// allowing for multiple properties to be passed as
// a string or array, but much faster (3-4x) than doing
// `[].slice.call(arguments)`
if (a) prop += '.' + toString(a);
if (b) prop += '.' + toString(b);
if (c) prop += '.' + toString(c);
const isArray = Array.isArray(path);
const isString = typeof path === 'string';
const splitChar = options.separator || '.';
const joinChar = options.joinChar || (typeof splitChar === 'string' ? splitChar : '.');
if (prop in obj) {
return obj[prop];
if (!isString && !isArray) {
return target;
}
var segs = prop.split('.');
var len = segs.length;
var i = -1;
if (isString && path in target) {
return isValid(path, target, options) ? target[path] : options.default;
}
while (obj && (++i < len)) {
var key = segs[i];
while (key[key.length - 1] === '\\') {
key = key.slice(0, -1) + '.' + segs[++i];
let segs = isArray ? path : split(path, splitChar, options);
let len = segs.length;
let idx = 0;
do {
let prop = segs[idx];
while (prop && prop.slice(-1) === '\\') {
prop = join([prop.slice(0, -1), segs[++idx] || ''], joinChar, options);
}
obj = obj[key];
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 obj;
return options.default;
};
function isObject(val) {
return val !== null && (typeof val === 'object' || typeof val === 'function');
function join(segs, joinChar, options) {
if (typeof options.join === 'function') {
return options.join(segs);
}
return segs[0] + joinChar + segs[1];
}
function toString(val) {
if (!val) return '';
if (Array.isArray(val)) {
return val.join('.');
function split(path, splitChar, options) {
if (typeof options.split === 'function') {
return options.split(path);
}
return val;
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';
}
{
"name": "get-value",
"description": "Use property paths (`a.b.c`) to get a nested value from an object.",
"version": "2.0.6",
"description": "Use property paths like 'a.b.c' to get a nested value from an object. Even works when keys have dots in them (no other dot-prop library can do this!).",
"version": "3.0.0",
"homepage": "https://github.com/jonschlinkert/get-value",

@@ -17,21 +17,20 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",

"engines": {
"node": ">=0.10.0"
"node": ">=6.0"
},
"scripts": {
"test": "mocha"
"test": "nyc --reporter=text --reporter=html mocha"
},
"dependencies": {
"isobject": "^3.0.1"
},
"devDependencies": {
"ansi-bold": "^0.1.1",
"arr-reduce": "^1.0.1",
"benchmarked": "^0.1.4",
"dot-prop": "^2.2.0",
"benchmarked": "^2.0.0",
"dot-prop": "^4.2.0",
"getobject": "^0.1.0",
"gulp": "^3.9.0",
"gulp-eslint": "^1.1.1",
"gulp-format-md": "^0.1.5",
"gulp-istanbul": "^0.10.2",
"gulp-mocha": "^2.1.3",
"isobject": "^2.0.0",
"matched": "^0.3.2",
"minimist": "^1.2.0"
"gulp-format-md": "^1.0.0",
"micromatch": "^3.1.5",
"minimist": "^1.2.0",
"mocha": "^3.5.3",
"nyc": "^11.4.1"
},

@@ -55,3 +54,3 @@ "keywords": [

"run": true,
"toc": false,
"toc": "collapsible",
"layout": "default",

@@ -73,6 +72,2 @@ "tasks": [

},
"reflinks": [
"verb",
"verb-readme-generator"
],
"lint": {

@@ -79,0 +74,0 @@ "reflinks": true

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc