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

get-value

Package Overview
Dependencies
Maintainers
1
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 1.3.1 to 2.0.0

63

index.js

@@ -8,52 +8,33 @@ /*!

'use strict';
module.exports = function(obj, prop) {
if (!isObject(obj)) { return obj; }
var segs = toSegments(prop);
if (segs === null) return obj;
var utils = require('./utils');
var len = segs.length;
var i = -1;
module.exports = function getValue(obj, prop, fn) {
if (!utils.isObject(obj)) return {};
if (Array.isArray(prop)) {
prop = utils.flatten(prop).join('.');
while (obj && (++i < len)) {
var key = segs[i];
while (key[key.length - 1] === '\\') {
key = key.slice(0, -1) + '.' + segs[++i];
}
obj = obj[key];
}
return obj;
};
if (typeof prop !== 'string') return obj;
var path;
if (fn && typeof fn === 'function') {
path = fn(prop);
} else if (fn === true) {
path = escapePath(prop);
} else {
path = prop.split(/[[.\]]/).filter(Boolean);
function toSegments(val) {
if (Array.isArray(val)) {
return val;
}
var len = path.length, i = -1;
var last = null;
while(++i < len) {
var key = path[i];
last = obj[key];
if (!last) { return last; }
if (utils.isObject(obj)) {
obj = last;
}
if (typeof val === 'string') {
return val.split('.');
}
return last;
};
function escape(str) {
return str.split('\\.').join(utils.nonchars[0]);
return null;
}
function unescape(str) {
return str.split(utils.nonchars[0]).join('.');
function isObject(val) {
return val !== null && (typeof val === 'object' || typeof val === 'function');
}
function escapePath(str) {
return escape(str).split('.').map(function (seg) {
return unescape(seg);
});
}
{
"name": "get-value",
"description": "Use property paths (`a.b.c`) to get a nested value from an object.",
"version": "1.3.1",
"version": "2.0.0",
"homepage": "https://github.com/jonschlinkert/get-value",

@@ -13,4 +13,3 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",

"files": [
"index.js",
"utils.js"
"index.js"
],

@@ -24,8 +23,2 @@ "main": "index.js",

},
"dependencies": {
"arr-flatten": "^1.0.1",
"is-extendable": "^0.1.1",
"lazy-cache": "^0.2.4",
"noncharacters": "^1.1.0"
},
"devDependencies": {

@@ -35,4 +28,10 @@ "ansi-bold": "^0.1.1",

"benchmarked": "^0.1.4",
"dot-prop": "^2.2.0",
"getobject": "^0.1.0",
"gulp": "^3.9.0",
"gulp-istanbul": "^0.10.2",
"gulp-jshint": "^1.11.2",
"gulp-mocha": "^2.1.3",
"isobject": "^2.0.0",
"jshint-stylish": "^2.0.1",
"matched": "^0.3.2",

@@ -39,0 +38,0 @@ "minimist": "^1.2.0",

@@ -5,22 +5,2 @@ # get-value [![NPM version](https://badge.fury.io/js/get-value.svg)](http://badge.fury.io/js/get-value) [![Build Status](https://travis-ci.org/jonschlinkert/get-value.svg)](https://travis-ci.org/jonschlinkert/get-value)

**[Benchmarks](./benchmark)**
This is 10x faster and more performant than [dot-prop](https://github.com/sindresorhus/dot-prop), and it passes all of the dot-prop tests.
Of the libs benchmarked, _dot-prop was the least performant_:
```bash
#1: deep
get-value x 3,308,335 ops/sec ±1.32% (94 runs sampled)
dot-prop x 197,631 ops/sec ±1.27% (94 runs sampled)
getobject x 218,635 ops/sec ±1.51% (91 runs sampled)
#2: shallow
get-value x 5,762,976 ops/sec ±1.21% (95 runs sampled)
dot-prop x 695,892 ops/sec ±1.42% (95 runs sampled)
getobject x 724,493 ops/sec ±1.46% (93 runs sampled)
```
Also, get-value supports escaping dots in paths, which is common when object keys are file paths with extensions, dot-prop does not.
## Install

@@ -100,2 +80,2 @@

_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on October 28, 2015._
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on October 29, 2015._
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