diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-02-19 14:01:16 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-02-19 14:01:50 -0400 |
commit | 52dff89530844d959cbd5f985660b877a1dc442a (patch) | |
tree | 4303d6577d7e77dad730e9dfc42c4f2505c1bca8 /src | |
parent | fff924e182e28fe940767009fca894c4bb4a07c5 (diff) |
sugar: splitKeys
Diffstat (limited to 'src')
-rw-r--r-- | src/util/sugar.js | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/util/sugar.js b/src/util/sugar.js index 3c364ee5..e060f458 100644 --- a/src/util/sugar.js +++ b/src/util/sugar.js @@ -268,6 +268,10 @@ export function escapeRegex(string) { return string.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'); } +export function splitKeys(key) { + return key.split(/(?<=(?<!\\)(?:\\\\)*)\./); +} + // Follows a key path like 'foo.bar.baz' to get an item nested deeply inside // an object. export function getNestedProp(obj, key) { @@ -276,7 +280,7 @@ export function getNestedProp(obj, key) { ? o[k[0]] : recursive(o[k[0]], k.slice(1))); - return recursive(obj, key.split(/(?<=(?<!\\)(?:\\\\)*)\./)); + return recursive(obj, splitKeys(key)); } // Gets the "look" of some arbitrary value. It's like typeof, but smarter. |