From 99e1a1f96bb18b7d43a0bc7e9148ff73bb4daa36 Mon Sep 17 00:00:00 2001 From: titanism <101466223+titanism@users.noreply.github.com> Date: Fri, 12 May 2023 12:20:53 -0500 Subject: [PATCH] feat: added support for Symbols and empty objects in `meta` --- src/index.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index e5d28f1..99ca000 100644 --- a/src/index.js +++ b/src/index.js @@ -57,6 +57,7 @@ function dotifyToArray(obj) { const newKey = current ? current + '.' + convertedKey : convertedKey; // joined key with dot // if (value && typeof value === 'object' && !(value instanceof Date) && !ObjectID.isValid(value)) { if (isPlainObject(value)) { + res.push(convertedKey); recurse(value, newKey); // it's a nested object, so do it again } else { res.push(newKey); @@ -502,8 +503,8 @@ class Axe { if (index !== -1) { let i = dotified.length; while (i--) { - if (!isSymbol(dotified[i]) && dotified[i].indexOf(key) === 0) - dotified.splice(i, 1); + if (dotified[i] === key.slice(0, -1)) dotified.splice(i, 1); + else if (dotified[i].indexOf(key) === 0) dotified.splice(i, 1); } } } @@ -520,8 +521,11 @@ class Axe { // (and it doesn't also do bigints yet) // for (const prop of dotified) { - if (isSymbol(prop) && meta[prop]) - pickedSymbols.push([prop, meta[prop]]); + if (isSymbol(prop)) { + if (meta[prop] !== undefined) pickedSymbols.push([prop, meta[prop]]); + } else if (meta[Symbol.for(prop)] !== undefined) { + pickedSymbols.push([Symbol.for(prop), meta[Symbol.for(prop)]]); + } } //