« get me outta code hell

sugar: splitKeys - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
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
commit52dff89530844d959cbd5f985660b877a1dc442a (patch)
tree4303d6577d7e77dad730e9dfc42c4f2505c1bca8
parentfff924e182e28fe940767009fca894c4bb4a07c5 (diff)
sugar: splitKeys
-rw-r--r--src/util/sugar.js6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/util/sugar.js b/src/util/sugar.js
index 3c364ee..e060f45 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.