@hapi/hoek
Advanced tools
Comparing version 7.1.0 to 7.2.0
@@ -279,5 +279,12 @@ /** | ||
@default true | ||
*/ | ||
readonly functions?: boolean; | ||
/** | ||
If true, allows traversing Set and Map objects for properties. false will return undefined regardless of the Set or Map passed. | ||
@default false | ||
*/ | ||
readonly functions?: boolean; | ||
readonly iterables?: boolean; | ||
} | ||
@@ -284,0 +291,0 @@ } |
@@ -539,8 +539,10 @@ 'use strict'; | ||
let key = path[i]; | ||
const type = options.iterables && internals.iterables(ref); | ||
if (Array.isArray(ref)) { | ||
if (Array.isArray(ref) || | ||
type === 'set') { | ||
const number = Number(key); | ||
if (Number.isInteger(number) && number < 0) { | ||
key = ref.length + number; | ||
if (Number.isInteger(number)) { | ||
key = number < 0 ? ref.length + number : number; | ||
} | ||
@@ -550,4 +552,4 @@ } | ||
if (!ref || | ||
!((typeof ref === 'object' || typeof ref === 'function') && key in ref) || | ||
(typeof ref !== 'object' && options.functions === false)) { // Only object and function can have properties | ||
typeof ref === 'function' && options.functions === false || // Defaults to true | ||
!type && ref[key] === undefined) { | ||
@@ -560,3 +562,11 @@ exports.assert(!options.strict || i + 1 === path.length, 'Missing segment', key, 'in reach path ', chain); | ||
ref = ref[key]; | ||
if (!type) { | ||
ref = ref[key]; | ||
} | ||
else if (type === 'set') { | ||
ref = [...ref][key]; | ||
} | ||
else { // type === 'map' | ||
ref = ref.get(key); | ||
} | ||
} | ||
@@ -568,2 +578,14 @@ | ||
internals.iterables = function (ref) { | ||
if (ref instanceof Set) { | ||
return 'set'; | ||
} | ||
if (ref instanceof Map) { | ||
return 'map'; | ||
} | ||
}; | ||
exports.reachTemplate = function (obj, template, options) { | ||
@@ -570,0 +592,0 @@ |
{ | ||
"name": "@hapi/hoek", | ||
"description": "General purpose node utilities", | ||
"version": "7.1.0", | ||
"version": "7.2.0", | ||
"repository": "git://github.com/hapijs/hoek", | ||
@@ -6,0 +6,0 @@ "main": "lib/index.js", |
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
43874
1171