object-lib
Advanced tools
Comparing version
@@ -15,3 +15,3 @@ const BYPASS_PROPS = [ | ||
// Proxy that errors when accessing non-existent properties | ||
const SafeProxy = (tgt, ctx, path = '') => { | ||
const SafeProxy = (tgt, ctx, key = '') => { | ||
// eslint-disable-next-line @blackflux/rules/prevent-typeof-object | ||
@@ -29,7 +29,7 @@ if (tgt === null || typeof tgt !== 'object') { | ||
const propStr = typeof prop === 'symbol' ? prop.toString() : String(prop); | ||
const currentPath = path ? `${path}.${propStr}` : propStr; | ||
const currentKey = key ? `${key}.${propStr}` : propStr; | ||
const found = prop in target; | ||
if (!found && ctx?.throw !== false) { | ||
throw new Error(`Property '${currentPath}' does not exist`); | ||
throw new Error(`Property '${currentKey}' does not exist`); | ||
} | ||
@@ -40,3 +40,3 @@ | ||
if (typeof ctx?.cb === 'function') { | ||
value = ctx.cb(currentPath, value, found); | ||
value = ctx.cb(currentKey, value, found); | ||
} | ||
@@ -46,3 +46,3 @@ | ||
if (value !== null && typeof value === 'object') { | ||
return SafeProxy(value, ctx, currentPath); | ||
return SafeProxy(value, ctx, currentKey); | ||
} | ||
@@ -49,0 +49,0 @@ |
{ | ||
"name": "object-lib", | ||
"type": "module", | ||
"version": "5.2.1", | ||
"version": "5.2.2", | ||
"main": "lib/index.js", | ||
@@ -6,0 +6,0 @@ "repository": { |
17060
-0.04%