@blakek/deep
Advanced tools
Comparing version 1.0.0 to 1.0.2
@@ -159,2 +159,22 @@ 'use strict'; | ||
const NotFound = Symbol('value not found'); | ||
function traverseObject(object, path) { | ||
// If the path has been exhausted, return the current object | ||
if (path.length === 0) { | ||
return object; | ||
} // If the value could not be found, return `defaultValue` | ||
if (!isObject(object)) { | ||
return NotFound; | ||
} | ||
const [key, ...keys] = path; // Search deeper in the object | ||
if (key in object) { | ||
return traverseObject(object[key], keys); | ||
} // The key was not found in the object. | ||
return NotFound; | ||
} | ||
function get(object, path, defaultValue) { | ||
@@ -201,23 +221,3 @@ if (path === undefined) return object; | ||
} | ||
function traverseObject(object, path) { | ||
// If the path has been exhausted, return the current object | ||
if (path.length === 0) { | ||
return object; | ||
} // If the value could not be found, return `defaultValue` | ||
if (!isObject(object)) { | ||
return NotFound; | ||
} | ||
const [key, ...keys] = path; // Search deeper in the object | ||
if (key in object) { | ||
return traverseObject(object[key], keys); | ||
} // The key was not found in the object. | ||
return NotFound; | ||
} | ||
exports.get = get; | ||
@@ -224,0 +224,0 @@ exports.has = has; |
@@ -1,2 +0,3 @@ | ||
import { Path } from 'pathington'; | ||
export declare type Path = Array<number | string> | string; | ||
export declare function traverseObject(object: any, path: string[]): any; | ||
export declare function get(object: any, path?: Path, defaultValue?: any): any; | ||
@@ -6,2 +7,1 @@ export declare function has(object: any, path: Path): boolean; | ||
export declare function set(object: any, path: Path, value: any): any; | ||
export declare function traverseObject(object: any, path: string[]): any; |
@@ -155,2 +155,22 @@ /** | ||
const NotFound = Symbol('value not found'); | ||
function traverseObject(object, path) { | ||
// If the path has been exhausted, return the current object | ||
if (path.length === 0) { | ||
return object; | ||
} // If the value could not be found, return `defaultValue` | ||
if (!isObject(object)) { | ||
return NotFound; | ||
} | ||
const [key, ...keys] = path; // Search deeper in the object | ||
if (key in object) { | ||
return traverseObject(object[key], keys); | ||
} // The key was not found in the object. | ||
return NotFound; | ||
} | ||
function get(object, path, defaultValue) { | ||
@@ -197,23 +217,3 @@ if (path === undefined) return object; | ||
} | ||
function traverseObject(object, path) { | ||
// If the path has been exhausted, return the current object | ||
if (path.length === 0) { | ||
return object; | ||
} // If the value could not be found, return `defaultValue` | ||
if (!isObject(object)) { | ||
return NotFound; | ||
} | ||
const [key, ...keys] = path; // Search deeper in the object | ||
if (key in object) { | ||
return traverseObject(object[key], keys); | ||
} // The key was not found in the object. | ||
return NotFound; | ||
} | ||
export { get, has, remove, set, traverseObject }; |
@@ -181,2 +181,24 @@ (function (global, factory) { | ||
function traverseObject(object, path) { | ||
// If the path has been exhausted, return the current object | ||
if (path.length === 0) { | ||
return object; | ||
} // If the value could not be found, return `defaultValue` | ||
if (!isObject(object)) { | ||
return NotFound; | ||
} | ||
var key = path[0], | ||
keys = path.slice(1); // Search deeper in the object | ||
if (key in object) { | ||
return traverseObject(object[key], keys); | ||
} // The key was not found in the object. | ||
return NotFound; | ||
} | ||
function get(object, path, defaultValue) { | ||
@@ -226,24 +248,2 @@ if (path === undefined) return object; | ||
} | ||
function traverseObject(object, path) { | ||
// If the path has been exhausted, return the current object | ||
if (path.length === 0) { | ||
return object; | ||
} // If the value could not be found, return `defaultValue` | ||
if (!isObject(object)) { | ||
return NotFound; | ||
} | ||
var key = path[0], | ||
keys = path.slice(1); // Search deeper in the object | ||
if (key in object) { | ||
return traverseObject(object[key], keys); | ||
} // The key was not found in the object. | ||
return NotFound; | ||
} | ||
}); |
{ | ||
"name": "@blakek/deep", | ||
"version": "1.0.0", | ||
"version": "1.0.2", | ||
"main": "dist/index.cjs.js", | ||
@@ -5,0 +5,0 @@ "module": "dist/index.esm.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
118375