From b1e2c8fd5cb5dfa46bc440a12eafaf56cd844b1c Mon Sep 17 00:00:00 2001 From: Philipp Tanlak Date: Mon, 24 Nov 2025 20:54:57 +0100 Subject: Docs --- node_modules/tailwindcss/src/util/toPath.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 node_modules/tailwindcss/src/util/toPath.js (limited to 'node_modules/tailwindcss/src/util/toPath.js') diff --git a/node_modules/tailwindcss/src/util/toPath.js b/node_modules/tailwindcss/src/util/toPath.js new file mode 100644 index 0000000..6dce924 --- /dev/null +++ b/node_modules/tailwindcss/src/util/toPath.js @@ -0,0 +1,26 @@ +/** + * Parse a path string into an array of path segments. + * + * Square bracket notation `a[b]` may be used to "escape" dots that would otherwise be interpreted as path separators. + * + * Example: + * a -> ['a'] + * a.b.c -> ['a', 'b', 'c'] + * a[b].c -> ['a', 'b', 'c'] + * a[b.c].e.f -> ['a', 'b.c', 'e', 'f'] + * a[b][c][d] -> ['a', 'b', 'c', 'd'] + * + * @param {string|string[]} path + **/ +export function toPath(path) { + if (Array.isArray(path)) return path + + let openBrackets = path.split('[').length - 1 + let closedBrackets = path.split(']').length - 1 + + if (openBrackets !== closedBrackets) { + throw new Error(`Path is invalid. Has unbalanced brackets: ${path}`) + } + + return path.split(/\.(?![^\[]*\])|[\[\]]/g).filter(Boolean) +} -- cgit v1.2.3