UNPKG

@stryke/helpers

Version:

A package containing miscellaneous helper functions that are used across many different Storm Software projects.

23 lines (22 loc) 651 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toPath = toPath; const a = /^[\w.]+$/g, E = /\\(?<temp1>\\)?/g, e = new RegExp(`${String.raw`[^.[\]]+`}|${String.raw`\[(?:`}([^"'][^[]*)|${String.raw`(["'])((?:(?!\2)[^\\]|\\.)*?)\2`}${String.raw`)\]`}|${String.raw`(?=(?:\.|\[\])(?:\.|\[\]|$))`}`, "g"); function toPath(t) { if (a.test(t)) return t.split("."); const n = []; t[0] === "." && n.push(""); const i = t.matchAll(e); for (const r of i) { let s = r[0]; const o = r[1], g = r[2], c = r[3]; g && c ? s = c.replace(E, "$1") : o && (s = o), n.push(s); } return n; }