pax_global_header00006660000000000000000000000064135570440350014520gustar00rootroot0000000000000052 comment=282e984eed35b62321966f21b8db96ab70221ebc dot-prop-5.2.0/000077500000000000000000000000001355704403500132705ustar00rootroot00000000000000dot-prop-5.2.0/.editorconfig000066400000000000000000000002571355704403500157510ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 dot-prop-5.2.0/.gitattributes000066400000000000000000000000231355704403500161560ustar00rootroot00000000000000* text=auto eol=lf dot-prop-5.2.0/.github/000077500000000000000000000000001355704403500146305ustar00rootroot00000000000000dot-prop-5.2.0/.github/funding.yml000066400000000000000000000001621355704403500170040ustar00rootroot00000000000000github: sindresorhus open_collective: sindresorhus tidelift: npm/dot-prop custom: https://sindresorhus.com/donate dot-prop-5.2.0/.github/security.md000066400000000000000000000002631355704403500170220ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. dot-prop-5.2.0/.gitignore000066400000000000000000000000271355704403500152570ustar00rootroot00000000000000node_modules yarn.lock dot-prop-5.2.0/.npmrc000066400000000000000000000000231355704403500144030ustar00rootroot00000000000000package-lock=false dot-prop-5.2.0/.travis.yml000066400000000000000000000000651355704403500154020ustar00rootroot00000000000000language: node_js node_js: - '12' - '10' - '8' dot-prop-5.2.0/bench.js000066400000000000000000000077521355704403500147200ustar00rootroot00000000000000'use strict'; const Benchmark = require('benchmark'); const dotProp = require('.'); const suite = new Benchmark.Suite(); suite .add('get', () => { const fixture1 = {foo: {bar: 1}}; dotProp.get(fixture1); fixture1[''] = 'foo'; dotProp.get(fixture1, ''); dotProp.get(fixture1, 'foo'); dotProp.get({foo: 1}, 'foo'); dotProp.get({foo: null}, 'foo'); dotProp.get({foo: undefined}, 'foo'); dotProp.get({foo: {bar: true}}, 'foo.bar'); dotProp.get({foo: {bar: {baz: true}}}, 'foo.bar.baz'); dotProp.get({foo: {bar: {baz: null}}}, 'foo.bar.baz'); dotProp.get({foo: {bar: 'a'}}, 'foo.fake'); dotProp.get({foo: {bar: 'a'}}, 'foo.fake.fake2'); dotProp.get({'\\': true}, '\\'); dotProp.get({'\\foo': true}, '\\foo'); dotProp.get({'bar\\': true}, 'bar\\'); dotProp.get({'foo\\bar': true}, 'foo\\bar'); dotProp.get({'\\.foo': true}, '\\\\.foo'); dotProp.get({'bar\\.': true}, 'bar\\\\.'); dotProp.get({'foo\\.bar': true}, 'foo\\\\.bar'); const fixture2 = {}; Object.defineProperty(fixture2, 'foo', { value: 'bar', enumerable: false }); dotProp.get(fixture2, 'foo'); dotProp.get({}, 'hasOwnProperty'); function fn() {} fn.foo = {bar: 1}; dotProp.get(fn); dotProp.get(fn, 'foo'); dotProp.get(fn, 'foo.bar'); const fixture3 = {foo: null}; dotProp.get(fixture3, 'foo.bar'); dotProp.get({'foo.baz': {bar: true}}, 'foo\\.baz.bar'); dotProp.get({'fo.ob.az': {bar: true}}, 'fo\\.ob\\.az.bar'); dotProp.get(null, 'foo.bar', false); dotProp.get('foo', 'foo.bar', false); dotProp.get([], 'foo.bar', false); dotProp.get(undefined, 'foo.bar', false); }) .add('set', () => { const func = () => 'test'; let fixture1 = {}; dotProp.set(fixture1, 'foo', 2); fixture1 = {foo: {bar: 1}}; dotProp.set(fixture1, 'foo.bar', 2); dotProp.set(fixture1, 'foo.bar.baz', 3); dotProp.set(fixture1, 'foo.bar', 'test'); dotProp.set(fixture1, 'foo.bar', null); dotProp.set(fixture1, 'foo.bar', false); dotProp.set(fixture1, 'foo.bar', undefined); dotProp.set(fixture1, 'foo.fake.fake2', 'fake'); dotProp.set(fixture1, 'foo.function', func); function fn() {} dotProp.set(fn, 'foo.bar', 1); fixture1.fn = fn; dotProp.set(fixture1, 'fn.bar.baz', 2); const fixture2 = {foo: null}; dotProp.set(fixture2, 'foo.bar', 2); const fixture3 = {}; dotProp.set(fixture3, '', 3); dotProp.set(fixture1, 'foo\\.bar.baz', true); dotProp.set(fixture1, 'fo\\.ob\\.ar.baz', true); }) .add('delete', () => { const func = () => 'test'; func.foo = 'bar'; const inner = { a: 'a', b: 'b', c: 'c', func }; const fixture1 = { foo: { bar: { baz: inner } }, top: { dog: 'sindre' } }; dotProp.delete(fixture1, 'foo.bar.baz.c'); dotProp.delete(fixture1, 'top'); dotProp.delete(fixture1, 'foo.bar.baz.func.foo'); dotProp.delete(fixture1, 'foo.bar.baz.func'); dotProp.set(fixture1, 'foo\\.bar.baz', true); dotProp.delete(fixture1, 'foo\\.bar.baz'); const fixture2 = {}; dotProp.set(fixture2, 'foo.bar\\.baz', true); dotProp.delete(fixture2, 'foo.bar\\.baz'); fixture2.dotted = { sub: { 'dotted.prop': 'foo', other: 'prop' } }; dotProp.delete(fixture2, 'dotted.sub.dotted\\.prop'); }) .add('has', () => { const fixture1 = {foo: {bar: 1}}; dotProp.has(fixture1); dotProp.has(fixture1, 'foo'); dotProp.has({foo: 1}, 'foo'); dotProp.has({foo: null}, 'foo'); dotProp.has({foo: undefined}, 'foo'); dotProp.has({foo: {bar: true}}, 'foo.bar'); dotProp.has({foo: {bar: {baz: true}}}, 'foo.bar.baz'); dotProp.has({foo: {bar: {baz: null}}}, 'foo.bar.baz'); dotProp.has({foo: {bar: 'a'}}, 'foo.fake.fake2'); function fn() {} fn.foo = {bar: 1}; dotProp.has(fn); dotProp.has(fn, 'foo'); dotProp.has(fn, 'foo.bar'); dotProp.has({'foo.baz': {bar: true}}, 'foo\\.baz.bar'); dotProp.has({'fo.ob.az': {bar: true}}, 'fo\\.ob\\.az.bar'); }) .on('cycle', event => { console.log(String(event.target)); }) .on('complete', () => { console.log('Finished'); }) .run({async: true}); dot-prop-5.2.0/index.d.ts000066400000000000000000000046141355704403500151760ustar00rootroot00000000000000declare const dotProp: { /** @param object - Object to get the `path` value. @param path - Path of the property in the object, using `.` to separate each nested key. Use `\\.` if you have a `.` in the key. @param defaultValue - Default value. @example ``` import dotProp = require('dot-prop'); dotProp.get({foo: {bar: 'unicorn'}}, 'foo.bar'); //=> 'unicorn' dotProp.get({foo: {bar: 'a'}}, 'foo.notDefined.deep'); //=> undefined dotProp.get({foo: {bar: 'a'}}, 'foo.notDefined.deep', 'default value'); //=> 'default value' dotProp.get({foo: {'dot.dot': 'unicorn'}}, 'foo.dot\\.dot'); //=> 'unicorn' ``` */ get( object: {[key: string]: any} | undefined, path: string ): T | undefined; get( object: {[key: string]: any} | undefined, path: string, defaultValue: T ): T; /** @param object - Object to set the `path` value. @param path - Path of the property in the object, using `.` to separate each nested key. Use `\\.` if you have a `.` in the key. @param value - Value to set at `path`. @example ``` import dotProp = require('dot-prop'); const object = {foo: {bar: 'a'}}; dotProp.set(object, 'foo.bar', 'b'); console.log(object); //=> {foo: {bar: 'b'}} const foo = dotProp.set({}, 'foo.bar', 'c'); console.log(foo); //=> {foo: {bar: 'c'}} dotProp.set(object, 'foo.baz', 'x'); console.log(object); //=> {foo: {bar: 'b', baz: 'x'}} ``` */ set( object: T, path: string, value: unknown ): T; /** @param object - Object to test the `path` value. @param path - Path of the property in the object, using `.` to separate each nested key. Use `\\.` if you have a `.` in the key. @example ``` import dotProp = require('dot-prop'); dotProp.has({foo: {bar: 'unicorn'}}, 'foo.bar'); //=> true ``` */ has(object: {[key: string]: any} | undefined, path: string): boolean; /** @param object - Object to delete the `path` value. @param path - Path of the property in the object, using `.` to separate each nested key. Use `\\.` if you have a `.` in the key. @example ``` import dotProp = require('dot-prop'); const object = {foo: {bar: 'a'}}; dotProp.delete(object, 'foo.bar'); console.log(object); //=> {foo: {}} object.foo.bar = {x: 'y', y: 'x'}; dotProp.delete(object, 'foo.bar.x'); console.log(object); //=> {foo: {bar: {y: 'x'}}} ``` */ delete(object: {[key: string]: any}, path: string): void; }; export = dotProp; dot-prop-5.2.0/index.js000066400000000000000000000053011355704403500147340ustar00rootroot00000000000000'use strict'; const isObj = require('is-obj'); const disallowedKeys = [ '__proto__', 'prototype', 'constructor' ]; const isValidPath = pathSegments => !pathSegments.some(segment => disallowedKeys.includes(segment)); function getPathSegments(path) { const pathArray = path.split('.'); const parts = []; for (let i = 0; i < pathArray.length; i++) { let p = pathArray[i]; while (p[p.length - 1] === '\\' && pathArray[i + 1] !== undefined) { p = p.slice(0, -1) + '.'; p += pathArray[++i]; } parts.push(p); } if (!isValidPath(parts)) { return []; } return parts; } module.exports = { get(object, path, value) { if (!isObj(object) || typeof path !== 'string') { return value === undefined ? object : value; } const pathArray = getPathSegments(path); if (pathArray.length === 0) { return; } for (let i = 0; i < pathArray.length; i++) { if (!Object.prototype.propertyIsEnumerable.call(object, pathArray[i])) { return value; } object = object[pathArray[i]]; if (object === undefined || object === null) { // `object` is either `undefined` or `null` so we want to stop the loop, and // if this is not the last bit of the path, and // if it did't return `undefined` // it would return `null` if `object` is `null` // but we want `get({foo: null}, 'foo.bar')` to equal `undefined`, or the supplied value, not `null` if (i !== pathArray.length - 1) { return value; } break; } } return object; }, set(object, path, value) { if (!isObj(object) || typeof path !== 'string') { return object; } const root = object; const pathArray = getPathSegments(path); for (let i = 0; i < pathArray.length; i++) { const p = pathArray[i]; if (!isObj(object[p])) { object[p] = {}; } if (i === pathArray.length - 1) { object[p] = value; } object = object[p]; } return root; }, delete(object, path) { if (!isObj(object) || typeof path !== 'string') { return; } const pathArray = getPathSegments(path); for (let i = 0; i < pathArray.length; i++) { const p = pathArray[i]; if (i === pathArray.length - 1) { delete object[p]; return; } object = object[p]; if (!isObj(object)) { return; } } }, has(object, path) { if (!isObj(object) || typeof path !== 'string') { return false; } const pathArray = getPathSegments(path); if (pathArray.length === 0) { return false; } // eslint-disable-next-line unicorn/no-for-loop for (let i = 0; i < pathArray.length; i++) { if (isObj(object)) { if (!(pathArray[i] in object)) { return false; } object = object[pathArray[i]]; } else { return false; } } return true; } }; dot-prop-5.2.0/index.test-d.ts000066400000000000000000000013121355704403500161430ustar00rootroot00000000000000import {expectType} from 'tsd'; import dotProp = require('.'); expectType(dotProp.get({foo: {bar: 'unicorn'}}, 'foo.bar')); expectType(dotProp.get({foo: {bar: 'unicorn'}}, 'foo.bar')); expectType(dotProp.get({foo: {bar: 'a'}}, 'foo.notDefined.deep')); expectType( dotProp.get({foo: {bar: 'a'}}, 'foo.notDefined.deep', 'default value') ); expectType( dotProp.get({foo: {'dot.dot': 'unicorn'}}, 'foo.dot\\.dot') ); const object = {foo: {bar: 'a'}}; expectType(dotProp.set(object, 'foo.bar', 'b')); expectType(dotProp.has({foo: {bar: 'unicorn'}}, 'foo.bar')); expectType(dotProp.delete({foo: {bar: 'a'}}, 'foo.bar')); dot-prop-5.2.0/license000066400000000000000000000021251355704403500146350ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (sindresorhus.com) 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. dot-prop-5.2.0/package.json000066400000000000000000000013521355704403500155570ustar00rootroot00000000000000{ "name": "dot-prop", "version": "5.2.0", "description": "Get, set, or delete a property from a nested object using a dot path", "license": "MIT", "repository": "sindresorhus/dot-prop", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=8" }, "scripts": { "test": "xo && ava && tsd", "bench": "node bench.js" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "object", "prop", "property", "dot", "path", "get", "set", "delete", "access", "notation", "dotty" ], "dependencies": { "is-obj": "^2.0.0" }, "devDependencies": { "ava": "^2.1.0", "benchmark": "^2.1.4", "tsd": "^0.7.2", "xo": "^0.25.3" } } dot-prop-5.2.0/readme.md000066400000000000000000000044761355704403500150620ustar00rootroot00000000000000# dot-prop [![Build Status](https://travis-ci.org/sindresorhus/dot-prop.svg?branch=master)](https://travis-ci.org/sindresorhus/dot-prop) > Get, set, or delete a property from a nested object using a dot path ## Install ``` $ npm install dot-prop ``` ## Usage ```js const dotProp = require('dot-prop'); // Getter dotProp.get({foo: {bar: 'unicorn'}}, 'foo.bar'); //=> 'unicorn' dotProp.get({foo: {bar: 'a'}}, 'foo.notDefined.deep'); //=> undefined dotProp.get({foo: {bar: 'a'}}, 'foo.notDefined.deep', 'default value'); //=> 'default value' dotProp.get({foo: {'dot.dot': 'unicorn'}}, 'foo.dot\\.dot'); //=> 'unicorn' // Setter const object = {foo: {bar: 'a'}}; dotProp.set(object, 'foo.bar', 'b'); console.log(object); //=> {foo: {bar: 'b'}} const foo = dotProp.set({}, 'foo.bar', 'c'); console.log(foo); //=> {foo: {bar: 'c'}} dotProp.set(object, 'foo.baz', 'x'); console.log(object); //=> {foo: {bar: 'b', baz: 'x'}} // Has dotProp.has({foo: {bar: 'unicorn'}}, 'foo.bar'); //=> true // Deleter const object = {foo: {bar: 'a'}}; dotProp.delete(object, 'foo.bar'); console.log(object); //=> {foo: {}} object.foo.bar = {x: 'y', y: 'x'}; dotProp.delete(object, 'foo.bar.x'); console.log(object); //=> {foo: {bar: {y: 'x'}}} ``` ## API ### get(object, path, defaultValue?) ### set(object, path, value) Returns the object. ### has(object, path) ### delete(object, path) #### object Type: `object` Object to get, set, or delete the `path` value. You are allowed to pass in `undefined` as the object to the `get` and `has` functions. #### path Type: `string` Path of the property in the object, using `.` to separate each nested key. Use `\\.` if you have a `.` in the key. The following path components are invalid and results in `undefined` being returned: `__proto__`, `prototype`, `constructor`. #### value Type: `unknown` Value to set at `path`. #### defaultValue Type: `unknown` Default value. ---
Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
dot-prop-5.2.0/test.js000066400000000000000000000141261355704403500146110ustar00rootroot00000000000000import test from 'ava'; import dotProp from '.'; test('get', t => { const fixture1 = {foo: {bar: 1}}; t.is(dotProp.get(fixture1), fixture1); fixture1[''] = 'foo'; t.is(dotProp.get(fixture1, ''), 'foo'); t.is(dotProp.get(fixture1, 'foo'), fixture1.foo); t.is(dotProp.get({foo: 1}, 'foo'), 1); t.is(dotProp.get({foo: null}, 'foo'), null); t.is(dotProp.get({foo: undefined}, 'foo'), undefined); t.is(dotProp.get({foo: {bar: true}}, 'foo.bar'), true); t.is(dotProp.get({foo: {bar: {baz: true}}}, 'foo.bar.baz'), true); t.is(dotProp.get({foo: {bar: {baz: null}}}, 'foo.bar.baz'), null); t.is(dotProp.get({foo: {bar: 'a'}}, 'foo.fake'), undefined); t.is(dotProp.get({foo: {bar: 'a'}}, 'foo.fake.fake2'), undefined); t.is(dotProp.get({foo: {bar: 'a'}}, 'foo.fake.fake2', 'some value'), 'some value'); t.is(dotProp.get({'\\': true}, '\\'), true); t.is(dotProp.get({'\\foo': true}, '\\foo'), true); t.is(dotProp.get({'bar\\': true}, 'bar\\'), true); t.is(dotProp.get({'foo\\bar': true}, 'foo\\bar'), true); t.is(dotProp.get({'\\.foo': true}, '\\\\.foo'), true); t.is(dotProp.get({'bar\\.': true}, 'bar\\\\.'), true); t.is(dotProp.get({'foo\\.bar': true}, 'foo\\\\.bar'), true); t.is(dotProp.get({foo: 1}, 'foo.bar'), undefined); const fixture2 = {}; Object.defineProperty(fixture2, 'foo', { value: 'bar', enumerable: false }); t.is(dotProp.get(fixture2, 'foo'), undefined); t.is(dotProp.get({}, 'hasOwnProperty'), undefined); function fn() {} fn.foo = {bar: 1}; t.is(dotProp.get(fn), fn); t.is(dotProp.get(fn, 'foo'), fn.foo); t.is(dotProp.get(fn, 'foo.bar'), 1); const f3 = {foo: null}; t.is(dotProp.get(f3, 'foo.bar'), undefined); t.is(dotProp.get(f3, 'foo.bar', 'some value'), 'some value'); t.is(dotProp.get({'foo.baz': {bar: true}}, 'foo\\.baz.bar'), true); t.is(dotProp.get({'fo.ob.az': {bar: true}}, 'fo\\.ob\\.az.bar'), true); t.is(dotProp.get(null, 'foo.bar', false), false); t.is(dotProp.get('foo', 'foo.bar', false), false); t.is(dotProp.get([], 'foo.bar', false), false); t.is(dotProp.get(undefined, 'foo.bar', false), false); }); test('set', t => { const func = () => 'test'; let fixture1 = {}; const o1 = dotProp.set(fixture1, 'foo', 2); t.is(fixture1.foo, 2); t.is(o1, fixture1); fixture1 = {foo: {bar: 1}}; dotProp.set(fixture1, 'foo.bar', 2); t.is(fixture1.foo.bar, 2); dotProp.set(fixture1, 'foo.bar.baz', 3); t.is(fixture1.foo.bar.baz, 3); dotProp.set(fixture1, 'foo.bar', 'test'); t.is(fixture1.foo.bar, 'test'); dotProp.set(fixture1, 'foo.bar', null); t.is(fixture1.foo.bar, null); dotProp.set(fixture1, 'foo.bar', false); t.is(fixture1.foo.bar, false); dotProp.set(fixture1, 'foo.bar', undefined); t.is(fixture1.foo.bar, undefined); dotProp.set(fixture1, 'foo.fake.fake2', 'fake'); t.is(fixture1.foo.fake.fake2, 'fake'); dotProp.set(fixture1, 'foo.function', func); t.is(fixture1.foo.function, func); function fn() {} dotProp.set(fn, 'foo.bar', 1); t.is(fn.foo.bar, 1); fixture1.fn = fn; dotProp.set(fixture1, 'fn.bar.baz', 2); t.is(fixture1.fn.bar.baz, 2); const fixture2 = {foo: null}; dotProp.set(fixture2, 'foo.bar', 2); t.is(fixture2.foo.bar, 2); const fixture3 = {}; dotProp.set(fixture3, '', 3); t.is(fixture3[''], 3); dotProp.set(fixture1, 'foo\\.bar.baz', true); t.is(fixture1['foo.bar'].baz, true); dotProp.set(fixture1, 'fo\\.ob\\.ar.baz', true); t.is(fixture1['fo.ob.ar'].baz, true); const fixture4 = 'noobject'; const output4 = dotProp.set(fixture4, 'foo.bar', 2); t.is(fixture4, 'noobject'); t.is(output4, fixture4); }); test('delete', t => { const func = () => 'test'; func.foo = 'bar'; const inner = { a: 'a', b: 'b', c: 'c', func }; const fixture1 = { foo: { bar: { baz: inner } }, top: { dog: 'sindre' } }; t.is(fixture1.foo.bar.baz.c, 'c'); dotProp.delete(fixture1, 'foo.bar.baz.c'); t.is(fixture1.foo.bar.baz.c, undefined); t.is(fixture1.top.dog, 'sindre'); dotProp.delete(fixture1, 'top'); t.is(fixture1.top, undefined); t.is(fixture1.foo.bar.baz.func.foo, 'bar'); dotProp.delete(fixture1, 'foo.bar.baz.func.foo'); t.is(fixture1.foo.bar.baz.func.foo, undefined); t.is(fixture1.foo.bar.baz.func, func); dotProp.delete(fixture1, 'foo.bar.baz.func'); t.is(fixture1.foo.bar.baz.func, undefined); dotProp.set(fixture1, 'foo\\.bar.baz', true); t.is(fixture1['foo.bar'].baz, true); dotProp.delete(fixture1, 'foo\\.bar.baz'); t.is(fixture1['foo.bar'].baz, undefined); const fixture2 = {}; dotProp.set(fixture2, 'foo.bar\\.baz', true); t.is(fixture2.foo['bar.baz'], true); dotProp.delete(fixture2, 'foo.bar\\.baz'); t.is(fixture2.foo['bar.baz'], undefined); fixture2.dotted = { sub: { 'dotted.prop': 'foo', other: 'prop' } }; dotProp.delete(fixture2, 'dotted.sub.dotted\\.prop'); t.is(fixture2.dotted.sub['dotted.prop'], undefined); t.is(fixture2.dotted.sub.other, 'prop'); const fixture3 = {foo: null}; dotProp.delete(fixture3, 'foo.bar'); t.deepEqual(fixture3, {foo: null}); }); test('has', t => { const fixture1 = {foo: {bar: 1}}; t.is(dotProp.has(fixture1), false); t.is(dotProp.has(fixture1, 'foo'), true); t.is(dotProp.has({foo: 1}, 'foo'), true); t.is(dotProp.has({foo: null}, 'foo'), true); t.is(dotProp.has({foo: undefined}, 'foo'), true); t.is(dotProp.has({foo: {bar: true}}, 'foo.bar'), true); t.is(dotProp.has({foo: {bar: {baz: true}}}, 'foo.bar.baz'), true); t.is(dotProp.has({foo: {bar: {baz: null}}}, 'foo.bar.baz'), true); t.is(dotProp.has({foo: {bar: 'a'}}, 'foo.fake.fake2'), false); t.is(dotProp.has({foo: null}, 'foo.bar'), false); t.is(dotProp.has({foo: ''}, 'foo.bar'), false); function fn() {} fn.foo = {bar: 1}; t.is(dotProp.has(fn), false); t.is(dotProp.has(fn, 'foo'), true); t.is(dotProp.has(fn, 'foo.bar'), true); t.is(dotProp.has({'foo.baz': {bar: true}}, 'foo\\.baz.bar'), true); t.is(dotProp.has({'fo.ob.az': {bar: true}}, 'fo\\.ob\\.az.bar'), true); t.is(dotProp.has(undefined, 'fo\\.ob\\.az.bar'), false); }); test('prevent setting/getting `__proto__`', t => { dotProp.set({}, '__proto__.unicorn', '🦄'); t.not({}.unicorn, '🦄'); // eslint-disable-line no-use-extend-native/no-use-extend-native t.is(dotProp.get({}, '__proto__'), undefined); });