MCPcopy Index your code
hub / github.com/nodejs/node / parseSqBrackets

Function parseSqBrackets

deps/npm/lib/utils/queryable.js:25–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23 const sqBracketItems = new Set()
24 sqBracketItems.add(_append)
25 const parseSqBrackets = str => {
26 const index = sqBracketsMatcher(str)
27
28 // once we find square brackets, we recursively parse all these
29 if (index) {
30 const preSqBracketPortion = index[1]
31
32 // we want to have a `new String` wrapper here in order to differentiate between multiple occurrences of the same string,
33 // e.g: foo.bar[foo.bar] should split into { foo: { bar: { 'foo.bar': {} } }
34 /* eslint-disable-next-line no-new-wrappers */
35 const foundKey = new String(index[2])
36 const postSqBracketPortion = index[3]
37
38 // we keep track of items found during this step to make sure we don't try to split-separate keys that were defined within square brackets, since the key name itself might contain dots
39 sqBracketItems.add(foundKey)
40
41 // returns an array that contains either dot-separate items (that will be split apart during the next step OR the fully parsed keys read from square brackets
42 // e.g: foo.bar[1.0.0].a.b -> ['foo.bar', '1.0.0', 'a.b']
43 return [
44 ...parseSqBrackets(preSqBracketPortion),
45 foundKey,
46 ...(postSqBracketPortion ? parseSqBrackets(postSqBracketPortion) : []),
47 ]
48 }
49
50 // at the end of parsing, any usage of the special empty-bracket syntax (e.g: foo.array[]) has not yet been parsed
51 // here we'll take care of parsing it and adding a special symbol to represent it in the resulting list of keys
52 return replaceAppendSymbols(str)
53 }
54
55 const res = []
56 // starts by parsing items defined as square brackets

Callers 1

parseKeysFunction · 0.85

Calls 3

sqBracketsMatcherFunction · 0.85
replaceAppendSymbolsFunction · 0.85
addMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…