pax_global_header00006660000000000000000000000064132476741770014534gustar00rootroot0000000000000052 comment=24c621df185834781548f69312cf5609aab48b26 get-value-3.0.1/000077500000000000000000000000001324767417700134265ustar00rootroot00000000000000get-value-3.0.1/.editorconfig000066400000000000000000000004411324767417700161020ustar00rootroot00000000000000# http://editorconfig.org/ root = true [*] charset = utf-8 end_of_line = lf indent_size = 2 indent_style = space insert_final_newline = true trim_trailing_whitespace = true [{**/{actual,fixtures,expected,templates}/**,*.md}] trim_trailing_whitespace = false insert_final_newline = false get-value-3.0.1/.eslintrc.json000066400000000000000000000067751324767417700162410ustar00rootroot00000000000000{ "env": { "browser": false, "es6": true, "node": true, "mocha": true }, "globals": { "document": false, "navigator": false, "window": false }, "rules": { "accessor-pairs": 2, "arrow-spacing": [2, { "before": true, "after": true }], "block-spacing": [2, "always"], "brace-style": [2, "1tbs", { "allowSingleLine": true }], "comma-dangle": [2, "never"], "comma-spacing": [2, { "before": false, "after": true }], "comma-style": [2, "last"], "constructor-super": 2, "curly": [2, "multi-line"], "dot-location": [2, "property"], "eol-last": 2, "eqeqeq": [2, "allow-null"], "generator-star-spacing": [2, { "before": true, "after": true }], "handle-callback-err": [2, "^(err|error)$" ], "indent": [2, 2, { "SwitchCase": 1 }], "key-spacing": [2, { "beforeColon": false, "afterColon": true }], "keyword-spacing": [2, { "before": true, "after": true }], "new-cap": [2, { "newIsCap": true, "capIsNew": false }], "new-parens": 2, "no-array-constructor": 2, "no-caller": 2, "no-class-assign": 2, "no-cond-assign": 2, "no-const-assign": 2, "no-control-regex": 2, "no-debugger": 2, "no-delete-var": 2, "no-dupe-args": 2, "no-dupe-class-members": 2, "no-dupe-keys": 2, "no-duplicate-case": 2, "no-empty-character-class": 2, "no-eval": 2, "no-ex-assign": 2, "no-extend-native": 2, "no-extra-bind": 2, "no-extra-boolean-cast": 2, "no-extra-parens": [2, "functions"], "no-fallthrough": 2, "no-floating-decimal": 2, "no-func-assign": 2, "no-implied-eval": 2, "no-inner-declarations": [2, "functions"], "no-invalid-regexp": 2, "no-irregular-whitespace": 2, "no-iterator": 2, "no-label-var": 2, "no-labels": 2, "no-lone-blocks": 2, "no-mixed-spaces-and-tabs": 2, "no-multi-spaces": 2, "no-multi-str": 2, "no-multiple-empty-lines": [2, { "max": 1 }], "no-native-reassign": 0, "no-negated-in-lhs": 2, "no-new": 2, "no-new-func": 2, "no-new-object": 2, "no-new-require": 2, "no-new-wrappers": 2, "no-obj-calls": 2, "no-octal": 2, "no-octal-escape": 2, "no-proto": 0, "no-redeclare": 2, "no-regex-spaces": 2, "no-return-assign": 2, "no-self-compare": 2, "no-sequences": 2, "no-shadow-restricted-names": 2, "no-spaced-func": 2, "no-sparse-arrays": 2, "no-this-before-super": 2, "no-throw-literal": 2, "no-trailing-spaces": 0, "no-undef": 2, "no-undef-init": 2, "no-unexpected-multiline": 2, "no-unneeded-ternary": [2, { "defaultAssignment": false }], "no-unreachable": 2, "no-unused-vars": [2, { "vars": "all", "args": "none" }], "no-useless-call": 0, "no-with": 2, "one-var": [0, { "initialized": "never" }], "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }], "padded-blocks": [0, "never"], "quotes": [2, "single", "avoid-escape"], "radix": 2, "semi": [2, "always"], "semi-spacing": [2, { "before": false, "after": true }], "space-before-blocks": [2, "always"], "space-before-function-paren": [2, "never"], "space-in-parens": [2, "never"], "space-infix-ops": 2, "space-unary-ops": [2, { "words": true, "nonwords": false }], "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }], "use-isnan": 2, "valid-typeof": 2, "wrap-iife": [2, "any"], "yoda": [2, "never"] } } get-value-3.0.1/.gitattributes000066400000000000000000000001771324767417700163260ustar00rootroot00000000000000# Enforce Unix newlines * text eol=lf # binaries *.ai binary *.psd binary *.jpg binary *.gif binary *.png binary *.jpeg binaryget-value-3.0.1/.gitignore000066400000000000000000000004561324767417700154230ustar00rootroot00000000000000# always ignore files *.DS_Store .idea .vscode *.sublime-* # test related, or directories generated by tests test/actual actual coverage .nyc* # npm node_modules npm-debug.log # yarn yarn.lock yarn-error.log # misc _gh_pages _draft _drafts bower_components vendor temp tmp TODO.md package-lock.jsonget-value-3.0.1/.travis.yml000066400000000000000000000003731324767417700155420ustar00rootroot00000000000000sudo: false os: - linux - osx language: node_js node_js: - node - '9' - '8' - '7' - '6' matrix: fast_finish: true allow_failures: - node_js: '5' - node_js: '4' - node_js: '0.8' - node_js: '0.12' - node_js: '0.10' get-value-3.0.1/.verb.md000066400000000000000000000140211324767417700147620ustar00rootroot00000000000000## Usage See the [unit tests](test/test.js) for many more examples. ```js const get = require('get-value'); const obj = { a: { b: { c: { d: 'foo' } } } }; console.log(get(obj)); //=> { a: { b: { c: { d: 'foo' } } } }; console.log(get(obj, 'a')); //=> { b: { c: { d: 'foo' } } } console.log(get(obj, 'a.b')); //=> { c: { d: 'foo' } } console.log(get(obj, 'a.b.c')); //=> { d: 'foo' } console.log(get(obj, 'a.b.c.d')); //=> 'foo' ``` ### Supports keys with dots Unlike other dot-prop libraries, get-value works when keys have dots in them: ```js console.log(get({ 'a.b': { c: 'd' } }, 'a.b.c')); //=> 'd' console.log(get({ 'a.b': { c: { 'd.e': 'f' } } }, 'a.b.c.d.e')); //=> 'f' ``` ### Supports arrays ```js console.log(get({ a: { b: { c: { d: 'foo' } } }, e: [{ f: 'g' }, { f: 'h' }] }, 'e.1.f')); //=> 'h' console.log(get({ a: { b: [{ c: 'd' }] } }, 'a.b.0.c')); //=> 'f' console.log(get({ a: { b: [{ c: 'd' }, { e: 'f' }] } }, 'a.b.1.e')); //=> 'f' ``` ### Supports functions ```js function foo() {} foo.bar = { baz: 'qux' }; console.log(get(foo)); //=> { [Function: foo] bar: { baz: 'qux' } } console.log(get(foo, 'bar')); //=> { baz: 'qux' } console.log(get(foo, 'bar.baz')); //=> qux ``` ### Supports passing object path as an array Slighly improve performance by passing an array of strings to use as object path segments (this is also useful when you need to dynamically build up the path segments): ```js console.log(get({ a: { b: 'c' } }, ['a', 'b'])); //=> 'c' ``` ## Options ### options.default **Type**: `any` **Default**: `undefined` The default value to return when get-value cannot resolve a value from the given object. ```js const obj = { foo: { a: { b: { c: { d: 'e' } } } } }; console.log(get(obj, 'foo.a.b.c.d', { default: true })); //=> 'e' console.log(get(obj, 'foo.bar.baz', { default: true })); //=> true console.log(get(obj, 'foo.bar.baz', { default: false })); //=> false console.log(get(obj, 'foo.bar.baz', { default: null })); //=> null // you can also pass the default value as the last argument // (this is necessary if the default value is an object) console.log(get(obj, 'foo.a.b.c.d', true)); //=> 'e' console.log(get(obj, 'foo.bar.baz', true)); //=> true console.log(get(obj, 'foo.bar.baz', false)); //=> false console.log(get(obj, 'foo.bar.baz', null)); //=> null ``` ### options.isValid **Type**: `function` **Default**: `true` If defined, this function is called on each resolved value. Useful if you want to do `.hasOwnProperty` or `Object.prototype.propertyIsEnumerable`. ```js const isEnumerable = Object.prototype.propertyIsEnumerable; const options = { isValid: (key, obj) => isEnumerable.call(obj, key) }; const obj = {}; Object.defineProperty(obj, 'foo', { value: 'bar', enumerable: false }); console.log(get(obj, 'foo', options)); //=> undefined console.log(get({}, 'hasOwnProperty', options)); //=> undefined console.log(get({}, 'constructor', options)); //=> undefined // without "isValid" check console.log(get(obj, 'foo', options)); //=> bar console.log(get({}, 'hasOwnProperty', options)); //=> [Function: hasOwnProperty] console.log(get({}, 'constructor', options)); //=> [Function: Object] ``` ### options.split **Type**: `function` **Default**: `String.split()` Custom function to use for splitting the string into object path segments. ```js const obj = { 'a.b': { c: { d: 'e' } } }; // example of using a string to split the object path const options = { split: path => path.split('/') }; console.log(get(obj, 'a.b/c/d', options)); //=> 'e' // example of using a regex to split the object path // (removing escaped dots is unnecessary, this is just an example) const options = { split: path => path.split(/\\?\./) }; console.log(get(obj, 'a\\.b.c.d', options)); //=> 'e' ``` ### options.separator **Type**: `string|regex` **Default**: `.` The separator to use for spliting the string (this is probably not needed when `options.split` is used). ```js const obj = { 'a.b': { c: { d: 'e' } } }; console.log(get(obj, 'a.b/c/d', { separator: '/' })); //=> 'e' console.log(get(obj, 'a\\.b.c.d', { separator: /\\?\./ })); //=> 'e' ``` ### options.join **Type**: `function` **Default**: `Array.join()` Customize how the object path is created when iterating over path segments. ```js const obj = { 'a/b': { c: { d: 'e' } } }; const options = { // when segs === ['a', 'b'] use a "/" to join, otherwise use a "." join: segs => segs.join(segs[0] === 'a' ? '/' : '.') }; console.log(get(obj, 'a.b.c.d', options)); //=> 'e' ``` ### options.joinChar **Type**: `string` **Default**: `.` The character to use when re-joining the string to check for keys with dots in them (this is probably not needed when `options.join` is used). This can be a different value than the separator, since the separator can be a string or regex. ```js const target = { 'a-b': { c: { d: 'e' } } }; const options = { joinChar: '-' }; console.log(get(target, 'a.b.c.d', options)); //=> 'e' ``` ## Benchmarks _(benchmarks were run on a MacBook Pro 2.5 GHz Intel Core i7, 16 GB 1600 MHz DDR3)_. get-value is more reliable and has more features than dot-prop, without sacrificing performance. ``` {%= include("./benchmark/stats.md") %} ``` ### Running the benchmarks Clone this library into a local directory: ```sh $ git clone https://github.com/jonschlinkert/get-value.git ``` Then install devDependencies and run benchmarks: ```sh $ npm install && node benchmark ``` ## Release history ### v3.0.0 - Improved support for escaping. It's no longer necessary to use backslashes to escape keys. - Adds `options.default` for defining a default value to return when no value is resolved. - Adds `options.isValid` to allow the user to check the object after each iteration. - Adds `options.separator` for customizing character to split on. - Adds `options.split` for customizing how the object path is split. - Adds `options.join` for customizing how the object path is joined when iterating over path segments. - Adds `options.joinChar` for customizing the join character. get-value-3.0.1/LICENSE000066400000000000000000000021001324767417700144240ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2014-2018, Jon Schlinkert. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. get-value-3.0.1/README.md000066400000000000000000000266331324767417700147170ustar00rootroot00000000000000# get-value [![NPM version](https://img.shields.io/npm/v/get-value.svg?style=flat)](https://www.npmjs.com/package/get-value) [![NPM monthly downloads](https://img.shields.io/npm/dm/get-value.svg?style=flat)](https://npmjs.org/package/get-value) [![NPM total downloads](https://img.shields.io/npm/dt/get-value.svg?style=flat)](https://npmjs.org/package/get-value) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/get-value.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/get-value) > 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!). Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support. ## Table of Contents
Details - [Install](#install) - [Usage](#usage) * [Supports keys with dots](#supports-keys-with-dots) * [Supports arrays](#supports-arrays) * [Supports functions](#supports-functions) * [Supports passing object path as an array](#supports-passing-object-path-as-an-array) - [Options](#options) * [options.default](#optionsdefault) * [options.isValid](#optionsisvalid) * [options.split](#optionssplit) * [options.separator](#optionsseparator) * [options.join](#optionsjoin) * [options.joinChar](#optionsjoinchar) - [Benchmarks](#benchmarks) * [Running the benchmarks](#running-the-benchmarks) - [Release history](#release-history) * [v3.0.0](#v300) - [About](#about)
## Install Install with [npm](https://www.npmjs.com/): ```sh $ npm install --save get-value ``` ## Usage See the [unit tests](test/test.js) for many more examples. ```js const get = require('foo'); const obj = { a: { b: { c: { d: 'foo' } } } }; console.log(get(obj)); //=> { a: { b: { c: { d: 'foo' } } } }; console.log(get(obj, 'a')); //=> { b: { c: { d: 'foo' } } } console.log(get(obj, 'a.b')); //=> { c: { d: 'foo' } } console.log(get(obj, 'a.b.c')); //=> { d: 'foo' } console.log(get(obj, 'a.b.c.d')); //=> 'foo' ``` ### Supports keys with dots Unlike other dot-prop libraries, get-value works when keys have dots in them: ```js console.log(get({ 'a.b': { c: 'd' } }, 'a.b.c')); //=> 'd' console.log(get({ 'a.b': { c: { 'd.e': 'f' } } }, 'a.b.c.d.e')); //=> 'f' ``` ### Supports arrays ```js console.log(get({ a: { b: { c: { d: 'foo' } } }, e: [{ f: 'g' }, { f: 'h' }] }, 'e.1.f')); //=> 'h' console.log(get({ a: { b: [{ c: 'd' }] } }, 'a.b.0.c')); //=> 'f' console.log(get({ a: { b: [{ c: 'd' }, { e: 'f' }] } }, 'a.b.1.e')); //=> 'f' ``` ### Supports functions ```js function foo() {} foo.bar = { baz: 'qux' }; console.log(get(foo)); //=> { [Function: foo] bar: { baz: 'qux' } } console.log(get(foo, 'bar')); //=> { baz: 'qux' } console.log(get(foo, 'bar.baz')); //=> qux ``` ### Supports passing object path as an array Slighly improve performance by passing an array of strings to use as object path segments (this is also useful when you need to dynamically build up the path segments): ```js console.log(get({ a: { b: 'c' } }, ['a', 'b'])); //=> 'c' ``` ## Options ### options.default **Type**: `any` **Default**: `undefined` The default value to return when get-value cannot resolve a value from the given object. ```js const obj = { foo: { a: { b: { c: { d: 'e' } } } } }; console.log(get(obj, 'foo.a.b.c.d', { default: true })); //=> 'e' console.log(get(obj, 'foo.bar.baz', { default: true })); //=> true console.log(get(obj, 'foo.bar.baz', { default: false })); //=> false console.log(get(obj, 'foo.bar.baz', { default: null })); //=> null // you can also pass the default value as the last argument // (this is necessary if the default value is an object) console.log(get(obj, 'foo.a.b.c.d', true)); //=> 'e' console.log(get(obj, 'foo.bar.baz', true)); //=> true console.log(get(obj, 'foo.bar.baz', false)); //=> false console.log(get(obj, 'foo.bar.baz', null)); //=> null ``` ### options.isValid **Type**: `function` **Default**: `true` If defined, this function is called on each resolved value. Useful if you want to do `.hasOwnProperty` or `Object.prototype.propertyIsEnumerable`. ```js const isEnumerable = Object.prototype.propertyIsEnumerable; const options = { isValid: (key, obj) => isEnumerable.call(obj, key) }; const obj = {}; Object.defineProperty(obj, 'foo', { value: 'bar', enumerable: false }); console.log(get(obj, 'foo', options)); //=> undefined console.log(get({}, 'hasOwnProperty', options)); //=> undefined console.log(get({}, 'constructor', options)); //=> undefined // without "isValid" check console.log(get(obj, 'foo', options)); //=> bar console.log(get({}, 'hasOwnProperty', options)); //=> [Function: hasOwnProperty] console.log(get({}, 'constructor', options)); //=> [Function: Object] ``` ### options.split **Type**: `function` **Default**: `String.split()` Custom function to use for splitting the string into object path segments. ```js const obj = { 'a.b': { c: { d: 'e' } } }; // example of using a string to split the object path const options = { split: path => path.split('/') }; console.log(get(obj, 'a.b/c/d', options)); //=> 'e' // example of using a regex to split the object path // (removing escaped dots is unnecessary, this is just an example) const options = { split: path => path.split(/\\?\./) }; console.log(get(obj, 'a\\.b.c.d', options)); //=> 'e' ``` ### options.separator **Type**: `string|regex` **Default**: `.` The separator to use for spliting the string (this is probably not needed when `options.split` is used). ```js const obj = { 'a.b': { c: { d: 'e' } } }; console.log(get(obj, 'a.b/c/d', { separator: '/' })); //=> 'e' console.log(get(obj, 'a\\.b.c.d', { separator: /\\?\./ })); //=> 'e' ``` ### options.join **Type**: `function` **Default**: `Array.join()` Customize how the object path is created when iterating over path segments. ```js const obj = { 'a/b': { c: { d: 'e' } } }; const options = { // when segs === ['a', 'b'] use a "/" to join, otherwise use a "." join: segs => segs.join(segs[0] === 'a' ? '/' : '.') }; console.log(get(obj, 'a.b.c.d', options)); //=> 'e' ``` ### options.joinChar **Type**: `string` **Default**: `.` The character to use when re-joining the string to check for keys with dots in them (this is probably not needed when `options.join` is used). This can be a different value than the separator, since the separator can be a string or regex. ```js const target = { 'a-b': { c: { d: 'e' } } }; const options = { joinChar: '-' }; console.log(get(target, 'a.b.c.d', options)); //=> 'e' ``` ## Benchmarks _(benchmarks were run on a MacBook Pro 2.5 GHz Intel Core i7, 16 GB 1600 MHz DDR3)_. get-value is more reliable and has more features than dot-prop, without sacrificing performance. ``` # deep (175 bytes) dot-prop x 883,166 ops/sec ±0.93% (86 runs sampled) get-value x 1,448,928 ops/sec ±1.53% (87 runs sampled) getobject x 213,797 ops/sec ±0.85% (90 runs sampled) object-path x 184,347 ops/sec ±2.48% (85 runs sampled) fastest is get-value (by 339% avg) # root (210 bytes) dot-prop x 3,905,828 ops/sec ±1.36% (87 runs sampled) get-value x 16,391,934 ops/sec ±1.43% (83 runs sampled) getobject x 1,200,021 ops/sec ±1.81% (88 runs sampled) object-path x 2,788,494 ops/sec ±1.81% (86 runs sampled) fastest is get-value (by 623% avg) # shallow (84 bytes) dot-prop x 2,553,558 ops/sec ±0.89% (89 runs sampled) get-value x 3,070,159 ops/sec ±0.88% (90 runs sampled) getobject x 726,670 ops/sec ±0.81% (86 runs sampled) object-path x 922,351 ops/sec ±2.05% (86 runs sampled) fastest is get-value (by 219% avg) ``` ### Running the benchmarks Clone this library into a local directory: ```sh $ git clone https://github.com/jonschlinkert/get-value.git ``` Then install devDependencies and run benchmarks: ```sh $ npm install && node benchmark ``` ## Release history ### v3.0.0 * Improved support for escaping. It's no longer necessary to use backslashes to escape keys. * Adds `options.default` for defining a default value to return when no value is resolved. * Adds `options.isValid` to allow the user to check the object after each iteration. * Adds `options.separator` for customizing character to split on. * Adds `options.split` for customizing how the object path is split. * Adds `options.join` for customizing how the object path is joined when iterating over path segments. * Adds `options.joinChar` for customizing the join character. ## About
Contributing Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
Running Tests Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: ```sh $ npm install && npm test ```
Building docs _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_ To generate the readme, run the following command: ```sh $ npm install -g verbose/verb#dev verb-generate-readme && verb ```
### Related projects You might also be interested in these projects: * [has-any-deep](https://www.npmjs.com/package/has-any-deep): Return true if `key` exists deeply on the given object. | [homepage](https://github.com/jonschlinkert/has-any-deep "Return true if `key` exists deeply on the given object. ") * [has-any](https://www.npmjs.com/package/has-any): Returns true if an object has any of the specified keys. | [homepage](https://github.com/jonschlinkert/has-any "Returns true if an object has any of the specified keys.") * [has-value](https://www.npmjs.com/package/has-value): Returns true if a value exists, false if empty. Works with deeply nested values using… [more](https://github.com/jonschlinkert/has-value) | [homepage](https://github.com/jonschlinkert/has-value "Returns true if a value exists, false if empty. Works with deeply nested values using object paths.") * [set-value](https://www.npmjs.com/package/set-value): Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths. | [homepage](https://github.com/jonschlinkert/set-value "Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths.") * [unset-value](https://www.npmjs.com/package/unset-value): Delete nested properties from an object using dot notation. | [homepage](https://github.com/jonschlinkert/unset-value "Delete nested properties from an object using dot notation.") ### Contributors | **Commits** | **Contributor** | | --- | --- | | 81 | [jonschlinkert](https://github.com/jonschlinkert) | | 2 | [ianwalter](https://github.com/ianwalter) | | 1 | [doowb](https://github.com/doowb) | ### Author **Jon Schlinkert** * [LinkedIn Profile](https://linkedin.com/in/jonschlinkert) * [GitHub Profile](https://github.com/jonschlinkert) * [Twitter Profile](https://twitter.com/jonschlinkert) ### License Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert). Released under the [MIT License](LICENSE). *** _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on March 07, 2018._get-value-3.0.1/benchmark/000077500000000000000000000000001324767417700153605ustar00rootroot00000000000000get-value-3.0.1/benchmark/code/000077500000000000000000000000001324767417700162725ustar00rootroot00000000000000get-value-3.0.1/benchmark/code/for-path-escape-check.js000066400000000000000000000017101324767417700226600ustar00rootroot00000000000000var isObject = require('isobject'); module.exports = function getValue(o, prop) { if (o == null || !isObject(o)) { return {}; } if (prop == null || typeof prop !== 'string') { return o; } var path; if (prop.indexOf('\\.') !== -1) { prop = replaceStr(prop, '\\.', '___DOT___'); path = prop.split('.').map(function(seg) { return replaceStr(seg, '___DOT___', '.'); }); } else { path = prop.split('.'); } var last = path.pop(); var len = path.length; for (var i = 0; i < len; i++) { var key = path[i]; o = o[key]; if (o == null) { return {}; } } return o[last]; }; function replaceStr(str, pattern, replacement) { var i, from = 0; while (str.indexOf(pattern, from) !== -1) { i = str.indexOf(pattern, from); from = i + pattern.length; str = str.substr(0, i) + replacement + str.substr(from, str.length); from = i + replacement.length; } return str; } get-value-3.0.1/benchmark/code/for-path-escape-flag.js000066400000000000000000000017041324767417700225170ustar00rootroot00000000000000var isObject = require('isobject'); module.exports = function getValue(o, prop, escape) { if (o == null || !isObject(o)) { return {}; } if (prop == null || typeof prop !== 'string') { return o; } var path; if (escape === true) { prop = replaceStr(prop, '\\.', '___DOT___'); path = prop.split('.').map(function(seg) { return replaceStr(seg, '___DOT___', '.'); }); } else { path = prop.split('.'); } var last = path.pop(); var len = path.length; for (var i = 0; i < len; i++) { var key = path[i]; o = o[key]; if (o == null) { return {}; } } return o[last]; }; function replaceStr(str, pattern, replacement) { var i, from = 0; while (str.indexOf(pattern, from) !== -1) { i = str.indexOf(pattern, from); from = i + pattern.length; str = str.substr(0, i) + replacement + str.substr(from, str.length); from = i + replacement.length; } return str; } get-value-3.0.1/benchmark/code/for-path-escape.js000066400000000000000000000015501324767417700216070ustar00rootroot00000000000000 var isObject = require('isobject'); module.exports = function getValue(o, prop) { if (o == null || !isObject(o)) { return {}; } if (prop == null || typeof prop !== 'string') { return o; } prop = replaceStr(prop, '\\.', '___DOT___'); var path = prop.split('.').map(function(seg) { return replaceStr(seg, '___DOT___', '.'); }); var last = path.pop(); var len = path.length; for (var i = 0; i < len; i++) { var key = path[i]; o = o[key]; if (o == null) { return {}; } } return o[last]; }; function replaceStr(str, pattern, replacement) { var i, from = 0; while (str.indexOf(pattern, from) !== -1) { i = str.indexOf(pattern, from); from = i + pattern.length; str = str.substr(0, i) + replacement + str.substr(from, str.length); from = i + replacement.length; } return str; } get-value-3.0.1/benchmark/code/for.js000066400000000000000000000006101324767417700174130ustar00rootroot00000000000000 var isObject = require('isobject'); module.exports = function getValue(obj, prop) { if (obj == null) { return {}; } if (typeof prop !== 'string') { return obj; } var path = prop.split('.'); var last = path.pop(); var len = path.length; for (var i = 0; i < len; i++) { obj = obj[path[i]]; if (!isObject(obj)) { return obj; } } return obj[last]; }; get-value-3.0.1/benchmark/code/get-value-fast.js000066400000000000000000000000511324767417700214500ustar00rootroot00000000000000module.exports = require('../../').fast; get-value-3.0.1/benchmark/code/libs/000077500000000000000000000000001324767417700172235ustar00rootroot00000000000000get-value-3.0.1/benchmark/code/libs/dot-prop.js000066400000000000000000000000521324767417700213220ustar00rootroot00000000000000module.exports = require('dot-prop').get; get-value-3.0.1/benchmark/code/libs/get-value.js000066400000000000000000000000461324767417700214520ustar00rootroot00000000000000module.exports = require('../../..'); get-value-3.0.1/benchmark/code/libs/getobject.js000066400000000000000000000001401324767417700215220ustar00rootroot00000000000000/** * https://github.com/cowboy/node-getobject */ module.exports = require('getobject').set; get-value-3.0.1/benchmark/code/libs/object-path.js000066400000000000000000000000551324767417700217610ustar00rootroot00000000000000module.exports = require('object-path').get; get-value-3.0.1/benchmark/code/loop-prop-loop-index.js000066400000000000000000000017251324767417700226400ustar00rootroot00000000000000const isObject = require('isobject'); module.exports = function(target, path, escape) { if (!isObject(target) && !Array.isArray(target)) { return target; } const isArray = Array.isArray(path); const isString = typeof path === 'string'; if (!isString && !isArray) { return target; } if (isString && path in target) { return target[path]; } let segs = isArray ? path : path.split(/\\?\./); let obj = target; let idx = 0; do { let seg = segs[idx]; if (seg in obj) { obj = obj[seg]; continue; } let rest = segs.slice(); let hasProp = false; do { const prop = rest.join('.'); if ((hasProp = (prop in obj))) { segs = segs.slice(rest.length); obj = obj[prop]; --idx; break; } rest.pop(); } while (rest.length); if (!hasProp) { return; } } while ((isObject(obj) || Array.isArray(obj)) && ++idx < segs.length); return obj; }; get-value-3.0.1/benchmark/code/loop-prop-loop.js000066400000000000000000000021021324767417700215210ustar00rootroot00000000000000const isObject = require('isobject'); module.exports = function(target, path) { if (!isObject(target) && !Array.isArray(target)) { return target; } const isArray = Array.isArray(path); const isString = typeof path === 'string'; if (!isString && !isArray) { return target; } if (isString && path in target) { return target[path]; } let segs = isArray ? path : path.split('.'); let obj = target; do { let prop = segs[0]; while (prop && prop.slice(-1) === '\\') { prop = prop.slice(0, -1) + '.' + (segs[1] || ''); segs.shift(); segs[0] = prop; } if (prop in obj) { obj = obj[segs.shift()]; continue; } let rest = segs.slice(); let hasProp = false; do { const prop = rest.join('.'); if ((hasProp = (prop in obj))) { segs = segs.slice(rest.length); obj = obj[prop]; break; } rest.pop(); } while (rest.length); if (!hasProp) { return; } } while (segs.length && (isObject(obj) || Array.isArray(obj))); return obj; }; get-value-3.0.1/benchmark/code/loop-prop-regex.js000066400000000000000000000016251324767417700216730ustar00rootroot00000000000000const isObject = require('isobject'); module.exports = function(target, path) { if (!isObject(target) && !Array.isArray(target)) { return target; } const isArray = Array.isArray(path); const isString = typeof path === 'string'; if (!isString && !isArray) { return target; } if (isString && path in target) { return target[path]; } let segs = isArray ? path : path.split(/\\?\./); let obj = target; while ((isObject(obj) || Array.isArray(obj)) && segs.length) { if (segs[0] in obj) { obj = obj[segs.shift()]; continue; } let rest = segs.slice(); let hasProp = false; do { const prop = rest.join('.'); if ((hasProp = (prop in obj))) { segs = segs.slice(rest.length); obj = obj[prop]; break; } rest.pop(); } while (rest.length); if (!hasProp) { return; } } return obj; }; get-value-3.0.1/benchmark/code/recursive-fn-escape-loop.js000066400000000000000000000021101324767417700234370ustar00rootroot00000000000000const isObject = require('isobject'); module.exports = function(target, path) { if (!isObject(target) && !Array.isArray(target)) { return target; } const isArray = Array.isArray(path); const isString = typeof path === 'string'; if (!isString && !isArray) { return target; } if (isString && path in target) { return target[path]; } let segs = Array.isArray(path) ? path : path.split('.'); let obj = target; function lookup() { if ((isObject(obj) || Array.isArray(obj)) && segs.length) { let prop = segs[0]; while (prop.slice(-1) === '\\') { prop = prop.slice(0, -1) + '.' + segs[1]; segs.shift(); segs[0] = prop; } if (prop in obj) { obj = obj[segs.shift()]; return lookup(); } let rest = segs.slice(); do { prop = rest.join('.'); if (prop in obj) { segs = segs.slice(rest.length); obj = obj[prop]; return lookup(); } } while (rest.pop()); return; } return obj; } return lookup(); }; get-value-3.0.1/benchmark/code/recursive-fn-prop-regex.js000066400000000000000000000020561324767417700233310ustar00rootroot00000000000000const isObject = require('isobject'); const isEnumerable = Object.prototype.propertyIsEnumerable; module.exports = function(target, path) { if (!isObject(target) && !Array.isArray(target)) { return target; } const isArray = Array.isArray(path); const isString = typeof path === 'string'; if (!isString && !isArray) { return target; } if (isString && path in target) { return target[path]; } let segs = Array.isArray(path) ? path : path.split(/\\?\./); let obj = target; function lookup() { if ((isObject(obj) || Array.isArray(obj)) && segs.length) { let prop = segs[0]; if (isEnumerable.call(obj, prop)) { obj = obj[segs.shift()]; return lookup(); } let rest = segs.slice(); do { prop = rest.join('.'); if (isEnumerable.call(obj, prop)) { segs = segs.slice(rest.length); obj = obj[prop]; return lookup(); } rest.pop(); } while (rest.length); return; } return obj; } return lookup(); }; get-value-3.0.1/benchmark/code/recursive-fn.js000066400000000000000000000016761324767417700212520ustar00rootroot00000000000000const isObject = require('isobject'); module.exports = function(target, path) { if (!isObject(target) && !Array.isArray(target)) { return target; } const isArray = Array.isArray(path); const isString = typeof path === 'string'; if (!isString && !isArray) { return target; } if (isString && path in target) { return target[path]; } let segs = Array.isArray(path) ? path : path.split(/\\?\./); let obj = target; function lookup() { if ((isObject(obj) || Array.isArray(obj)) && segs.length) { if (segs[0] in obj) { obj = obj[segs.shift()]; return lookup(); } let rest = segs.slice(); do { const prop = rest.join('.'); if (prop in obj) { segs = segs.slice(rest.length); obj = obj[prop]; return lookup(); } rest.pop(); } while (rest.length); return; } return obj; } return lookup(); }; get-value-3.0.1/benchmark/code/reduce-custom.js000066400000000000000000000003651324767417700214130ustar00rootroot00000000000000 var reduce = require('arr-reduce'); module.exports = function get(obj, path) { if (obj == null) return {}; if (path == null) return obj; return reduce(path.split('.'), function(prev, curr) { return prev && prev[curr]; }, obj); }; get-value-3.0.1/benchmark/code/reduce.js000066400000000000000000000003171324767417700201000ustar00rootroot00000000000000 module.exports = function get(obj, path) { if (obj == null) return {}; if (path == null) return obj; return path.split('.').reduce(function(prev, curr) { return prev && prev[curr]; }, obj); }; get-value-3.0.1/benchmark/code/while-fn-both.js000066400000000000000000000020241324767417700212710ustar00rootroot00000000000000 var isObject = require('isobject'); module.exports = function getValue(obj, str, fn) { if (obj == null || !isObject(obj)) { return {}; } if (str == null || typeof str !== 'string') { return obj; } var path; if (fn && typeof fn === 'function') { path = fn(str); } else if (fn === true) { str = replaceStr(str, '\\.', '___DOT___'); path = str.split('.').map(function(seg) { return replaceStr(seg, '___DOT___', '.'); }); } else { path = str.split('.'); } var len = path.length; var i = 0; var last; while (i < len) { var key = path[i]; last = obj[key]; if (last == null) { return {}; } if (typeof last === 'object') { obj = last; } i++; } return last; }; function replaceStr(str, token, replacement) { var i = str.indexOf(token); var end = i + token.length; str = str.substr(0, i) + replacement + str.substr(end, str.length); if (str.indexOf(token, end) !== -1) { str = str.replace(token, replacement); } return str; } get-value-3.0.1/benchmark/code/while-fn-optional.js000066400000000000000000000011171324767417700221640ustar00rootroot00000000000000 var isObject = require('isobject'); module.exports = function getValue(obj, str, fn) { if (obj == null || !isObject(obj)) { return {}; } if (str == null || typeof str !== 'string') { return obj; } var paths; if (fn && typeof fn === 'function') { paths = fn(str); } else { paths = str.split('.'); } var len = paths.length; var i = 0; var last; while (i < len) { var key = paths[i]; last = obj[key]; if (last == null) { return {}; } if (typeof last === 'object') { obj = last; } i++; } return last; }; get-value-3.0.1/benchmark/code/while-has-own.js000066400000000000000000000007641324767417700213210ustar00rootroot00000000000000 var isObject = require('isobject'); module.exports = function getValue(obj, str) { if (obj == null || !isObject(obj)) { return {}; } if (str == null || typeof str !== 'string') { return obj; } var paths = str.split('.'); var len = paths.length; var i = 0; var last; while (i < len) { var key = paths[i]; if (obj.hasOwnProperty(key)) { last = obj[key]; if (typeof last === 'object') { obj = last; } } i++; } return last; }; get-value-3.0.1/benchmark/code/while-in.js000066400000000000000000000007471324767417700203540ustar00rootroot00000000000000 var isObject = require('isobject'); module.exports = function getValue(obj, str) { if (obj == null || !isObject(obj)) { return {}; } if (str == null || typeof str !== 'string') { return obj; } var paths = str.split('.'); var len = paths.length; var i = 0; var last; while (i < len) { var key = paths[i]; if (key in obj) { last = obj[key]; if (typeof last === 'object') { obj = last; } } i++; } return last; }; get-value-3.0.1/benchmark/code/while-path-escape-check.js000066400000000000000000000011331324767417700232010ustar00rootroot00000000000000 var isObject = require('isobject'); module.exports = function getValue(o, prop) { if (o == null || !isObject(o)) { return {}; } if (prop == null) { return o; } var path; if (/\\\./.test(prop)) { prop = prop.replace(/\\\./g, '___DOT___'); path = prop.split('.').map(function(seg) { return seg.replace(/___DOT___/g, '.'); }); } else { path = prop.split('.'); } var last = path.pop(); var len = path.length; for (var i = 0; i < len; i++) { var key = path[i]; o = o[key]; if (o == null) { return {}; } } return o[last]; }; get-value-3.0.1/benchmark/code/while-path-escape-flag-no-regex.js000066400000000000000000000016501324767417700245630ustar00rootroot00000000000000 var isObject = require('isobject'); module.exports = function getValue(o, prop, escape) { if (o == null || !isObject(o)) { return {}; } if (prop == null) { return o; } var path; if (escape === true) { prop = replaceStr(prop, '\\.', '___DOT___'); path = prop.split('.').map(function(seg) { return replaceStr(seg, '___DOT___', '.'); }); } else { path = prop.split('.'); } var last = path.pop(); var len = path.length; for (var i = 0; i < len; i++) { var key = path[i]; o = o[key]; if (o == null) { return {}; } } return o[last]; }; function replaceStr(str, pattern, replacement) { var i, from = 0; while (str.indexOf(pattern, from) !== -1) { i = str.indexOf(pattern, from); from = i + pattern.length; str = str.substr(0, i) + replacement + str.substr(from, str.length); from = i + replacement.length; } return str; } get-value-3.0.1/benchmark/code/while-path-escape-flag.js000066400000000000000000000011411324767417700230340ustar00rootroot00000000000000 var isObject = require('isobject'); module.exports = function getValue(o, prop, escape) { if (o == null || !isObject(o)) { return {}; } if (prop == null) { return o; } var path; if (escape === true) { prop = prop.replace(/\\\./g, '___DOT___'); path = prop.split('.').map(function(seg) { return seg.replace(/___DOT___/g, '.'); }); } else { path = prop.split('.'); } var last = path.pop(); var len = path.length; for (var i = 0; i < len; i++) { var key = path[i]; o = o[key]; if (o == null) { return {}; } } return o[last]; }; get-value-3.0.1/benchmark/code/while-path-escape-no-regex.js000066400000000000000000000015141324767417700236530ustar00rootroot00000000000000 var isObject = require('isobject'); module.exports = function getValue(o, prop) { if (o == null || !isObject(o)) { return {}; } if (prop == null) { return o; } prop = replaceStr(prop, '\\.', '___DOT___'); var path = prop.split('.').map(function(seg) { return replaceStr(seg, '___DOT___', '.'); }); var last = path.pop(); var len = path.length; for (var i = 0; i < len; i++) { var key = path[i]; o = o[key]; if (o == null) { return {}; } } return o[last]; }; function replaceStr(str, pattern, replacement) { var i, from = 0; while (str.indexOf(pattern, from) !== -1) { i = str.indexOf(pattern, from); from = i + pattern.length; str = str.substr(0, i) + replacement + str.substr(from, str.length); from = i + replacement.length; } return str; } get-value-3.0.1/benchmark/code/while-path-escape.js000066400000000000000000000010051324767417700221240ustar00rootroot00000000000000 var isObject = require('isobject'); module.exports = function getValue(o, prop) { if (o == null || !isObject(o)) { return {}; } if (prop == null) { return o; } prop = prop.replace(/\\\./g, '___DOT___'); var path = prop.split('.').map(function(seg) { return seg.replace(/___DOT___/g, '.'); }); var last = path.pop(); var len = path.length; for (var i = 0; i < len; i++) { var key = path[i]; o = o[key]; if (o == null) { return {}; } } return o[last]; }; get-value-3.0.1/benchmark/code/while-path-fn.js000066400000000000000000000007501324767417700212750ustar00rootroot00000000000000 var isObject = require('isobject'); module.exports = function getValue(o, prop, cb) { if (o == null || !isObject(o)) { return {}; } if (prop == null) { return o; } cb = typeof cb === 'function' ? cb : function(str) { return str.split('.'); }; var path = cb(prop); var last = path.pop(); var len = path.length; for (var i = 0; i < len; i++) { var key = path[i]; o = o[key]; if (o == null) { return {}; } } return o[last]; }; get-value-3.0.1/benchmark/code/while.js000066400000000000000000000005051324767417700177400ustar00rootroot00000000000000 module.exports = getValue; function getValue(o, prop) { if (o == null) { return {}; } if (typeof prop !== 'string') { return o; } var path = prop.split('.'); var last = path.pop(); var len = path.length; var i = 0; while (len--) { o = o[path[i++]]; if (!o) return o; } return o[last]; }; get-value-3.0.1/benchmark/fixtures/000077500000000000000000000000001324767417700172315ustar00rootroot00000000000000get-value-3.0.1/benchmark/fixtures/deep.js000066400000000000000000000002571324767417700205100ustar00rootroot00000000000000/** * Deeply nested values */ module.exports = [{a: {b: {c: {d: {e: {f: {g: {h: {i: {j: {k: {l: {m: {n: {o: 'LAST VALUE!'}}}}}}}}}}}}}}}, 'a.b.c.d.e.f.g.h.i.j.k.l.m.n.o']; get-value-3.0.1/benchmark/fixtures/escaped.js000066400000000000000000000002251324767417700211720ustar00rootroot00000000000000/** * Escaped dots. Some of the fns will fail on this. */ module.exports = [{'a.b.c': {d: {e: {f: {g: 'success'}}}}}, 'a\\.b\\.c.d.e.f.g', true]; get-value-3.0.1/benchmark/fixtures/root.js000066400000000000000000000003221324767417700205470ustar00rootroot00000000000000/** * Deeply nested values */ module.exports = [{ a: 'A', b: 'B', c: 'C', d: 'D', e: 'E', f: 'F', g: 'G', h: 'H', i: 'I', j: 'J', k: 'K', l: {i: {k: 'L'}}, m: 'M', n: 'N' }, 'l'];get-value-3.0.1/benchmark/fixtures/shallow.js000066400000000000000000000001241324767417700212350ustar00rootroot00000000000000/** * Deeply nested values */ module.exports = [{x: {y: {z: 'foooo'}}}, 'x.y.z'];get-value-3.0.1/benchmark/index.js000066400000000000000000000006271324767417700170320ustar00rootroot00000000000000'use strict'; const path = require('path'); const bench = require('benchmarked'); const write = require('write'); bench.run({fixtures: 'fixtures/{deep,root,shallow}.js', code: 'code/libs/*.js'}) .then(function(stats) { write.sync(path.join(__dirname, 'stats.json'), JSON.stringify(stats, null, 2)) write.sync(path.join(__dirname, 'stats.md'), bench.render(stats)); }) .catch(console.error); get-value-3.0.1/benchmark/stats.json000066400000000000000000002002001324767417700174030ustar00rootroot00000000000000[ { "name": "deep", "file": { "stat": null, "_contents": null, "history": [ "/Users/jonschlinkert/dev/js-utils/objects/get-value/benchmark/fixtures/deep.js" ], "_cwd": "/Users/jonschlinkert/dev/js-utils/objects/get-value", "_isVinyl": true, "_symlink": null, "key": "deep", "content": [ { "a": { "b": { "c": { "d": { "e": { "f": { "g": { "h": { "i": { "j": { "k": { "l": { "m": { "n": {} } } } } } } } } } } } } } }, "a.b.c.d.e.f.g.h.i.j.k.l.m.n.o" ], "bytes": "(175 bytes)", "suite": { "0": { "name": "dot-prop", "options": { "async": false, "defer": false, "delay": 0.005, "initCount": 1, "maxTime": 5, "minSamples": 5, "minTime": 0.05 }, "async": false, "defer": false, "delay": 0.005, "initCount": 1, "maxTime": 5, "minSamples": 5, "minTime": 0.05, "events": { "abort": [ null ], "complete": [ null ], "cycle": [ null ], "error": [ null ] }, "id": 1, "stats": { "moe": 1.0544115967923902e-8, "rme": 0.9312204166276381, "sem": 5.379651004042807e-9, "deviation": 4.9888831050403404e-8, "mean": 0.0000011322900335571271, "sample": [ 0.0000012718052703094024, 0.0000012093247945113938, 0.000001152774597375983, 0.0000011621844966904495, 0.000001086466410212327, 0.000001175188945241984, 0.0000012028490501160492, 0.0000011484656834455487, 0.000001216860681842471, 0.0000011412587581489794, 0.0000010630211020176305, 0.0000011342484694199575, 0.0000011214515789695146, 0.000001116593444278471, 0.0000011594300561738654, 0.0000011635041131051313, 0.0000011079358523910711, 0.0000010722776714144453, 0.000001087204603311523, 0.0000011026626664715351, 0.0000010989549272349272, 0.000001116796819126819, 0.0000011692560083160084, 0.000001097718711018711, 0.0000011750079417879417, 0.000001085760997920998, 0.0000011092300207900208, 0.0000011059019126819126, 0.000001083578627858628, 0.0000011385441164241165, 0.000001041818503118503, 0.000001075708399168399, 0.0000011226169854469854, 0.0000011668906652806653, 0.0000010556635550935552, 0.000001103339896049896, 0.0000011895545738045738, 0.0000011656771725571725, 0.0000011886272972972973, 0.0000011341500207900207, 0.0000011410091060291061, 0.0000011860243243243244, 0.0000012243833264033265, 0.0000011722451975051975, 0.0000012119272765072766, 0.0000010544976507276506, 0.0000011619861954261955, 0.0000012015573804573805, 0.0000011176579417879417, 0.0000011035213721413723, 0.0000012026829937629937, 0.000001131677027027027, 0.0000011159613097713098, 0.0000010695280873180874, 0.0000010542943451143451, 0.0000011451016216216217, 0.0000012258720166320165, 0.0000011221829729729729, 0.0000011703533056133056, 0.0000011227406444906444, 0.000001180626923076923, 0.000001147100893970894, 0.0000011498013513513513, 0.000001121387525987526, 0.0000010601792931392933, 0.0000010608756548856548, 0.0000010874835966735968, 0.0000011204259875259876, 0.0000010585026195426195, 0.0000011370509979209979, 0.0000011415584823284823, 0.0000011658254677754676, 0.0000011112087525987526, 0.0000010633537214137214, 0.0000012348819542619543, 0.0000011418314137214137, 0.0000011086174636174635, 0.0000011215029313929313, 0.0000011695037837837838, 0.0000010484917463617463, 0.0000010702541661471969, 0.0000011313097909653825, 0.0000011429603956281428, 0.0000011734309936416905, 0.0000011106596434359806, 0.0000010626078419149732 ], "variance": 2.488895463575695e-15 }, "times": { "cycle": 0.0544925901549703, "elapsed": 5.572, "period": 0.0000011322900335571271, "timeStamp": 1520399983855 }, "running": false, "count": 48126, "cycles": 7, "hz": 883165.9472074186 }, "1": { "name": "get-value", "options": { "async": false, "defer": false, "delay": 0.005, "initCount": 1, "maxTime": 5, "minSamples": 5, "minTime": 0.05 }, "async": false, "defer": false, "delay": 0.005, "initCount": 1, "maxTime": 5, "minSamples": 5, "minTime": 0.05, "events": { "abort": [ null ], "complete": [ null ], "cycle": [ null ], "error": [ null ] }, "id": 2, "stats": { "moe": 1.0555427754193995e-8, "rme": 1.5294049759907062, "sem": 5.385422323568365e-9, "deviation": 5.023187537288846e-8, "mean": 6.901656474183028e-7, "sample": [ 6.820895971600555e-7, 7.08544618747589e-7, 6.771623505207663e-7, 6.754013244181561e-7, 8.55399871415713e-7, 9.952610261026103e-7, 6.597315931593159e-7, 6.865505464832197e-7, 7.445285842870001e-7, 6.550293686511509e-7, 6.449817208696319e-7, 6.89127928365225e-7, 6.521842602764223e-7, 6.882446925376185e-7, 6.538579588003097e-7, 6.722259382893117e-7, 7.126440148755505e-7, 7.011750796451191e-7, 6.521562694353129e-7, 6.632939190475586e-7, 6.779980580552629e-7, 7.229718735324355e-7, 6.674311498089786e-7, 7.137067790371508e-7, 6.676227296381383e-7, 6.428278142333127e-7, 6.792827243073096e-7, 6.763922474519908e-7, 6.887553530404762e-7, 6.616625331590236e-7, 6.74608564864762e-7, 6.914175435033698e-7, 7.253035653089977e-7, 6.977297650627642e-7, 6.705374744564459e-7, 6.830323276682702e-7, 6.854819576833741e-7, 6.992925733805668e-7, 6.903952176113361e-7, 7.106325151821863e-7, 7.059438132591094e-7, 6.652502530364372e-7, 8.078609438259109e-7, 6.786452808704453e-7, 6.592332363360324e-7, 7.114106528340081e-7, 6.687961032388664e-7, 6.803647773279353e-7, 7.906115511133604e-7, 7.034459893724697e-7, 7.426071862348178e-7, 7.22555427631579e-7, 6.793003289473685e-7, 6.846528593117409e-7, 6.636595521255061e-7, 6.625667004048583e-7, 7.070035045546559e-7, 6.649972402942021e-7, 6.372569148736904e-7, 6.409775727076335e-7, 6.901288195701852e-7, 6.563319763739213e-7, 6.566319976024275e-7, 6.363865211473384e-7, 6.286606810604263e-7, 6.267464067631524e-7, 7.425975324983454e-7, 6.926624667524132e-7, 6.812375095216094e-7, 7.322166431488119e-7, 6.326476942096128e-7, 7.304433136449345e-7, 6.343892558784231e-7, 7.083381326407013e-7, 6.885455850950912e-7, 6.417125535395412e-7, 6.636704961226758e-7, 7.10816548244902e-7, 6.881396585956719e-7, 6.816021902823391e-7, 6.667072963624331e-7, 6.734727463443263e-7, 7.263188771368989e-7, 6.944513055531275e-7, 7.435780522221251e-7, 6.821859367390517e-7, 6.599778099674081e-7 ], "variance": 2.523241303477398e-15 }, "times": { "cycle": 0.0552691552109051, "elapsed": 5.483, "period": 6.901656474183028e-7, "timeStamp": 1520399989427 }, "running": false, "count": 80081, "cycles": 6, "hz": 1448927.520140552 }, "2": { "name": "getobject", "options": { "async": false, "defer": false, "delay": 0.005, "initCount": 1, "maxTime": 5, "minSamples": 5, "minTime": 0.05 }, "async": false, "defer": false, "delay": 0.005, "initCount": 1, "maxTime": 5, "minSamples": 5, "minTime": 0.05, "events": { "abort": [ null ], "complete": [ null ], "cycle": [ null ], "error": [ null ] }, "id": 3, "stats": { "moe": 3.97866766095305e-8, "rme": 0.8506258610018234, "sem": 2.0299324800780868e-8, "deviation": 1.9257630400203384e-7, "mean": 0.000004677341523883579, "sample": [ 0.000004556714631739481, 0.0000048250758948596035, 0.000004687612900331928, 0.00000483121952094734, 0.000004540601327711492, 0.000004508066206154122, 0.00000496295119763165, 0.0000046796637660357045, 0.000004427031824919348, 0.000004469615136454791, 0.00000458139654721423, 0.000004628309878803732, 0.0000045983954137239515, 0.000004836767808876101, 0.000004952575202720376, 0.000004708749411456971, 0.000004680550265934258, 0.000004572794140727178, 0.000004597125294271515, 0.000004506650972185892, 0.000004437546429505624, 0.000004589863109251025, 0.000004487153457145348, 0.000004912558113174645, 0.000004580319557066876, 0.000004747056566181566, 0.000004760447072072072, 0.000004794917966042966, 0.000004491153672903673, 0.000004721007276507277, 0.000004735130544005544, 0.000004678188756063756, 0.00000447407623007623, 0.000004788577529452529, 0.000004790017325017325, 0.000004402838704088704, 0.000004950355076230076, 0.000004782129591129591, 0.000004515439449064449, 0.000004489884095634096, 0.000004553332293832294, 0.000004838777113652113, 0.000004495328222453223, 0.00000476556904019404, 0.000004663184598059598, 0.000004782549376299376, 0.000004437370062370062, 0.000004588456254331254, 0.000004606345374220374, 0.000004416891891891892, 0.000004358009528759529, 0.000004771950883575883, 0.000004601127598752598, 0.000004438758489258489, 0.000004773818087318087, 0.000004433334286209286, 0.000004776369282744283, 0.000004511638946638946, 0.00000491984009009009, 0.000004722565921690921, 0.000004823693087318087, 0.000004803217342342342, 0.000004834445252945253, 0.000004616144577269577, 0.0000045534643104643105, 0.000004669933125433126, 0.000004469115384615385, 0.000004421819213444213, 0.00000461867862092862, 0.000004696541146916147, 0.000004549398302148302, 0.000004822201923076923, 0.000004754586451836452, 0.0000044417475744975744, 0.0000045466973319473324, 0.0000050478569819819815, 0.000004416547557172557, 0.00000456596509009009, 0.000004455009268884268, 0.000004911209026334026, 0.000005135406531531532, 0.000005092080907830907, 0.000005021216042966043, 0.0000048795920824670825, 0.000004849750433125433, 0.00000511752130977131, 0.000004848928794178795, 0.000004522515419265419, 0.000005203894057519058, 0.000004535814795564796 ], "variance": 3.7085632863083755e-14 }, "times": { "cycle": 0.053995230551712035, "elapsed": 5.443, "period": 0.000004677341523883579, "timeStamp": 1520399994910 }, "running": false, "count": 11544, "cycles": 6, "hz": 213796.66096515948 }, "3": { "name": "object-path", "options": { "async": false, "defer": false, "delay": 0.005, "initCount": 1, "maxTime": 5, "minSamples": 5, "minTime": 0.05 }, "async": false, "defer": false, "delay": 0.005, "initCount": 1, "maxTime": 5, "minSamples": 5, "minTime": 0.05, "events": { "abort": [ null ], "complete": [ null ], "cycle": [ null ], "error": [ null ] }, "id": 4, "stats": { "moe": 1.3466748759026716e-7, "rme": 2.4825593922914635, "sem": 6.870790183176896e-8, "deviation": 6.334555555053093e-7, "mean": 0.000005424542430220198, "sample": [ 0.000004997054252782194, 0.000006004418322734499, 0.000006919637619236884, 0.000005000908386327504, 0.000004984031796502384, 0.000005175451376684241, 0.00000680830365163054, 0.000004979618140988088, 0.000004973004588947471, 0.000004931244092950596, 0.00000504623794180824, 0.000005341678383128296, 0.0000066085549697324744, 0.000005116252099199375, 0.000005900046865846514, 0.000005534936047646944, 0.000005103691857059168, 0.000005573665397383323, 0.000007913875610232377, 0.000005204727982815857, 0.000005079777777777778, 0.000005234714020699082, 0.000005027683557898848, 0.000005805906073032611, 0.000006267100078109744, 0.00000502956141378637, 0.000005079960554579184, 0.000005033203866432337, 0.000004954308240578012, 0.000005714024116383519, 0.0000061415962702597156, 0.000005059872095293888, 0.000005513540519429799, 0.000004957921597344269, 0.000004970211091583675, 0.000006025013766842414, 0.000005920727006444054, 0.000005009911443077524, 0.000005053362722124586, 0.000005214142745557508, 0.000004922906073032611, 0.000006205019625073228, 0.000005713756785784026, 0.000004979413102909588, 0.0000053116656702025075, 0.000004889298842815815, 0.000006324940308582449, 0.000005532582352941177, 0.0000054340985535197686, 0.000005035929026036645, 0.0000050070407907425265, 0.000004987019575699132, 0.000006805161427193828, 0.000005116794021215043, 0.0000052267108003857274, 0.000005281073481195757, 0.00000501099787849566, 0.000004941840212150434, 0.00000696453818707811, 0.000005067245033751205, 0.000005040908775313404, 0.000004946929701060753, 0.000005050662391513982, 0.000005168427386692382, 0.0000068295952748312445, 0.0000052247504339440695, 0.000004904510318225651, 0.0000050422018322082935, 0.000004951430954676953, 0.000005272013114754098, 0.0000064550230472516885, 0.00000509746055930569, 0.000004964689296046287, 0.0000050182346190935395, 0.00000487367974927676, 0.0000056238330761812925, 0.000006322973963355834, 0.000005082462487945998, 0.000005148212246865959, 0.000004839743008678881, 0.000005567881858956007, 0.000006469906956770684, 0.000004966329325317302, 0.000005011798931195724, 0.0000052445371695772495 ], "variance": 4.0126594080054005e-13 }, "times": { "cycle": 0.05684378012627746, "elapsed": 5.559, "period": 0.000005424542430220198, "timeStamp": 1520400000353 }, "running": false, "count": 10479, "cycles": 8, "hz": 184347.3459492153 }, "name": "(175 bytes)", "options": { "name": "deep" }, "events": { "start": [ null ], "complete": [ null, null ] }, "length": 4, "running": false } }, "results": [ { "name": "dot-prop", "file": { "stat": null, "_contents": null, "history": [ "/Users/jonschlinkert/dev/js-utils/objects/get-value/benchmark/code/libs/dot-prop.js" ], "_cwd": "/Users/jonschlinkert/dev/js-utils/objects/get-value", "_isVinyl": true, "_symlink": null, "key": "dot-prop" }, "runs": 86, "hz": 883165.9472074186, "ops": "883,166", "rme": "0.93" }, { "name": "get-value", "file": { "stat": null, "_contents": null, "history": [ "/Users/jonschlinkert/dev/js-utils/objects/get-value/benchmark/code/libs/get-value.js" ], "_cwd": "/Users/jonschlinkert/dev/js-utils/objects/get-value", "_isVinyl": true, "_symlink": null, "key": "get-value" }, "runs": 87, "hz": 1448927.520140552, "ops": "1,448,928", "rme": "1.53" }, { "name": "getobject", "file": { "stat": null, "_contents": null, "history": [ "/Users/jonschlinkert/dev/js-utils/objects/get-value/benchmark/code/libs/getobject.js" ], "_cwd": "/Users/jonschlinkert/dev/js-utils/objects/get-value", "_isVinyl": true, "_symlink": null, "key": "getobject" }, "runs": 90, "hz": 213796.66096515948, "ops": "213,797", "rme": "0.85" }, { "name": "object-path", "file": { "stat": null, "_contents": null, "history": [ "/Users/jonschlinkert/dev/js-utils/objects/get-value/benchmark/code/libs/object-path.js" ], "_cwd": "/Users/jonschlinkert/dev/js-utils/objects/get-value", "_isVinyl": true, "_symlink": null, "key": "object-path" }, "runs": 85, "hz": 184347.3459492153, "ops": "184,347", "rme": "2.48" } ], "fastest": [ "get-value" ] }, { "name": "root", "file": { "stat": null, "_contents": null, "history": [ "/Users/jonschlinkert/dev/js-utils/objects/get-value/benchmark/fixtures/root.js" ], "_cwd": "/Users/jonschlinkert/dev/js-utils/objects/get-value", "_isVinyl": true, "_symlink": null, "key": "root", "content": [ { "a": "A", "b": "B", "c": "C", "d": "D", "e": "E", "f": "F", "g": "G", "h": "H", "i": "I", "j": "J", "k": "K", "m": "M", "n": "N" }, "l" ], "bytes": "(210 bytes)", "suite": { "0": { "name": "dot-prop", "options": { "async": false, "defer": false, "delay": 0.005, "initCount": 1, "maxTime": 5, "minSamples": 5, "minTime": 0.05 }, "async": false, "defer": false, "delay": 0.005, "initCount": 1, "maxTime": 5, "minSamples": 5, "minTime": 0.05, "events": { "abort": [ null ], "complete": [ null ], "cycle": [ null ], "error": [ null ] }, "id": 5, "stats": { "moe": 3.473314180872674e-9, "rme": 1.3566169445031946, "sem": 1.7720990718738134e-9, "deviation": 1.652903976299394e-8, "mean": 2.5602762776522986e-7, "sample": [ 2.4600602509239446e-7, 2.416449411147443e-7, 2.390050078232599e-7, 2.5071840948909896e-7, 2.5261372302849164e-7, 2.472630208089344e-7, 2.3476502993338766e-7, 2.3189098397580283e-7, 2.674121197355962e-7, 2.8466358379377235e-7, 2.621249436900701e-7, 2.4763476230314506e-7, 2.496762707657231e-7, 2.639364915925827e-7, 2.4278752539692757e-7, 2.399784091640389e-7, 2.5768883822272074e-7, 2.520214943046528e-7, 2.620334274130529e-7, 2.444040846533607e-7, 2.421102111737288e-7, 2.454154247837239e-7, 2.5214620815827457e-7, 2.461019830288767e-7, 2.438046895828928e-7, 2.432180458385813e-7, 2.449129839206421e-7, 2.675917415167367e-7, 2.4240529818980817e-7, 2.4389284105430575e-7, 2.7006449210741634e-7, 2.450341123256691e-7, 2.4978899635019717e-7, 2.4850142498598e-7, 2.5762673641436754e-7, 2.464059003613029e-7, 2.477411673852886e-7, 2.658453108767801e-7, 2.4386850137442196e-7, 2.58993743851875e-7, 2.440990043485056e-7, 2.488911862318774e-7, 2.599142296341923e-7, 2.4639496014635985e-7, 2.763817583407647e-7, 2.5204324142939883e-7, 2.5259703235177845e-7, 2.4940798267952524e-7, 2.571761190736672e-7, 2.6547355042152004e-7, 3.1967487336011696e-7, 2.421106432662517e-7, 2.432334081067912e-7, 2.5400824193503904e-7, 2.577380462063196e-7, 2.552122171862503e-7, 2.470444044018277e-7, 2.5687303374918406e-7, 2.500478657387403e-7, 2.4396449486545376e-7, 2.3404362755463212e-7, 3.0746375479208993e-7, 2.520591920789166e-7, 2.866478951578057e-7, 3.2340440642438843e-7, 2.7234055326229853e-7, 2.7333470622305167e-7, 2.7196159432947514e-7, 2.761215191269892e-7, 2.4671931913250533e-7, 2.4949549980234067e-7, 2.4748858632197327e-7, 2.6113963023912185e-7, 2.6048632013459223e-7, 2.481050904176588e-7, 2.484287644911881e-7, 2.6393977825379464e-7, 2.7472399400586544e-7, 2.5588040690244825e-7, 2.4369533340075204e-7, 2.6650048725327056e-7, 2.498465565903303e-7, 2.4613981410828053e-7, 2.476137598484918e-7, 2.822498138324768e-7, 2.6148073970562547e-7, 2.770672731284418e-7 ], "variance": 2.732091554866347e-16 }, "times": { "cycle": 0.055697786309814694, "elapsed": 5.358, "period": 2.5602762776522986e-7, "timeStamp": 1520400005915 }, "running": false, "count": 217546, "cycles": 3, "hz": 3905828.4792490127 }, "1": { "name": "get-value", "options": { "async": false, "defer": false, "delay": 0.005, "initCount": 1, "maxTime": 5, "minSamples": 5, "minTime": 0.05 }, "async": false, "defer": false, "delay": 0.005, "initCount": 1, "maxTime": 5, "minSamples": 5, "minTime": 0.05, "events": { "abort": [ null ], "complete": [ null ], "cycle": [ null ], "error": [ null ] }, "id": 6, "stats": { "moe": 8.742349120630953e-10, "rme": 1.4330401068900118, "sem": 4.4603822044035474e-10, "deviation": 4.063601581081575e-9, "mean": 6.100561372007673e-8, "sample": [ 7.655253244651108e-8, 7.595835772266458e-8, 6.906693546641128e-8, 6.633042883577703e-8, 6.337549031056589e-8, 6.475839535841379e-8, 6.432172117293473e-8, 6.156442352015636e-8, 6.337605698727128e-8, 6.23899878920487e-8, 5.958892163796517e-8, 6.271369787454359e-8, 6.343452121113679e-8, 5.7187533768959964e-8, 6.622980263699623e-8, 6.664362537914293e-8, 6.169239931915009e-8, 6.119130348467467e-8, 6.28812438031491e-8, 6.291924438744376e-8, 6.030608918502175e-8, 6.767377182504097e-8, 6.017154575264033e-8, 6.563754668435343e-8, 6.176299407019882e-8, 5.811710708722346e-8, 6.567192193462441e-8, 5.8680033590398145e-8, 6.085416429367478e-8, 6.438461163963558e-8, 5.700976792870784e-8, 5.987376268845972e-8, 5.979350479212724e-8, 6.216613666691009e-8, 5.830055633377371e-8, 5.6856240608824777e-8, 5.692183886679635e-8, 6.026520568195146e-8, 6.175855910880376e-8, 6.184610975752788e-8, 5.805532909776117e-8, 6.169122479734978e-8, 5.970778535341801e-8, 6.185017825252773e-8, 6.075523748193686e-8, 6.489980017128176e-8, 6.807751937984496e-8, 5.971605511997469e-8, 5.757595151000139e-8, 5.941264851611133e-8, 6.027015382164125e-8, 5.7922583521986686e-8, 5.770979138589957e-8, 6.114165930863247e-8, 6.181881642977116e-8, 6.040429797714915e-8, 6.372721941547334e-8, 6.265088727934196e-8, 5.8726443779086365e-8, 5.935050576803493e-8, 6.192386813517538e-8, 6.004600597051918e-8, 5.734031848670132e-8, 6.28120669547918e-8, 5.781889941511927e-8, 5.5756334550436116e-8, 6.00326960575813e-8, 5.5442137534455424e-8, 5.601477868431374e-8, 5.5328674094492104e-8, 5.971375620750036e-8, 5.94920980384575e-8, 5.632123474826177e-8, 5.475912669426183e-8, 5.845292535779022e-8, 5.89259107756405e-8, 5.5066083380677976e-8, 5.7305054243432624e-8, 6.459551226902579e-8, 5.6999298758217674e-8, 5.4756130184238294e-8, 5.705504423342261e-8, 6.181580391202012e-8 ], "variance": 1.6512857809768673e-17 }, "times": { "cycle": 0.05637376249837991, "elapsed": 5.665, "period": 6.100561372007673e-8, "timeStamp": 1520400011274 }, "running": false, "count": 924075, "cycles": 7, "hz": 16391934.102793945 }, "2": { "name": "getobject", "options": { "async": false, "defer": false, "delay": 0.005, "initCount": 1, "maxTime": 5, "minSamples": 5, "minTime": 0.05 }, "async": false, "defer": false, "delay": 0.005, "initCount": 1, "maxTime": 5, "minSamples": 5, "minTime": 0.05, "events": { "abort": [ null ], "complete": [ null ], "cycle": [ null ], "error": [ null ] }, "id": 7, "stats": { "moe": 1.5103959856294698e-8, "rme": 1.8125075338075372, "sem": 7.706101967497295e-9, "deviation": 7.22896442303113e-8, "mean": 8.33318459348182e-7, "sample": [ 7.921838920699188e-7, 8.144075780695261e-7, 7.598170899366983e-7, 7.571719569125712e-7, 8.206051095545976e-7, 7.72339544420498e-7, 7.595468151340996e-7, 7.949708153735633e-7, 8.207508530890804e-7, 7.741798820641762e-7, 7.913066331417624e-7, 8.518323605124521e-7, 7.544107249760537e-7, 7.569418253113026e-7, 8.34191870210728e-7, 8.879193306992338e-7, 8.058851772030651e-7, 7.85765789631226e-7, 8.011733716475096e-7, 7.862446270354406e-7, 8.283676364942529e-7, 7.975651789990421e-7, 7.790552861590038e-7, 7.834173251915708e-7, 7.745096384099617e-7, 7.876770683668582e-7, 7.96033285440613e-7, 7.795693845785441e-7, 8.010801454741379e-7, 7.538675017959769e-7, 7.773146551724138e-7, 8.117576179358238e-7, 7.951981112308429e-7, 7.7619610572318e-7, 7.922049808429119e-7, 7.574925317289273e-7, 8.243982279693487e-7, 8.220210877634099e-7, 7.966582106082375e-7, 8.240544181034482e-7, 8.039833872126436e-7, 8.396863176484674e-7, 8.119253921216475e-7, 7.747473958333333e-7, 8.991837284482758e-7, 7.768815104166666e-7, 0.0000010136659632423372, 8.209435763888889e-7, 7.987928639846743e-7, 0.0000010952636344588123, 0.0000011383986470306514, 0.0000010645391522988507, 8.679220994971264e-7, 8.409233716475095e-7, 7.949522419779694e-7, 8.522368594348658e-7, 7.978019187021073e-7, 8.534794061302682e-7, 7.893578633860153e-7, 8.603021731321838e-7, 0.0000010107129130747128, 8.817334620450191e-7, 8.495129310344827e-7, 8.763879160680076e-7, 9.030820013170498e-7, 9.274257213840996e-7, 8.911314804837165e-7, 8.716106022509578e-7, 8.841712164750958e-7, 8.701056633141762e-7, 8.942284782088123e-7, 8.570594169061303e-7, 8.489714289990422e-7, 8.342969049329502e-7, 8.422377723898468e-7, 8.327155471743295e-7, 8.471605004789271e-7, 9.715935255028734e-7, 8.636366888170498e-7, 8.551864673132184e-7, 8.26143438697318e-7, 8.231760207136016e-7, 8.144688248323754e-7, 7.680304118773947e-7, 8.116870809386973e-7, 8.042534722222222e-7, 7.735542534722223e-7, 8.226791337404214e-7 ], "variance": 5.22579266294498e-15 }, "times": { "cycle": 0.05567900617980812, "elapsed": 5.347, "period": 8.33318459348182e-7, "timeStamp": 1520400016939 }, "running": false, "count": 66816, "cycles": 4, "hz": 1200021.4189209195 }, "3": { "name": "object-path", "options": { "async": false, "defer": false, "delay": 0.005, "initCount": 1, "maxTime": 5, "minSamples": 5, "minTime": 0.05 }, "async": false, "defer": false, "delay": 0.005, "initCount": 1, "maxTime": 5, "minSamples": 5, "minTime": 0.05, "events": { "abort": [ null ], "complete": [ null ], "cycle": [ null ], "error": [ null ] }, "id": 8, "stats": { "moe": 6.478043395542929e-9, "rme": 1.8063987006663704, "sem": 3.305124181399454e-9, "deviation": 3.0650460738536074e-8, "mean": 3.5861647781042e-7, "sample": [ 3.6926855396217793e-7, 3.7377249419729847e-7, 4.1492321147105965e-7, 3.834303775580104e-7, 3.536959184895019e-7, 3.4067977068521754e-7, 3.433373747181782e-7, 3.578886413365168e-7, 4.5120638995484204e-7, 3.4220291165927333e-7, 3.492754437653381e-7, 3.3702245263066885e-7, 3.4772101808314653e-7, 3.4357272830055667e-7, 4.2872025990782183e-7, 3.712129874102992e-7, 3.5207396199812454e-7, 3.335706399930833e-7, 3.352083918037257e-7, 3.888079940578432e-7, 3.9215454250034817e-7, 3.442111654187695e-7, 3.4184984116667884e-7, 3.377211979299896e-7, 3.6940146789712916e-7, 4.0806568150961216e-7, 3.5471681653909473e-7, 3.3622831769019365e-7, 3.4289042587381854e-7, 3.3064376274899486e-7, 3.4967237952814784e-7, 4.2621733797708293e-7, 3.334902304165601e-7, 3.3082168132596105e-7, 3.313521772495622e-7, 3.3945805211756296e-7, 3.627313446541128e-7, 4.2037408420403636e-7, 3.32034893711917e-7, 3.3389579110997423e-7, 3.3501058152494594e-7, 3.3090220940142924e-7, 3.9109015275683475e-7, 3.736587687668e-7, 3.3058231823247886e-7, 3.278854192311181e-7, 3.370492633815774e-7, 3.725577309301994e-7, 3.7864633893517495e-7, 3.557013164543841e-7, 3.4343186441556425e-7, 3.97498633012426e-7, 3.467907472433497e-7, 3.810999520582557e-7, 4.128627570390142e-7, 3.4966063075786826e-7, 3.539942858623683e-7, 3.4936156497402077e-7, 3.412676250696451e-7, 3.6789901784210326e-7, 4.158637223525144e-7, 3.493079868354561e-7, 3.4635525480389237e-7, 3.42830985915493e-7, 3.418110771343794e-7, 3.663793811627817e-7, 4.153888205035179e-7, 3.355033883151716e-7, 3.626517939282429e-7, 3.269179807455589e-7, 3.404139121759073e-7, 3.380883747748682e-7, 4.3021448747683895e-7, 3.5113796856576443e-7, 3.3595233035748996e-7, 3.285557549529005e-7, 3.3277091547619813e-7, 4.1282900991181633e-7, 3.3244053231792424e-7, 3.3034176148606495e-7, 3.2531096474583686e-7, 3.29328607907584e-7, 3.318363939255552e-7, 4.18307896649536e-7, 3.584342288915618e-7, 3.295696689414746e-7 ], "variance": 9.394507434845412e-16 }, "times": { "cycle": 0.055754462421663806, "elapsed": 5.478, "period": 3.5861647781042e-7, "timeStamp": 1520400022286 }, "running": false, "count": 155471, "cycles": 4, "hz": 2788494.288119808 }, "name": "(210 bytes)", "options": { "name": "root" }, "events": { "start": [ null ], "complete": [ null, null ] }, "length": 4, "running": false } }, "results": [ { "name": "dot-prop", "file": { "stat": null, "_contents": null, "history": [ "/Users/jonschlinkert/dev/js-utils/objects/get-value/benchmark/code/libs/dot-prop.js" ], "_cwd": "/Users/jonschlinkert/dev/js-utils/objects/get-value", "_isVinyl": true, "_symlink": null, "key": "dot-prop" }, "runs": 87, "hz": 3905828.4792490127, "ops": "3,905,828", "rme": "1.36" }, { "name": "get-value", "file": { "stat": null, "_contents": null, "history": [ "/Users/jonschlinkert/dev/js-utils/objects/get-value/benchmark/code/libs/get-value.js" ], "_cwd": "/Users/jonschlinkert/dev/js-utils/objects/get-value", "_isVinyl": true, "_symlink": null, "key": "get-value" }, "runs": 83, "hz": 16391934.102793945, "ops": "16,391,934", "rme": "1.43" }, { "name": "getobject", "file": { "stat": null, "_contents": null, "history": [ "/Users/jonschlinkert/dev/js-utils/objects/get-value/benchmark/code/libs/getobject.js" ], "_cwd": "/Users/jonschlinkert/dev/js-utils/objects/get-value", "_isVinyl": true, "_symlink": null, "key": "getobject" }, "runs": 88, "hz": 1200021.4189209195, "ops": "1,200,021", "rme": "1.81" }, { "name": "object-path", "file": { "stat": null, "_contents": null, "history": [ "/Users/jonschlinkert/dev/js-utils/objects/get-value/benchmark/code/libs/object-path.js" ], "_cwd": "/Users/jonschlinkert/dev/js-utils/objects/get-value", "_isVinyl": true, "_symlink": null, "key": "object-path" }, "runs": 86, "hz": 2788494.288119808, "ops": "2,788,494", "rme": "1.81" } ], "fastest": [ "get-value" ] }, { "name": "shallow", "file": { "stat": null, "_contents": null, "history": [ "/Users/jonschlinkert/dev/js-utils/objects/get-value/benchmark/fixtures/shallow.js" ], "_cwd": "/Users/jonschlinkert/dev/js-utils/objects/get-value", "_isVinyl": true, "_symlink": null, "key": "shallow", "content": [ { "x": { "y": {} } }, "x.y.z" ], "bytes": "(84 bytes)", "suite": { "0": { "name": "dot-prop", "options": { "async": false, "defer": false, "delay": 0.005, "initCount": 1, "maxTime": 5, "minSamples": 5, "minTime": 0.05 }, "async": false, "defer": false, "delay": 0.005, "initCount": 1, "maxTime": 5, "minSamples": 5, "minTime": 0.05, "events": { "abort": [ null ], "complete": [ null ], "cycle": [ null ], "error": [ null ] }, "id": 9, "stats": { "moe": 3.4860930019070955e-9, "rme": 0.8901940670351274, "sem": 1.7786188785240283e-9, "deviation": 1.677945694111536e-8, "mean": 3.9161045113655346e-7, "sample": [ 3.979962307236279e-7, 3.7867977662026167e-7, 3.7205464567725527e-7, 3.658720334636141e-7, 4.2132507820458176e-7, 3.854084338132771e-7, 3.6754354843337543e-7, 3.6654903592333294e-7, 3.781719270056238e-7, 3.6542704866291747e-7, 3.6250039452542176e-7, 3.746078632503156e-7, 3.9691867755078614e-7, 4.1592759382531846e-7, 3.949785306438655e-7, 3.8077398714564445e-7, 3.8671820125100423e-7, 3.841658800068863e-7, 3.9339333467232867e-7, 3.6852644754963847e-7, 3.936968968782279e-7, 3.8722800700103293e-7, 4.1927722225410307e-7, 3.8256011132790084e-7, 3.883331085733961e-7, 3.9276602490531386e-7, 3.8317732841730747e-7, 3.7522183805807416e-7, 3.7379252984046826e-7, 4.019940103867784e-7, 4.309351902329852e-7, 3.941995437851486e-7, 3.918275708711121e-7, 3.9090254504762994e-7, 4.1800081057041204e-7, 3.8267275909560427e-7, 3.8518014030758635e-7, 3.838209643635946e-7, 4.01202656949386e-7, 4.034555047056123e-7, 3.962023413290485e-7, 4.119873393205555e-7, 3.845666317571445e-7, 3.824001707219098e-7, 3.714905959485826e-7, 3.7154298892459543e-7, 3.8406125186502927e-7, 4.2018069264317686e-7, 4.2331700476299785e-7, 4.1498365230115916e-7, 3.8325178612418224e-7, 3.970128400091817e-7, 3.989418756455871e-7, 3.8128174853666935e-7, 4.295697951337082e-7, 3.8123388184322276e-7, 3.996656576380122e-7, 3.903955870538276e-7, 4.4270917020544014e-7, 3.866596465052221e-7, 3.8566536353724325e-7, 3.8075251061632046e-7, 3.5959024514702443e-7, 3.958747191688105e-7, 3.8438906016343135e-7, 4.1980928284396064e-7, 3.631544093154452e-7, 3.950514177988504e-7, 3.932010857624788e-7, 3.9858449740962023e-7, 3.9772738290136713e-7, 3.921133034252546e-7, 3.895796355750218e-7, 3.9291065138661503e-7, 3.832428153282447e-7, 4.0498377026059713e-7, 4.039726007980213e-7, 4.003389322390662e-7, 4.0725623852755866e-7, 3.803596978008349e-7, 4.152732620358755e-7, 3.8324022849205167e-7, 3.796344339789793e-7, 3.8955147804024127e-7, 3.795542207953281e-7, 4.151426870495184e-7, 3.8427993819942023e-7, 3.9928096584667504e-7, 3.895772259193899e-7 ], "variance": 2.815501752387444e-16 }, "times": { "cycle": 0.055255843044916556, "elapsed": 5.424, "period": 3.9161045113655346e-7, "timeStamp": 1520400027766 }, "running": false, "count": 141099, "cycles": 4, "hz": 2553557.9990210803 }, "1": { "name": "get-value", "options": { "async": false, "defer": false, "delay": 0.005, "initCount": 1, "maxTime": 5, "minSamples": 5, "minTime": 0.05 }, "async": false, "defer": false, "delay": 0.005, "initCount": 1, "maxTime": 5, "minSamples": 5, "minTime": 0.05, "events": { "abort": [ null ], "complete": [ null ], "cycle": [ null ], "error": [ null ] }, "id": 10, "stats": { "moe": 2.877142092737967e-9, "rme": 0.8833282821344, "sem": 1.467929639152024e-9, "deviation": 1.3926003313768427e-8, "mean": 3.257160617325513e-7, "sample": [ 3.259133893005799e-7, 3.207778881740729e-7, 3.162368725005589e-7, 3.2434769865123326e-7, 3.413954519486326e-7, 3.1447358975632777e-7, 3.2573394147892396e-7, 3.234969696216995e-7, 3.48606522765096e-7, 3.0354923664806874e-7, 3.1564727340138615e-7, 3.528446804566358e-7, 3.2988164307541427e-7, 3.0991493993051193e-7, 3.212862225889979e-7, 3.2537518762371205e-7, 3.1523453711510976e-7, 3.4948066952512514e-7, 3.3823651650789663e-7, 3.259557656542461e-7, 3.183184549972193e-7, 3.198869712898345e-7, 3.126701590092272e-7, 3.4808537103149685e-7, 3.314247501838862e-7, 3.8700211095363674e-7, 3.3404085562392735e-7, 3.138624531314472e-7, 3.0927030970620067e-7, 3.151177110804136e-7, 3.170597346058856e-7, 3.108378333124032e-7, 3.326760493472788e-7, 3.4458122985474486e-7, 3.278046799782327e-7, 3.2720701099729107e-7, 3.210874102246701e-7, 3.3575957254683867e-7, 3.191442265717037e-7, 3.195274274471813e-7, 3.3569500606973925e-7, 3.5815124713705653e-7, 3.2067307128804054e-7, 3.1166614042326714e-7, 3.145245929088702e-7, 3.25816036071593e-7, 3.275506957774947e-7, 3.327727405919042e-7, 3.262212434892329e-7, 3.1584384923126603e-7, 3.115201018998583e-7, 3.166141260472543e-7, 3.2346170682262607e-7, 3.271364166412515e-7, 3.178427788043511e-7, 3.2886973681849985e-7, 3.207076957117143e-7, 3.497579997966787e-7, 3.2267086465378564e-7, 3.2022107604815126e-7, 3.193109859289691e-7, 3.285233131806032e-7, 3.188864869067054e-7, 3.248335815049365e-7, 3.067768727985983e-7, 3.394534304491607e-7, 3.3911921207010996e-7, 3.049380467997823e-7, 3.1208013251765606e-7, 3.1443910825663933e-7, 3.395231158393283e-7, 3.131264180166604e-7, 3.2517143574747493e-7, 3.138269855223265e-7, 3.2682706326282867e-7, 3.4967067927258813e-7, 3.217866740819146e-7, 3.2766215771753887e-7, 3.3970423924938553e-7, 3.564195296101613e-7, 3.293295180686867e-7, 3.191016307565347e-7, 3.169623855570107e-7, 3.4035321098174295e-7, 3.2493091859373413e-7, 3.0736053054902736e-7, 3.2895111318419113e-7, 3.1561990874461046e-7, 3.0340219945820847e-7, 3.248842264521029e-7 ], "variance": 1.9393356829508923e-16 }, "times": { "cycle": 0.05446721699110243, "elapsed": 5.373, "period": 3.257160617325513e-7, "timeStamp": 1520400033190 }, "running": false, "count": 167223, "cycles": 4, "hz": 3070158.6979800523 }, "2": { "name": "getobject", "options": { "async": false, "defer": false, "delay": 0.005, "initCount": 1, "maxTime": 5, "minSamples": 5, "minTime": 0.05 }, "async": false, "defer": false, "delay": 0.005, "initCount": 1, "maxTime": 5, "minSamples": 5, "minTime": 0.05, "events": { "abort": [ null ], "complete": [ null ], "cycle": [ null ], "error": [ null ] }, "id": 11, "stats": { "moe": 1.1163299131335605e-8, "rme": 0.8112038494648819, "sem": 5.695560781293676e-9, "deviation": 5.2818457803625e-8, "mean": 0.0000013761398122925057, "sample": [ 0.000001435441917929924, 0.000001392053223388306, 0.0000013893638180909546, 0.0000014137102837470153, 0.0000013894223443833639, 0.0000013369544410004276, 0.000001364771680234886, 0.0000013944217269451488, 0.0000013786108072225172, 0.0000014592325274144537, 0.0000013351975161844366, 0.0000013240390276126305, 0.000001363535949266746, 0.000001443418293230501, 0.000001360185494308127, 0.0000013745643538205542, 0.0000013619423681360767, 0.0000013772516573783048, 0.0000014468780803465309, 0.0000013383889754628774, 0.0000013488405483214918, 0.000001380405403977708, 0.0000013669532236338185, 0.0000013735828953276459, 0.0000013425180528776313, 0.0000013923942051187238, 0.0000013433256649322521, 0.0000013591069438208183, 0.0000014536740973561184, 0.0000013989166688677003, 0.0000014513368109664298, 0.0000014404878106758934, 0.0000013285876495602334, 0.0000013512132273315548, 0.000001360714127306809, 0.0000013224077672466142, 0.0000013484359637774905, 0.0000014048047891860495, 0.0000013123846389776358, 0.0000014137501853035143, 0.0000014086452140575079, 0.0000013136899680511183, 0.0000013578805111821088, 0.0000013272813801916933, 0.0000013417366900958465, 0.0000013331606389776356, 0.0000013540930607028755, 0.0000014522572012779553, 0.000001332976664536741, 0.000001339550057507987, 0.000001448404319488818, 0.0000013540394376996804, 0.0000013727845111821087, 0.0000013800178146964857, 0.0000015798776741214057, 0.0000013407175207667731, 0.000001444862696485623, 0.0000014347464025559107, 0.0000013039589776357828, 0.0000013230767284345048, 0.000001327336766773163, 0.000001324181699680511, 0.0000013475196677316295, 0.0000013278597316293929, 0.0000014237983897763578, 0.0000014773775335463258, 0.0000013891045623003196, 0.0000013101990287539936, 0.0000013067186709265175, 0.0000013123805495207669, 0.0000013356945942492014, 0.0000013186450862619808, 0.0000013929317571884984, 0.0000013707672332268372, 0.0000013277075782747605, 0.0000013436348881789138, 0.0000013232825303514378, 0.0000013597357955271565, 0.0000013276163578274762, 0.0000014219530990415335, 0.0000013642469009584664, 0.0000014402591182108626, 0.0000014834185814696484, 0.0000013678503769968052, 0.0000015266850862619808, 0.000001380135642172524 ], "variance": 2.7897894847533145e-15 }, "times": { "cycle": 0.05384147015594429, "elapsed": 5.343, "period": 0.0000013761398122925057, "timeStamp": 1520400038564 }, "running": false, "count": 39125, "cycles": 4, "hz": 726670.3506921321 }, "3": { "name": "object-path", "options": { "async": false, "defer": false, "delay": 0.005, "initCount": 1, "maxTime": 5, "minSamples": 5, "minTime": 0.05 }, "async": false, "defer": false, "delay": 0.005, "initCount": 1, "maxTime": 5, "minSamples": 5, "minTime": 0.05, "events": { "abort": [ null ], "complete": [ null ], "cycle": [ null ], "error": [ null ] }, "id": 12, "stats": { "moe": 2.2266966308650523e-8, "rme": 2.053796293254094, "sem": 1.1360697096250267e-8, "deviation": 1.0535477071351082e-7, "mean": 0.0000010841857287301897, "sample": [ 0.0000011770766844243055, 0.0000012285647133263935, 0.000001077501438981079, 0.000001037860816851387, 0.0000010797383678680152, 0.0000012278745359913582, 9.842278306982224e-7, 9.907888474376596e-7, 0.0000011118436798657325, 0.0000013122836986007298, 9.912141644386331e-7, 0.0000010376231728498663, 0.0000010590778283015554, 0.000001050763392595773, 0.0000010169165121679905, 0.0000013778558771296423, 0.0000010194397845475304, 0.0000010200007806248901, 0.0000010860316738549208, 0.0000010010904353935325, 9.9594030171152e-7, 0.0000013086746940926211, 9.966026619308758e-7, 0.000001027282098319705, 0.0000010112183798130403, 0.000001131985343767686, 0.0000010012475556683125, 0.0000012563086200503503, 0.0000011133849261333697, 0.000001076850041958588, 9.979481469916667e-7, 0.0000010400696122245858, 0.0000010329773618781835, 0.0000012376672391249194, 0.0000011717323042095198, 0.0000010511966979567144, 0.0000010061559103062, 9.95590386604477e-7, 0.0000010117021330575125, 0.0000011718427431158642, 0.0000011739611639117113, 0.000001013867001034328, 0.0000010449019144825431, 0.0000010359886028766027, 0.0000010262930465837904, 0.000001192623309459222, 0.000001205772174625788, 0.0000010482039772838157, 0.0000010299974434534845, 0.0000010949676235826779, 0.0000010342249370621183, 0.0000010977703401572958, 0.0000012895088698503152, 0.0000010305162077242832, 0.0000010030931675806484, 9.805126168497883e-7, 0.000001009839581585059, 0.0000010750631720692415, 0.0000014024745418707677, 0.0000010162094416580474, 0.0000010421082726722743, 0.0000010085001268515447, 0.000001019396401319256, 0.0000010608331999765813, 0.0000013426459475810388, 0.0000010606535977049628, 0.0000010378298042583088, 0.0000010293678499638962, 0.0000010460036884526064, 9.91238207685252e-7, 0.0000013634743076833004, 0.0000010056285201303644, 9.835563903905076e-7, 9.816092777268203e-7, 9.835747155598056e-7, 0.0000010127867332799907, 0.0000012251525341035501, 0.00000111207544739564, 0.000001028709334322125, 0.0000010267524638473098, 0.0000010297699498448508, 0.0000010334627154036805, 0.000001244200874299877, 0.0000011776640971097364, 0.0000010508457875529363, 0.0000010121918971136396 ], "variance": 1.1099627712096438e-14 }, "times": { "cycle": 0.05555476092586365, "elapsed": 5.376, "period": 0.0000010841857287301897, "timeStamp": 1520400043907 }, "running": false, "count": 51241, "cycles": 4, "hz": 922351.1926975935 }, "name": "(84 bytes)", "options": { "name": "shallow" }, "events": { "start": [ null ], "complete": [ null, null ] }, "length": 4, "running": false } }, "results": [ { "name": "dot-prop", "file": { "stat": null, "_contents": null, "history": [ "/Users/jonschlinkert/dev/js-utils/objects/get-value/benchmark/code/libs/dot-prop.js" ], "_cwd": "/Users/jonschlinkert/dev/js-utils/objects/get-value", "_isVinyl": true, "_symlink": null, "key": "dot-prop" }, "runs": 89, "hz": 2553557.9990210803, "ops": "2,553,558", "rme": "0.89" }, { "name": "get-value", "file": { "stat": null, "_contents": null, "history": [ "/Users/jonschlinkert/dev/js-utils/objects/get-value/benchmark/code/libs/get-value.js" ], "_cwd": "/Users/jonschlinkert/dev/js-utils/objects/get-value", "_isVinyl": true, "_symlink": null, "key": "get-value" }, "runs": 90, "hz": 3070158.6979800523, "ops": "3,070,159", "rme": "0.88" }, { "name": "getobject", "file": { "stat": null, "_contents": null, "history": [ "/Users/jonschlinkert/dev/js-utils/objects/get-value/benchmark/code/libs/getobject.js" ], "_cwd": "/Users/jonschlinkert/dev/js-utils/objects/get-value", "_isVinyl": true, "_symlink": null, "key": "getobject" }, "runs": 86, "hz": 726670.3506921321, "ops": "726,670", "rme": "0.81" }, { "name": "object-path", "file": { "stat": null, "_contents": null, "history": [ "/Users/jonschlinkert/dev/js-utils/objects/get-value/benchmark/code/libs/object-path.js" ], "_cwd": "/Users/jonschlinkert/dev/js-utils/objects/get-value", "_isVinyl": true, "_symlink": null, "key": "object-path" }, "runs": 86, "hz": 922351.1926975935, "ops": "922,351", "rme": "2.05" } ], "fastest": [ "get-value" ] } ]get-value-3.0.1/benchmark/stats.md000066400000000000000000000015411324767417700170410ustar00rootroot00000000000000# deep (175 bytes) dot-prop x 883,166 ops/sec ±0.93% (86 runs sampled) get-value x 1,448,928 ops/sec ±1.53% (87 runs sampled) getobject x 213,797 ops/sec ±0.85% (90 runs sampled) object-path x 184,347 ops/sec ±2.48% (85 runs sampled) fastest is get-value (by 339% avg) # root (210 bytes) dot-prop x 3,905,828 ops/sec ±1.36% (87 runs sampled) get-value x 16,391,934 ops/sec ±1.43% (83 runs sampled) getobject x 1,200,021 ops/sec ±1.81% (88 runs sampled) object-path x 2,788,494 ops/sec ±1.81% (86 runs sampled) fastest is get-value (by 623% avg) # shallow (84 bytes) dot-prop x 2,553,558 ops/sec ±0.89% (89 runs sampled) get-value x 3,070,159 ops/sec ±0.88% (90 runs sampled) getobject x 726,670 ops/sec ±0.81% (86 runs sampled) object-path x 922,351 ops/sec ±2.05% (86 runs sampled) fastest is get-value (by 219% avg) get-value-3.0.1/examples/000077500000000000000000000000001324767417700152445ustar00rootroot00000000000000get-value-3.0.1/examples/arrays.js000066400000000000000000000002441324767417700171030ustar00rootroot00000000000000const get = require('..'); console.log(get({ a: { b: [{ c: 'd' }] } }, 'a.b.0.c'), 'd'); console.log(get({ a: { b: [{ c: 'd' }, { e: 'f' }] } }, 'a.b.1.e'), 'f'); get-value-3.0.1/examples/functions.js000066400000000000000000000003721324767417700176140ustar00rootroot00000000000000const get = require('..'); function foo() {} foo.bar = { baz: 'qux' }; console.log(get(foo)); //=> { [Function: foo] bar: { baz: 'qux' } } console.log(get(foo, 'bar')); //=> { baz: 'qux' } console.log(get(foo, 'bar.baz')); //=> qux get-value-3.0.1/examples/join.js000066400000000000000000000003071324767417700165410ustar00rootroot00000000000000const get = require('..'); const obj = { 'a/b': { c: { d: 'e' } } }; const options = { join: segs => segs.join(segs[0] === 'a' ? '/' : '.') }; console.log(get(obj, 'a.b.c.d', options)); //=> 'e' get-value-3.0.1/examples/keys-with-dots.js000066400000000000000000000004001324767417700204670ustar00rootroot00000000000000const get = require('..'); console.log(get({ files: { 'foo/bar.md': { b: 'c' } } }, 'files.foo/bar.md')); //=> { b: c } console.log(get({ 'a.b': { c: 'd' } }, 'a.b.c')); //=> 'd' console.log(get({ 'a.b': { c: { 'd.e': 'f' } } }, 'a.b.c.d.e')); //=> 'f' get-value-3.0.1/examples/options.default.js000066400000000000000000000014321324767417700207200ustar00rootroot00000000000000const get = require('..'); console.log(get(null, 'foo.bar', false), false); console.log(get('foo', 'foo.bar', false), false); console.log(get([], 'foo.bar', false), false); console.log(get(undefined, 'foo.bar', false), false); const obj = { foo: { a: { b: { c: { d: 'e' } } } } }; console.log(get(obj, 'foo.a.b.c.d', { default: true }), 'e'); console.log(get(obj, 'foo.bar.baz', { default: true }), true); console.log(get(obj, 'foo.bar.baz', { default: false }), false); console.log(get(obj, 'foo.bar.baz', { default: null }), null); // you can also pass the default as the last argument console.log(get(obj, 'foo.a.b.c.d', true), 'e'); console.log(get(obj, 'foo.bar.baz', true), true); console.log(get(obj, 'foo.bar.baz', false), false); console.log(get(obj, 'foo.bar.baz', null), null); get-value-3.0.1/examples/options.isValue.js000066400000000000000000000006731324767417700207120ustar00rootroot00000000000000const get = require('..'); const isEnumerable = Object.prototype.propertyIsEnumerable; const options = { isValid: (key, obj) => isEnumerable.call(obj, key) }; const obj = {}; Object.defineProperty(obj, 'foo', { value: 'bar', enumerable: false }); console.log(get(obj, 'foo', options)); //=> undefined console.log(get({}, 'hasOwnProperty', options)); //=> undefined console.log(get({}, 'constructor', options)); //=> undefined get-value-3.0.1/index.js000066400000000000000000000047201324767417700150760ustar00rootroot00000000000000/*! * 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'; } get-value-3.0.1/package.json000066400000000000000000000031161324767417700157150ustar00rootroot00000000000000{ "name": "get-value", "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.1", "homepage": "https://github.com/jonschlinkert/get-value", "author": "Jon Schlinkert (https://github.com/jonschlinkert)", "repository": "jonschlinkert/get-value", "bugs": { "url": "https://github.com/jonschlinkert/get-value/issues" }, "license": "MIT", "files": [ "index.js" ], "main": "index.js", "engines": { "node": ">=6.0" }, "scripts": { "test": "nyc --reporter=text --reporter=html mocha" }, "dependencies": { "isobject": "^3.0.1" }, "devDependencies": { "arr-reduce": "^1.0.1", "benchmarked": "^2.0.0", "dot-prop": "^4.2.0", "getobject": "^0.1.0", "glob": "^7.1.2", "gulp-format-md": "^1.0.0", "micromatch": "^3.1.5", "minimist": "^1.2.0", "mocha": "^3.5.3", "nyc": "^11.4.1", "object-path": "^0.11.4", "write": "^1.0.3" }, "keywords": [ "get", "key", "nested", "object", "path", "paths", "prop", "properties", "property", "props", "segment", "value", "values" ], "verb": { "run": true, "toc": "collapsible", "layout": "default", "tasks": [ "readme" ], "plugins": [ "gulp-format-md" ], "related": { "list": [ "has-any", "has-any-deep", "has-value", "set-value", "unset-value" ] }, "lint": { "reflinks": true } } } get-value-3.0.1/test/000077500000000000000000000000001324767417700144055ustar00rootroot00000000000000get-value-3.0.1/test/test.js000066400000000000000000000010431324767417700157200ustar00rootroot00000000000000'use strict'; require('mocha'); const path = require('path'); const argv = require('minimist')(process.argv.slice(2)); const glob = require('glob'); const mm = require('micromatch'); const units = require('./units'); const cwd = path.join.bind(path, __dirname, '../benchmark/code'); const files = pattern => { const paths = glob.sync('**/*.js', { cwd: cwd() }); return mm(paths, `{,libs/}${pattern}{,.js}`).map(f => cwd(f)); }; if (argv.bench) { files(argv.bench).forEach(file => units(require(file))); return; } units(require('..')); get-value-3.0.1/test/units.js000066400000000000000000000471741324767417700161220ustar00rootroot00000000000000'use strict'; const assert = require('assert'); module.exports = function(get) { describe('get value:', function() { it('should return non-object when given as the first argument', function() { assert.deepStrictEqual(get(null), null); assert.deepStrictEqual(get('foo'), 'foo'); assert.deepStrictEqual(get(['a']), ['a']); }); it('should get a value', function() { assert.deepStrictEqual(get({ a: 'a', b: { c: 'd' } }, 'a'), 'a'); assert.deepStrictEqual(get({ a: 'a', b: { c: 'd' } }, 'b.c'), 'd'); assert.deepStrictEqual(get({ foo: 'bar' }, 'foo.bar'), undefined); }); it('should get a property that has dots in the key', function() { assert.deepStrictEqual(get({ 'a.b': 'c' }, 'a.b'), 'c'); }); it('should support using dot notation to get nested values', function() { const fixture = { a: { locals: { name: { first: 'Brian' } } }, b: { locals: { name: { last: 'Woodward' } } }, c: { locals: { paths: ['a.txt', 'b.js', 'c.hbs'] } } }; assert.deepStrictEqual(get(fixture, 'a.locals.name'), { first: 'Brian' }); assert.deepStrictEqual(get(fixture, 'b.locals.name'), { last: 'Woodward' }); assert.strictEqual(get(fixture, 'b.locals.name.last'), 'Woodward'); assert.strictEqual(get(fixture, 'c.locals.paths.0'), 'a.txt'); assert.strictEqual(get(fixture, 'c.locals.paths.1'), 'b.js'); assert.strictEqual(get(fixture, 'c.locals.paths.2'), 'c.hbs'); }); it('should support a custom separator on options.separator', function() { const fixture = { 'a.b': { c: { d: 'e' } } }; assert.strictEqual(get(fixture, 'a.b/c/d', { separator: '/' }), 'e'); assert.strictEqual(get(fixture, 'a\\.b.c.d', { separator: /\\?\./ }), 'e'); }); it('should support a custom split function', function() { const fixture = { 'a.b': { c: { d: 'e' } } }; assert.strictEqual(get(fixture, 'a.b/c/d', { split: path => path.split('/') }), 'e'); assert.strictEqual(get(fixture, 'a\\.b.c.d', { split: path => path.split(/\\?\./) }), 'e'); }); it('should support a custom join character', function() { const fixture = { 'a-b': { c: { d: 'e' } } }; const options = { joinChar: '-' }; assert.strictEqual(get(fixture, 'a.b.c.d', options), 'e'); }); it('should support a custom join function', function() { const fixture = { 'a-b': { c: { d: 'e' } } }; const options = { split: path => path.split(/[-\/]/), join: segs => segs.join('-') }; assert.strictEqual(get(fixture, 'a/b-c/d', options), 'e'); }); it('should support a default value as the last argument', function() { const fixture = { foo: { c: { d: 'e' } } }; assert.equal(get(fixture, 'foo.bar.baz', 'quz'), 'quz'); assert.equal(get(fixture, 'foo.bar.baz', true), true); assert.equal(get(fixture, 'foo.bar.baz', false), false); assert.equal(get(fixture, 'foo.bar.baz', null), null); }); it('should support options.default', function() { const fixture = { foo: { c: { d: 'e' } } }; assert.equal(get(fixture, 'foo.bar.baz', { default: 'qux' }), 'qux'); assert.equal(get(fixture, 'foo.bar.baz', { default: true }), true); assert.equal(get(fixture, 'foo.bar.baz', { default: false }), false); assert.equal(get(fixture, 'foo.bar.baz', { default: null }), null); assert.deepStrictEqual(get(fixture, 'foo.bar.baz', { default: { one: 'two' } }), { one: 'two' }); }); it('should support a custom function for validating the object', function() { const isEnumerable = Object.prototype.propertyIsEnumerable; const options = { isValid: function(key, obj) { return isEnumerable.call(obj, key); } }; const fixture = { 'a.b': { c: { d: 'e' } } }; assert.strictEqual(get(fixture, 'a.b.c.d', options), 'e'); }); it('should support nested keys with dots', function() { assert.strictEqual(get({ 'a.b.c': 'd' }, 'a.b.c'), 'd'); assert.strictEqual(get({ 'a.b': { c: 'd' } }, 'a.b.c'), 'd'); assert.strictEqual(get({ 'a.b': { c: { d: 'e' } } }, 'a.b.c.d'), 'e'); assert.strictEqual(get({ a: { b: { c: 'd' } } }, 'a.b.c'), 'd'); assert.strictEqual(get({ a: { 'b.c': 'd' } }, 'a.b.c'), 'd'); assert.strictEqual(get({ 'a.b.c.d': 'e' }, 'a.b.c.d'), 'e'); assert.strictEqual(get({ 'a.b.c.d': 'e' }, 'a.b.c'), undefined); assert.strictEqual(get({ 'a.b.c.d.e.f': 'g' }, 'a.b.c.d.e.f'), 'g'); assert.strictEqual(get({ 'a.b.c.d.e': { f: 'g' } }, 'a.b.c.d.e.f'), 'g'); assert.strictEqual(get({ 'a.b.c.d': { e: { f: 'g' } } }, 'a.b.c.d.e.f'), 'g'); assert.strictEqual(get({ 'a.b.c': { d: { e: { f: 'g' } } } }, 'a.b.c.d.e.f'), 'g'); assert.strictEqual(get({ 'a.b': { c: { d: { e: { f: 'g' } } } } }, 'a.b.c.d.e.f'), 'g'); assert.strictEqual(get({ a: { b: { c: { d: { e: { f: 'g' } } } } } }, 'a.b.c.d.e.f'), 'g'); assert.deepStrictEqual(get({ 'a.b.c.d.e': { f: 'g' } }, 'a.b.c.d.e'), { f: 'g' }); assert.deepStrictEqual(get({ 'a.b.c.d': { 'e.f': 'g' } }, 'a.b.c.d.e'), undefined); assert.deepStrictEqual(get({ 'a.b.c': { 'd.e.f': 'g' } }, 'a.b.c'), { 'd.e.f': 'g' }); assert.deepStrictEqual(get({ 'a.b': { 'c.d.e.f': 'g' } }, 'a.b'), { 'c.d.e.f': 'g' }); assert.deepStrictEqual(get({ a: { 'b.c.d.e.f': 'g' } }, 'a'), { 'b.c.d.e.f': 'g' }); assert.strictEqual(get({ 'a.b.c.d.e': { f: 'g' } }, 'a.b.c.d.e.f'), 'g'); assert.strictEqual(get({ 'a.b.c.d': { 'e.f': 'g' } }, 'a.b.c.d.e.f'), 'g'); assert.strictEqual(get({ 'a.b.c': { 'd.e.f': 'g' } }, 'a.b.c.d.e.f'), 'g'); assert.strictEqual(get({ 'a.b': { 'c.d.e.f': 'g' } }, 'a.b.c.d.e.f'), 'g'); assert.strictEqual(get({ a: { 'b.c.d.e.f': 'g' } }, 'a.b.c.d.e.f'), 'g'); assert.strictEqual(get({ 'a.b': { 'c.d': { 'e.f': 'g' } } }, 'a.b.c.d.e.f'), 'g'); assert.strictEqual(get({ 'a.b': { c: { 'd.e.f': 'g' } } }, 'a.b.c.d.e.f'), 'g'); assert.strictEqual(get({ a: { 'b.c.d.e': { f: 'g' } } }, 'a.b.c.d.e.f'), 'g'); assert.strictEqual(get({ a: { 'b.c.d': { 'e.f': 'g' } } }, 'a.b.c.d.e.f'), 'g'); assert.strictEqual(get({ a: { 'b.c': { 'd.e.f': 'g' } } }, 'a.b.c.d.e.f'), 'g'); assert.strictEqual(get({ a: { b: { 'c.d.e.f': 'g' } } }, 'a.b.c.d.e.f'), 'g'); }); it('should support return default when options.isValid returns false', function() { const fixture = { foo: { bar: { baz: 'qux' }, 'a.b.c': 'xyx', yyy: 'zzz' } }; const options = val => { return Object.assign( {}, { default: val, isValid: function(key) { return key !== 'bar' && key !== 'a.b.c'; } } ); }; assert.equal(get(fixture, 'foo.bar.baz', options('fez')), 'fez'); assert.equal(get(fixture, 'foo.bar.baz', options(true)), true); assert.equal(get(fixture, 'foo.bar.baz', options(false)), false); assert.equal(get(fixture, 'foo.bar.baz', options(null)), null); assert.equal(get(fixture, 'foo.a.b.c', options('fez')), 'fez'); assert.equal(get(fixture, 'foo.a.b.c', options(true)), true); assert.equal(get(fixture, 'foo.a.b.c', options(false)), false); assert.equal(get(fixture, 'foo.a.b.c', options(null)), null); assert.equal(get(fixture, 'foo.yyy', options('fez')), 'zzz'); }); it('should get a value from an array', function() { const fixture = { a: { paths: ['a.txt', 'a.js', 'a.hbs'] }, b: { paths: { '0': 'b.txt', '1': 'b.js', '2': 'b.hbs', 3: 'b3.hbs' } } }; assert.strictEqual(get(fixture, 'a.paths.0'), 'a.txt'); assert.strictEqual(get(fixture, 'a.paths.1'), 'a.js'); assert.strictEqual(get(fixture, 'a.paths.2'), 'a.hbs'); assert.strictEqual(get(fixture, 'b.paths.0'), 'b.txt'); assert.strictEqual(get(fixture, 'b.paths.1'), 'b.js'); assert.strictEqual(get(fixture, 'b.paths.2'), 'b.hbs'); assert.strictEqual(get(fixture, 'b.paths.3'), 'b3.hbs'); }); it('should get a value from an object in an array', function() { assert.strictEqual(get({ a: { b: [{ c: 'd' }] } }, 'a.b.0.c'), 'd'); assert.strictEqual(get({ a: { b: [{ c: 'd' }, { e: 'f' }] } }, 'a.b.1.e'), 'f'); }); it('should return `undefined` if the path is not found', function() { const fixture = { a: { b: {} } }; assert.strictEqual(get(fixture, 'a.b.c'), undefined); assert.strictEqual(get(fixture, 'a.b.c.d'), undefined); }); it('should get the specified property', function() { assert.deepStrictEqual(get({ a: 'aaa', b: 'b' }, 'a'), 'aaa'); assert.deepStrictEqual(get({ first: 'Jon', last: 'Schlinkert' }, 'first'), 'Jon'); assert.deepStrictEqual(get({ locals: { a: 'a' }, options: { b: 'b' } }, 'locals'), { a: 'a' }); }); it('should support passing a property formatted as an array', function() { assert.deepStrictEqual(get({ a: 'aaa', b: 'b' }, ['a']), 'aaa'); assert.deepStrictEqual(get({ a: { b: { c: 'd' } } }, ['a', 'b', 'c']), 'd'); assert.deepStrictEqual(get({ first: 'Harry', last: 'Potter' }, ['first']), 'Harry'); assert.deepStrictEqual(get({ locals: { a: 'a' }, options: { b: 'b' } }, ['locals']), { a: 'a' }); }); it('should support escaped dots', function() { assert.deepStrictEqual(get({ 'a.b': 'a', b: { c: 'd' } }, 'a\\.b'), 'a'); assert.deepStrictEqual(get({ 'a.b': { b: { c: 'd' } } }, 'a\\.b.b.c'), 'd'); }); it('should get the value of a deeply nested property', function() { assert.strictEqual(get({ a: { b: 'c', c: { d: 'e', e: 'f', g: { h: 'i' } } } }, 'a.c.g.h'), 'i'); }); it('should return the entire object if no property is passed', function() { assert.deepStrictEqual(get({ a: 'a', b: { c: 'd' } }), { a: 'a', b: { c: 'd' } }); }); }); /** * These tests are from the "dot-prop" library */ describe('dot-prop tests:', function() { it('should pass dot-prop tests', function() { const f1 = { foo: { bar: 1 } }; assert.deepStrictEqual(get(f1), f1); f1[''] = 'foo'; assert.deepStrictEqual(get(f1, ''), 'foo'); assert.deepStrictEqual(get(f1, 'foo'), f1.foo); assert.deepStrictEqual(get({ foo: 1 }, 'foo'), 1); assert.deepStrictEqual(get({ foo: null }, 'foo'), null); assert.deepStrictEqual(get({ foo: undefined }, 'foo'), undefined); assert.deepStrictEqual(get({ foo: { bar: true } }, 'foo.bar'), true); assert.deepStrictEqual(get({ foo: { bar: { baz: true } } }, 'foo.bar.baz'), true); assert.deepStrictEqual(get({ foo: { bar: { baz: null } } }, 'foo.bar.baz'), null); assert.deepStrictEqual(get({ '\\': true }, '\\'), true); assert.deepStrictEqual(get({ '\\foo': true }, '\\foo'), true); assert.deepStrictEqual(get({ 'bar\\': true }, 'bar\\'), true); assert.deepStrictEqual(get({ 'foo\\bar': true }, 'foo\\bar'), true); assert.deepStrictEqual(get({ '\\.foo': true }, '\\\\.foo'), true); assert.deepStrictEqual(get({ 'bar\\.': true }, 'bar\\\\.'), true); assert.deepStrictEqual(get({ 'foo\\.bar': true }, 'foo\\\\.bar'), true); assert.deepStrictEqual(get({ foo: 1 }, 'foo.bar'), undefined); function fn() {} fn.foo = { bar: 1 }; assert.deepStrictEqual(get(fn), fn); assert.deepStrictEqual(get(fn, 'foo'), fn.foo); assert.deepStrictEqual(get(fn, 'foo.bar'), 1); const f3 = { foo: null }; assert.deepStrictEqual(get(f3, 'foo.bar'), undefined); assert.deepStrictEqual(get(f3, 'foo.bar', 'some value'), 'some value'); assert.deepStrictEqual(get({ 'foo.baz': { bar: true } }, 'foo\\.baz.bar'), true); assert.deepStrictEqual(get({ 'fo.ob.az': { bar: true } }, 'fo\\.ob\\.az.bar'), true); assert.deepStrictEqual(get(null, 'foo.bar', false), false); assert.deepStrictEqual(get('foo', 'foo.bar', false), false); assert.deepStrictEqual(get([], 'foo.bar', false), false); assert.deepStrictEqual(get(undefined, 'foo.bar', false), false); }); it('should use a custom options.isValid function', function() { const isEnumerable = Object.prototype.propertyIsEnumerable; const options = { isValid: (key, obj) => isEnumerable.call(obj, key) }; const target = {}; Object.defineProperty(target, 'foo', { value: 'bar', enumerable: false }); assert.deepStrictEqual(get(target, 'foo', options), undefined); assert.deepStrictEqual(get({}, 'hasOwnProperty', options), undefined); }); it('should return a default value', function() { assert.deepStrictEqual(get({ foo: { bar: 'a' } }, 'foo.fake'), undefined); assert.deepStrictEqual(get({ foo: { bar: 'a' } }, 'foo.fake.fake2'), undefined); assert.deepStrictEqual(get({ foo: { bar: 'a' } }, 'foo.fake.fake2', 'some value'), 'some value'); }); it('should pass all of the dot-prop tests', function() { const f1 = { foo: { bar: 1 } }; assert.deepStrictEqual(get(f1), f1); assert.deepStrictEqual(get(f1, 'foo'), f1.foo); assert.deepStrictEqual(get({ foo: 1 }, 'foo'), 1); assert.deepStrictEqual(get({ foo: null }, 'foo'), null); assert.deepStrictEqual(get({ foo: undefined }, 'foo'), undefined); assert.deepStrictEqual(get({ foo: { bar: true } }, 'foo.bar'), true); assert.deepStrictEqual(get({ foo: { bar: { baz: true } } }, 'foo.bar.baz'), true); assert.deepStrictEqual(get({ foo: { bar: { baz: null } } }, 'foo.bar.baz'), null); assert.deepStrictEqual(get({ foo: { bar: 'a' } }, 'foo.fake.fake2'), undefined); }); }); /** * These tests are from the "object-path" library */ describe('object-path .get tests', function() { function getTestObj() { return { a: 'b', b: { c: [], d: ['a', 'b'], e: [{}, { f: 'g' }], f: 'i' } }; } it('should return the value using unicode key', function() { const obj = { '15\u00f8C': { '3\u0111': 1 } }; assert.equal(get(obj, '15\u00f8C.3\u0111'), 1); assert.equal(get(obj, ['15\u00f8C', '3\u0111']), 1); }); it('should return the value using dot in key (with array of segments)', function() { const obj = { 'a.b': { 'looks.like': 1 } }; assert.equal(get(obj, ['a.b', 'looks.like']), 1); }); // object-path fails this test it('should return the value using dot in key', function() { const obj = { 'a.b': { 'looks.like': 1 } }; assert.equal(get(obj, 'a.b.looks.like'), 1); }); it('should return the value under shallow object', function() { const obj = getTestObj(); assert.equal(get(obj, 'a'), 'b'); assert.equal(get(obj, ['a']), 'b'); }); it('should work with number path', function() { const obj = getTestObj(); assert.equal(get(obj.b.d, 0), 'a'); assert.equal(get(obj.b, 0), undefined); }); it('should return the value under deep object', function() { const obj = getTestObj(); assert.equal(get(obj, 'b.f'), 'i'); assert.equal(get(obj, ['b', 'f']), 'i'); }); it('should return the value under array', function() { const obj = getTestObj(); assert.equal(get(obj, 'b.d.0'), 'a'); assert.equal(get(obj, ['b', 'd', 0]), 'a'); }); it('should return the value under array deep', function() { const obj = getTestObj(); assert.equal(get(obj, 'b.e.1.f'), 'g'); assert.equal(get(obj, ['b', 'e', 1, 'f']), 'g'); }); it('should return undefined for missing values under object', function() { const obj = getTestObj(); assert.equal(get(obj, 'a.b'), undefined); assert.equal(get(obj, ['a', 'b']), undefined); }); it('should return undefined for missing values under array', function() { const obj = getTestObj(); assert.equal(get(obj, 'b.d.5'), undefined); assert.equal(get(obj, ['b', 'd', '5']), undefined); }); it('should return the value under integer-like key', function() { const obj = { '1a': 'foo' }; assert.equal(get(obj, '1a'), 'foo'); assert.equal(get(obj, ['1a']), 'foo'); }); it('should return the default value when the key doesnt exist', function() { const obj = { '1a': 'foo' }; assert.equal(get(obj, '1b', null), null); assert.equal(get(obj, ['1b'], null), null); }); // this test differs from behavior in object-path. I was unable to figure // out exactly how the default values work in object-path. it('should return the default value when path is empty', function() { const obj = { '1a': 'foo' }; assert.deepStrictEqual(get(obj, '', null), null); assert.deepStrictEqual(get(obj, []), undefined); assert.equal(get({}, ['1'], 'foo'), 'foo'); }); it('should return the default value when object is null or undefined', function() { assert.deepStrictEqual(get(null, 'test', 'a'), 'a'); assert.deepStrictEqual(get(undefined, 'test', 'a'), 'a'); }); it('should not fail on an object with a null prototype', function assertSuccessForObjWithNullProto() { const foo = 'FOO'; const objWithNullProto = Object.create(null); objWithNullProto.foo = foo; assert.equal(get(objWithNullProto, 'foo'), foo); }); // this differs from object-path, which does not allow // the user to get non-own properties for some reason. it('should get non-"own" properties', function() { const Base = function(enabled) {}; Base.prototype = { one: { two: true } }; const Extended = function() { Base.call(this, true); }; Extended.prototype = Object.create(Base.prototype); const extended = new Extended(); assert.equal(get(extended, ['one', 'two']), true); extended.enabled = true; assert.equal(get(extended, 'enabled'), true); assert.deepStrictEqual(get(extended, 'one'), { two: true }); }); }); describe('deep-property unit tests', function() { it('should handle invalid input', function() { const a = undefined; const b = {}; assert.equal(get(a, 'sample'), undefined); assert.deepStrictEqual(get(b, undefined), {}); assert.deepStrictEqual(get(b, ''), undefined); assert.deepStrictEqual(get(b, '...'), undefined); }); it('should get shallow properties', function() { const fn = function() {}; const a = { sample: 'string', example: fn, unknown: undefined }; assert.equal(get(a, 'example'), fn); assert.equal(get(a, 'sample'), 'string'); assert.equal(get(a, 'unknown'), undefined); assert.equal(get(a, 'invalid'), undefined); }); it('should get deep properties', function() { const a = { b: { example: { type: 'vegetable' } }, c: { example: { type: 'mineral' } } }; assert.equal(get(a, 'b.example.type'), 'vegetable'); assert.equal(get(a, 'c.example.type'), 'mineral'); assert.equal(get(a, 'c.gorky.type'), undefined); }); it('should get properties on non-objects', function() { const fn = function() {}; // the commented out lines are from from the "deep-property" lib, // but it's invalid javascript. This is a good example of why it's always // better to use "use strict" (and lint your code). // const str = 'An example string'; // const num = 42; fn.path = { to: { property: 'string' } }; // str.path = { to: { property: 'string' } }; // num.path = { to: { property: 'string' } }; assert.equal(get(fn, 'path.to.property'), 'string'); // assert.equal(get(str, 'path.to.property'), undefined); // assert.equal(get(num, 'path.to.property'), undefined); }); }); };