pathtrace 1.0.0-beta.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # pathtrace 🔍
2
2
 
3
3
  [![npm version](https://badge.fury.io/js/pathtrace.svg)](https://badge.fury.io/js/pathtrace)
4
+ [![codecov](https://codecov.io/gh/tada5hi/pathtrace/graph/badge.svg?token=VIP3G2QT16)](https://codecov.io/gh/tada5hi/pathtrace)
4
5
  [![main](https://github.com/tada5hi/pathtrace/actions/workflows/main.yml/badge.svg)](https://github.com/tada5hi/pathtrace/actions/workflows/main.yml)
5
6
  [![Known Vulnerabilities](https://snyk.io/test/github/tada5hi/pathtrace/badge.svg)](https://snyk.io/test/github/tada5hi/pathtrace)
6
7
  [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white)](https://conventionalcommits.org)
package/dist/index.cjs CHANGED
@@ -81,12 +81,15 @@
81
81
  return !!input && typeof input === 'object' && !Array.isArray(input);
82
82
  }
83
83
 
84
- function expandPathInternal(data, path, currPath = []) {
84
+ function expandPathVerboseInternal(data, path, currPath = [], currMatches = []) {
85
85
  const segments = Array.isArray(path) ? path : pathToArray(path);
86
86
  if (!segments.length) {
87
87
  // no more paths to traverse
88
88
  return [
89
- arrayToPath(currPath)
89
+ {
90
+ value: arrayToPath(currPath),
91
+ matches: currMatches
92
+ }
90
93
  ];
91
94
  }
92
95
  const key = segments[0];
@@ -96,7 +99,10 @@ function expandPathInternal(data, path, currPath = []) {
96
99
  if (!rest.length) {
97
100
  // globstar leaves are always selected
98
101
  return [
99
- arrayToPath(currPath)
102
+ {
103
+ value: arrayToPath(currPath),
104
+ matches: currMatches
105
+ }
100
106
  ];
101
107
  }
102
108
  return [];
@@ -107,33 +113,56 @@ function expandPathInternal(data, path, currPath = []) {
107
113
  // value is a primitive, paths being traversed from here might be in their prototype,
108
114
  // return the entire path
109
115
  return [
110
- arrayToPath([
111
- ...currPath,
112
- ...segments
113
- ])
116
+ {
117
+ value: arrayToPath([
118
+ ...currPath,
119
+ ...segments
120
+ ]),
121
+ matches: currMatches
122
+ }
114
123
  ];
115
124
  }
116
125
  // Use a non-null value so that non-existing fields are still selected
117
126
  data = data || {};
118
127
  if (key === Character.WILDCARD) {
119
- return Object.keys(data).flatMap((key)=>expandPathInternal(data[key], arrayToPath(rest), currPath.concat(key)));
128
+ return Object.keys(data).flatMap((key)=>expandPathVerboseInternal(data[key], arrayToPath(rest), currPath.concat(key), currMatches.concat(key)));
120
129
  }
121
130
  if (key === Character.GLOBSTAR) {
122
131
  return Object.keys(data).flatMap((key)=>{
123
132
  const nextPath = currPath.concat(key);
124
133
  const value = data[key];
125
- const set = new Set([
126
- // recursively find matching sub-paths
127
- ...expandPathInternal(value, arrayToPath(segments), nextPath),
128
- // skip the first remaining segment, if it matches the current key
129
- ...rest[0] === key ? expandPathInternal(value, arrayToPath(rest.slice(1)), nextPath) : []
130
- ]);
131
- return [
132
- ...set
133
- ];
134
+ // recursively find matching sub-paths & skip the first remaining segment, if it matches the current key
135
+ const children = expandPathVerboseInternal(value, arrayToPath(segments), nextPath, [
136
+ key
137
+ ]).concat(rest[0] === key ? expandPathVerboseInternal(value, arrayToPath(rest.slice(1)), nextPath, []) : []);
138
+ const pathMatches = [];
139
+ const output = [];
140
+ for(let i = 0; i < children.length; i++){
141
+ /* istanbul ignore next */ if (pathMatches.indexOf(children[i].value) !== -1) {
142
+ continue;
143
+ }
144
+ pathMatches.push(children[i].value);
145
+ output.push({
146
+ value: children[i].value,
147
+ matches: children[i].matches.length > 0 ? [
148
+ ...currMatches,
149
+ children[i].matches.flat()
150
+ ] : currMatches
151
+ });
152
+ }
153
+ return output;
134
154
  });
135
155
  }
136
- return expandPathInternal(data[key], rest, currPath.concat(key));
156
+ return expandPathVerboseInternal(data[key], rest, currPath.concat(key), currMatches);
157
+ }
158
+ /**
159
+ * Verbose expand wildcard and glob patterns.
160
+ * Track wildcard/glob pattern matches.
161
+ *
162
+ * @param data
163
+ * @param path
164
+ */ function expandPathVerbose(data, path) {
165
+ return expandPathVerboseInternal(data, path);
137
166
  }
138
167
  /**
139
168
  * Expand wildcard and glob patterns to paths.
@@ -141,7 +170,7 @@ function expandPathInternal(data, path, currPath = []) {
141
170
  * @param data
142
171
  * @param path
143
172
  */ function expandPath(data, path) {
144
- return expandPathInternal(data, path);
173
+ return expandPathVerbose(data, path).map((el)=>el.value);
145
174
  }
146
175
 
147
176
  function getPathValue(data, path) {
@@ -168,6 +197,35 @@ function getPathValue(data, path) {
168
197
  return res;
169
198
  }
170
199
 
200
+ const NUMBER_REGEX = /^\d+$/;
201
+ function setPathValue(data, path, value) {
202
+ const parts = Array.isArray(path) ? path : pathToArray(path);
203
+ let temp = data;
204
+ let index = 0;
205
+ while(index < parts.length){
206
+ /* istanbul ignore next */ if (!Array.isArray(temp) && !isObject(temp)) {
207
+ break;
208
+ }
209
+ const key = parts[index];
210
+ // [foo, '0']
211
+ if (typeof temp[key] === 'undefined') {
212
+ const match = NUMBER_REGEX.test(key);
213
+ if (match) {
214
+ temp[key] = [];
215
+ } else {
216
+ temp[key] = {};
217
+ }
218
+ }
219
+ if (index === parts.length - 1) {
220
+ temp[key] = value;
221
+ break;
222
+ }
223
+ index++;
224
+ temp = temp[key];
225
+ }
226
+ return data;
227
+ }
228
+
171
229
  class PathInfo {
172
230
  get value() {
173
231
  if (typeof this._value !== 'undefined') {
@@ -230,38 +288,11 @@ function getPathInfo(data, path) {
230
288
  return new PathInfo(data, path);
231
289
  }
232
290
 
233
- const NUMBER_REGEX = /^\d+$/;
234
- function setPathValue(data, path, value) {
235
- const parts = Array.isArray(path) ? path : pathToArray(path);
236
- let temp = data;
237
- let index = 0;
238
- while(index < parts.length){
239
- /* istanbul ignore next */ if (!Array.isArray(temp) && !isObject(temp)) {
240
- break;
241
- }
242
- const key = parts[index];
243
- // [foo, '0']
244
- if (typeof temp[key] === 'undefined') {
245
- const match = NUMBER_REGEX.test(key);
246
- if (match) {
247
- temp[key] = [];
248
- } else {
249
- temp[key] = {};
250
- }
251
- }
252
- if (index === parts.length - 1) {
253
- temp[key] = value;
254
- break;
255
- }
256
- index++;
257
- temp = temp[key];
258
- }
259
- return data;
260
- }
261
-
262
291
  exports.BRACKET_NUMBER_REGEX = BRACKET_NUMBER_REGEX;
292
+ exports.PathInfo = PathInfo;
263
293
  exports.arrayToPath = arrayToPath;
264
294
  exports.expandPath = expandPath;
295
+ exports.expandPathVerbose = expandPathVerbose;
265
296
  exports.getPathInfo = getPathInfo;
266
297
  exports.getPathValue = getPathValue;
267
298
  exports.pathToArray = pathToArray;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/helpers/array-to-path.ts","../src/helpers/path-to-array.ts","../src/constants.ts","../src/utils/is-object.ts","../src/expand-path.ts","../src/get-path-value.ts","../src/path-info.ts","../src/get-path-info.ts","../src/set-path-value.ts"],"sourcesContent":["/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\n/**\n * @see https://github.com/express-validator/express-validator/blob/bec1dcbaa29002dcd21093ec84818c4671063b5d/src/field-selection.ts#L214\n * @param parts\n */\nexport function arrayToPath(parts: readonly string[]) : string {\n return parts.reduce((prev, segment) => {\n let part = '';\n\n segment = segment.replace(/^\\[(\\d+)]$/g, '\\\\[$1]');\n segment = segment.replace(/\\./g, '\\\\.');\n\n if (/^\\d+$/.test(segment)) {\n // Index access\n part = `[${segment}]`;\n } else if (prev) {\n // Object key access\n part = `.${segment}`;\n } else {\n // Top level key\n part = segment;\n }\n\n return prev + part;\n }, '');\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport const BRACKET_NUMBER_REGEX = /(?<!\\\\)\\[(\\d+)]$/;\n\n/**\n * Convert string to property path array.\n *\n * @see https://github.com/lodash/lodash/blob/main/src/.internal/stringToPath.ts\n * @see https://github.com/chaijs/pathval\n *\n * @param segment\n */\nexport function pathToArray(segment: string) : string[] {\n const str = segment.replace(/([^\\\\])\\[/g, '$1.[');\n const parts = str.match(/(\\\\\\.|[^.]+?)+/g);\n if (!parts) {\n return [];\n }\n\n const result : string[] = [];\n\n for (let i = 0; i < parts.length; i++) {\n if (\n parts[i] === 'constructor' ||\n parts[i] === '__proto__' ||\n parts[i] === 'prototype'\n ) {\n continue;\n }\n\n const regex = BRACKET_NUMBER_REGEX.exec(parts[i]);\n if (regex) {\n result.push(regex[1]);\n } else {\n result.push(parts[i].replace(/\\\\([.[\\]])/g, '$1'));\n }\n }\n\n return result;\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum Character {\n WILDCARD = '*',\n GLOBSTAR = '**',\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function isObject(input: unknown) : input is Record<string, any> {\n return !!input &&\n typeof input === 'object' &&\n !Array.isArray(input);\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { Character } from './constants';\nimport { isObject } from './utils';\nimport { arrayToPath, pathToArray } from './helpers';\n\nfunction expandPathInternal(\n data: Record<string, any>,\n path: string | string[],\n currPath: readonly string[] = [],\n): string[] {\n const segments = Array.isArray(path) ? path : pathToArray(path);\n if (!segments.length) {\n // no more paths to traverse\n return [arrayToPath(currPath)];\n }\n\n const key = segments[0];\n const rest = segments.slice(1);\n\n if (\n typeof data !== 'undefined' &&\n data !== null &&\n !isObject(data) &&\n !Array.isArray(data)\n ) {\n if (key === Character.GLOBSTAR) {\n if (!rest.length) {\n // globstar leaves are always selected\n return [arrayToPath(currPath)];\n }\n\n return [];\n }\n\n if (key === Character.WILDCARD) {\n return [];\n }\n\n // value is a primitive, paths being traversed from here might be in their prototype,\n // return the entire path\n return [arrayToPath([...currPath, ...segments])];\n }\n\n // Use a non-null value so that non-existing fields are still selected\n data = data || {};\n\n if (key === Character.WILDCARD) {\n return Object.keys(data)\n .flatMap((key) => expandPathInternal(data[key], arrayToPath(rest), currPath.concat(key)));\n }\n\n if (key === Character.GLOBSTAR) {\n return Object.keys(data)\n .flatMap((key) => {\n const nextPath = currPath.concat(key);\n const value = data[key];\n const set = new Set([\n // recursively find matching sub-paths\n ...expandPathInternal(value, arrayToPath(segments), nextPath),\n // skip the first remaining segment, if it matches the current key\n ...(rest[0] === key ? expandPathInternal(value, arrayToPath(rest.slice(1)), nextPath) : []),\n ]);\n\n return [...set];\n });\n }\n\n return expandPathInternal(data[key], rest, currPath.concat(key));\n}\n\n/**\n * Expand wildcard and glob patterns to paths.\n *\n * @param data\n * @param path\n */\nexport function expandPath(\n data: Record<string, any>,\n path: string | string[],\n): string[] {\n return expandPathInternal(data, path);\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { pathToArray } from './helpers';\n\nexport function getPathValue(\n data: unknown,\n path: string | string[],\n): unknown {\n const parts = Array.isArray(path) ?\n path :\n pathToArray(path);\n\n let res : unknown | undefined;\n let temp = data;\n let index = 0;\n while (index < parts.length) {\n if (temp === null || typeof temp === 'undefined') {\n break;\n }\n\n if (parts[index] in Object(temp)) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n temp = temp[parts[index]];\n } else {\n break;\n }\n\n if (index === parts.length - 1) {\n res = temp;\n }\n\n index++;\n }\n\n return res;\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { getPathValue } from './get-path-value';\nimport { pathToArray } from './helpers';\n\nexport class PathInfo {\n protected data: unknown;\n\n protected pathParts: string[];\n\n protected _value: unknown;\n\n protected _parent: PathInfo | null | undefined;\n\n protected _exists: boolean | undefined;\n\n constructor(data: unknown, path: string | string[]) {\n this.data = data;\n\n if (Array.isArray(path)) {\n this.pathParts = path;\n } else {\n this.pathParts = pathToArray(path);\n }\n }\n\n get value() {\n if (typeof this._value !== 'undefined') {\n return this._value;\n }\n\n if (this.pathParts.length > 0) {\n this._value = getPathValue(this.data, this.pathParts);\n } else {\n this._value = this.data;\n }\n\n return this._value;\n }\n\n get name() : string | null {\n if (this.pathParts.length > 0) {\n return this.pathParts[this.pathParts.length - 1];\n }\n\n return null;\n }\n\n get parent() : PathInfo | null {\n if (typeof this._parent !== 'undefined') {\n return this._parent;\n }\n\n if (this.pathParts.length === 0) {\n this._parent = null;\n return this._parent;\n }\n\n if (this.pathParts.length > 1) {\n this._parent = new PathInfo(\n this.data,\n this.pathParts.slice(0, this.pathParts.length - 1),\n );\n } else {\n this._parent = new PathInfo(this.data, []);\n }\n\n return this._parent;\n }\n\n get exists() : boolean {\n if (typeof this._exists !== 'undefined') {\n return this._exists;\n }\n\n if (!this.name || !this.parent) {\n this._exists = true;\n return this._exists;\n }\n\n if (\n this.parent.value !== null &&\n typeof this.parent.value !== 'undefined'\n ) {\n this._exists = this.name in Object(this.parent.value);\n } else {\n this._exists = false;\n }\n\n return this._exists;\n }\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { PathInfo } from './path-info';\n\nexport function getPathInfo(\n data: Record<string, any>,\n path: string | string[],\n) : PathInfo {\n return new PathInfo(data, path);\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { pathToArray } from './helpers';\nimport { isObject } from './utils';\n\nconst NUMBER_REGEX = /^\\d+$/;\n\nexport function setPathValue(\n data: Record<string, any> | Record<string, any>[],\n path: string | string[],\n value: unknown,\n) {\n const parts = Array.isArray(path) ?\n path :\n pathToArray(path);\n\n let temp = data;\n let index = 0;\n while (index < parts.length) {\n /* istanbul ignore next */\n if (!Array.isArray(temp) && !isObject(temp)) {\n break;\n }\n\n const key = parts[index] as keyof typeof temp;\n\n // [foo, '0']\n if (typeof temp[key] === 'undefined') {\n const match = NUMBER_REGEX.test(key);\n if (match) {\n (temp as Record<string, any>)[key] = [];\n } else {\n temp[key] = {};\n }\n }\n\n if (index === parts.length - 1) {\n temp[key] = value;\n break;\n }\n\n index++;\n temp = temp[key];\n }\n\n return data;\n}\n"],"names":["arrayToPath","parts","reduce","prev","segment","part","replace","test","BRACKET_NUMBER_REGEX","pathToArray","str","match","result","i","length","regex","exec","push","Character","isObject","input","Array","isArray","expandPathInternal","data","path","currPath","segments","key","rest","slice","GLOBSTAR","WILDCARD","Object","keys","flatMap","concat","nextPath","value","set","Set","expandPath","getPathValue","res","temp","index","PathInfo","_value","pathParts","name","parent","_parent","exists","_exists","constructor","getPathInfo","NUMBER_REGEX","setPathValue"],"mappings":";;AAAA;;;;;;;;IAWO,SAASA,WAAAA,CAAYC,KAAwB,EAAA;AAChD,IAAA,OAAOA,KAAMC,CAAAA,MAAM,CAAC,CAACC,IAAMC,EAAAA,OAAAA,GAAAA;AACvB,QAAA,IAAIC,IAAO,GAAA,EAAA,CAAA;QAEXD,OAAUA,GAAAA,OAAAA,CAAQE,OAAO,CAAC,aAAe,EAAA,QAAA,CAAA,CAAA;QACzCF,OAAUA,GAAAA,OAAAA,CAAQE,OAAO,CAAC,KAAO,EAAA,KAAA,CAAA,CAAA;QAEjC,IAAI,OAAA,CAAQC,IAAI,CAACH,OAAU,CAAA,EAAA;;AAEvBC,YAAAA,IAAAA,GAAO,CAAC,CAAC,EAAED,OAAAA,CAAQ,CAAC,CAAC,CAAA;AACzB,SAAA,MAAO,IAAID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A,CAAAA;AACX;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/helpers/array-to-path.ts","../src/helpers/path-to-array.ts","../src/path-expand/constants.ts","../src/utils/is-object.ts","../src/path-expand/module.ts","../src/path-value/get.ts","../src/path-value/set.ts","../src/path-info/module.ts","../src/path-info/helper.ts"],"sourcesContent":["/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\n/**\n * @see https://github.com/express-validator/express-validator/blob/bec1dcbaa29002dcd21093ec84818c4671063b5d/src/field-selection.ts#L214\n * @param parts\n */\nexport function arrayToPath(parts: readonly string[]) : string {\n return parts.reduce((prev, segment) => {\n let part = '';\n\n segment = segment.replace(/^\\[(\\d+)]$/g, '\\\\[$1]');\n segment = segment.replace(/\\./g, '\\\\.');\n\n if (/^\\d+$/.test(segment)) {\n // Index access\n part = `[${segment}]`;\n } else if (prev) {\n // Object key access\n part = `.${segment}`;\n } else {\n // Top level key\n part = segment;\n }\n\n return prev + part;\n }, '');\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport const BRACKET_NUMBER_REGEX = /(?<!\\\\)\\[(\\d+)]$/;\n\n/**\n * Convert string to property path array.\n *\n * @see https://github.com/lodash/lodash/blob/main/src/.internal/stringToPath.ts\n * @see https://github.com/chaijs/pathval\n *\n * @param segment\n */\nexport function pathToArray(segment: string) : string[] {\n const str = segment.replace(/([^\\\\])\\[/g, '$1.[');\n const parts = str.match(/(\\\\\\.|[^.]+?)+/g);\n if (!parts) {\n return [];\n }\n\n const result : string[] = [];\n\n for (let i = 0; i < parts.length; i++) {\n if (\n parts[i] === 'constructor' ||\n parts[i] === '__proto__' ||\n parts[i] === 'prototype'\n ) {\n continue;\n }\n\n const regex = BRACKET_NUMBER_REGEX.exec(parts[i]);\n if (regex) {\n result.push(regex[1]);\n } else {\n result.push(parts[i].replace(/\\\\([.[\\]])/g, '$1'));\n }\n }\n\n return result;\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum Character {\n WILDCARD = '*',\n GLOBSTAR = '**',\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function isObject(input: unknown) : input is Record<string, any> {\n return !!input &&\n typeof input === 'object' &&\n !Array.isArray(input);\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { Character } from './constants';\nimport type { PathExpanded } from './types';\nimport { isObject } from '../utils';\nimport { arrayToPath, pathToArray } from '../helpers';\n\nfunction expandPathVerboseInternal(\n data: Record<string, any>,\n path: string | string[],\n currPath: readonly string[] = [],\n currMatches: readonly (string | string[])[] = [],\n): PathExpanded[] {\n const segments = Array.isArray(path) ? path : pathToArray(path);\n if (!segments.length) {\n // no more paths to traverse\n return [\n {\n value: arrayToPath(currPath),\n matches: currMatches,\n },\n ];\n }\n\n const key = segments[0];\n const rest = segments.slice(1);\n\n if (\n typeof data !== 'undefined' &&\n data !== null &&\n !isObject(data) &&\n !Array.isArray(data)\n ) {\n if (key === Character.GLOBSTAR) {\n if (!rest.length) {\n // globstar leaves are always selected\n return [\n {\n value: arrayToPath(currPath),\n matches: currMatches,\n },\n ];\n }\n\n return [];\n }\n\n if (key === Character.WILDCARD) {\n return [];\n }\n\n // value is a primitive, paths being traversed from here might be in their prototype,\n // return the entire path\n return [{ value: arrayToPath([...currPath, ...segments]), matches: currMatches }];\n }\n\n // Use a non-null value so that non-existing fields are still selected\n data = data || {};\n\n if (key === Character.WILDCARD) {\n return Object.keys(data)\n .flatMap((key) => expandPathVerboseInternal(\n data[key],\n arrayToPath(rest),\n currPath.concat(key),\n currMatches.concat(key),\n ));\n }\n\n if (key === Character.GLOBSTAR) {\n return Object.keys(data)\n .flatMap((key) => {\n const nextPath = currPath.concat(key);\n const value = data[key];\n\n // recursively find matching sub-paths & skip the first remaining segment, if it matches the current key\n const children = expandPathVerboseInternal(value, arrayToPath(segments), nextPath, [key])\n .concat(rest[0] === key ? expandPathVerboseInternal(value, arrayToPath(rest.slice(1)), nextPath, []) : []);\n\n const pathMatches : string[] = [];\n const output : PathExpanded[] = [];\n for (let i = 0; i < children.length; i++) {\n /* istanbul ignore next */\n if (pathMatches.indexOf(children[i].value) !== -1) {\n continue;\n }\n\n pathMatches.push(children[i].value);\n\n output.push({\n value: children[i].value,\n matches: children[i].matches.length > 0 ?\n [...currMatches, children[i].matches.flat()] :\n currMatches,\n });\n }\n\n return output;\n });\n }\n\n return expandPathVerboseInternal(data[key], rest, currPath.concat(key), currMatches);\n}\n\n/**\n * Verbose expand wildcard and glob patterns.\n * Track wildcard/glob pattern matches.\n *\n * @param data\n * @param path\n */\nexport function expandPathVerbose(\n data: Record<string, any>,\n path: string | string[],\n): PathExpanded[] {\n return expandPathVerboseInternal(data, path);\n}\n\n/**\n * Expand wildcard and glob patterns to paths.\n *\n * @param data\n * @param path\n */\nexport function expandPath(\n data: Record<string, any>,\n path: string | string[],\n): string[] {\n return expandPathVerbose(data, path)\n .map((el) => el.value);\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { pathToArray } from '../helpers';\n\nexport function getPathValue(\n data: unknown,\n path: string | string[],\n): unknown {\n const parts = Array.isArray(path) ?\n path :\n pathToArray(path);\n\n let res : unknown | undefined;\n let temp = data;\n let index = 0;\n while (index < parts.length) {\n if (temp === null || typeof temp === 'undefined') {\n break;\n }\n\n if (parts[index] in Object(temp)) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n temp = temp[parts[index]];\n } else {\n break;\n }\n\n if (index === parts.length - 1) {\n res = temp;\n }\n\n index++;\n }\n\n return res;\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { pathToArray } from '../helpers';\nimport { isObject } from '../utils';\n\nconst NUMBER_REGEX = /^\\d+$/;\n\nexport function setPathValue(\n data: Record<string, any> | Record<string, any>[],\n path: string | string[],\n value: unknown,\n) {\n const parts = Array.isArray(path) ?\n path :\n pathToArray(path);\n\n let temp = data;\n let index = 0;\n while (index < parts.length) {\n /* istanbul ignore next */\n if (!Array.isArray(temp) && !isObject(temp)) {\n break;\n }\n\n const key = parts[index] as keyof typeof temp;\n\n // [foo, '0']\n if (typeof temp[key] === 'undefined') {\n const match = NUMBER_REGEX.test(key);\n if (match) {\n (temp as Record<string, any>)[key] = [];\n } else {\n temp[key] = {};\n }\n }\n\n if (index === parts.length - 1) {\n temp[key] = value;\n break;\n }\n\n index++;\n temp = temp[key];\n }\n\n return data;\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { getPathValue } from '../path-value/get';\nimport { pathToArray } from '../helpers';\n\nexport class PathInfo {\n protected data: unknown;\n\n protected pathParts: string[];\n\n protected _value: unknown;\n\n protected _parent: PathInfo | null | undefined;\n\n protected _exists: boolean | undefined;\n\n constructor(data: unknown, path: string | string[]) {\n this.data = data;\n\n if (Array.isArray(path)) {\n this.pathParts = path;\n } else {\n this.pathParts = pathToArray(path);\n }\n }\n\n get value() {\n if (typeof this._value !== 'undefined') {\n return this._value;\n }\n\n if (this.pathParts.length > 0) {\n this._value = getPathValue(this.data, this.pathParts);\n } else {\n this._value = this.data;\n }\n\n return this._value;\n }\n\n get name() : string | null {\n if (this.pathParts.length > 0) {\n return this.pathParts[this.pathParts.length - 1];\n }\n\n return null;\n }\n\n get parent() : PathInfo | null {\n if (typeof this._parent !== 'undefined') {\n return this._parent;\n }\n\n if (this.pathParts.length === 0) {\n this._parent = null;\n return this._parent;\n }\n\n if (this.pathParts.length > 1) {\n this._parent = new PathInfo(\n this.data,\n this.pathParts.slice(0, this.pathParts.length - 1),\n );\n } else {\n this._parent = new PathInfo(this.data, []);\n }\n\n return this._parent;\n }\n\n get exists() : boolean {\n if (typeof this._exists !== 'undefined') {\n return this._exists;\n }\n\n if (!this.name || !this.parent) {\n this._exists = true;\n return this._exists;\n }\n\n if (\n this.parent.value !== null &&\n typeof this.parent.value !== 'undefined'\n ) {\n this._exists = this.name in Object(this.parent.value);\n } else {\n this._exists = false;\n }\n\n return this._exists;\n }\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { PathInfo } from './module';\n\nexport function getPathInfo(\n data: Record<string, any>,\n path: string | string[],\n) : PathInfo {\n return new PathInfo(data, path);\n}\n"],"names":["arrayToPath","parts","reduce","prev","segment","part","replace","test","BRACKET_NUMBER_REGEX","pathToArray","str","match","result","i","length","regex","exec","push","Character","isObject","input","Array","isArray","expandPathVerboseInternal","data","path","currPath","currMatches","segments","value","matches","key","rest","slice","GLOBSTAR","WILDCARD","Object","keys","flatMap","concat","nextPath","children","pathMatches","output","indexOf","flat","expandPathVerbose","expandPath","map","el","getPathValue","res","temp","index","NUMBER_REGEX","setPathValue","PathInfo","_value","pathParts","name","parent","_parent","exists","_exists","constructor","getPathInfo"],"mappings":";;AAAA;;;;;;;;IAWO,SAASA,WAAAA,CAAYC,KAAwB,EAAA;AAChD,IAAA,OAAOA,KAAMC,CAAAA,MAAM,CAAC,CAACC,IAAMC,EAAAA,OAAAA,GAAAA;AACvB,QAAA,IAAIC,IAAO,GAAA,EAAA,CAAA;QAEXD,OAAUA,GAAAA,OAAAA,CAAQE,OAAO,CAAC,aAAe,EAAA,QAAA,CAAA,CAAA;QACzCF,OAAU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AO,CAACG,IAAO,CAAA,EAAA;YACrB,IAAI,CAACiC,SAAS,GAAGjC,IAAAA,CAAAA;SACd,MAAA;YACH,IAAI,CAACiC,SAAS,GAAGjD,WAAYgB,CAAAA,IAAAA,CAAAA,CAAAA;AACjC,SAAA;AACJ,KAAA;AAmEJ;;ACvFO,SAASwC,WAAAA,CACZzC,IAAyB,EACzBC,IAAuB,EAAA;IAEvB,OAAO,IAAI+B,SAAShC,IAAMC,EAAAA,IAAAA,CAAAA,CAAAA;AAC9B;;;;;;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from './helpers';
2
- export * from './expand-path';
3
- export * from './get-path-value';
4
- export * from './get-path-info';
5
- export * from './set-path-value';
2
+ export * from './path-expand';
3
+ export * from './path-value';
4
+ export * from './path-info';
package/dist/index.mjs CHANGED
@@ -79,12 +79,15 @@
79
79
  return !!input && typeof input === 'object' && !Array.isArray(input);
80
80
  }
81
81
 
82
- function expandPathInternal(data, path, currPath = []) {
82
+ function expandPathVerboseInternal(data, path, currPath = [], currMatches = []) {
83
83
  const segments = Array.isArray(path) ? path : pathToArray(path);
84
84
  if (!segments.length) {
85
85
  // no more paths to traverse
86
86
  return [
87
- arrayToPath(currPath)
87
+ {
88
+ value: arrayToPath(currPath),
89
+ matches: currMatches
90
+ }
88
91
  ];
89
92
  }
90
93
  const key = segments[0];
@@ -94,7 +97,10 @@ function expandPathInternal(data, path, currPath = []) {
94
97
  if (!rest.length) {
95
98
  // globstar leaves are always selected
96
99
  return [
97
- arrayToPath(currPath)
100
+ {
101
+ value: arrayToPath(currPath),
102
+ matches: currMatches
103
+ }
98
104
  ];
99
105
  }
100
106
  return [];
@@ -105,33 +111,56 @@ function expandPathInternal(data, path, currPath = []) {
105
111
  // value is a primitive, paths being traversed from here might be in their prototype,
106
112
  // return the entire path
107
113
  return [
108
- arrayToPath([
109
- ...currPath,
110
- ...segments
111
- ])
114
+ {
115
+ value: arrayToPath([
116
+ ...currPath,
117
+ ...segments
118
+ ]),
119
+ matches: currMatches
120
+ }
112
121
  ];
113
122
  }
114
123
  // Use a non-null value so that non-existing fields are still selected
115
124
  data = data || {};
116
125
  if (key === Character.WILDCARD) {
117
- return Object.keys(data).flatMap((key)=>expandPathInternal(data[key], arrayToPath(rest), currPath.concat(key)));
126
+ return Object.keys(data).flatMap((key)=>expandPathVerboseInternal(data[key], arrayToPath(rest), currPath.concat(key), currMatches.concat(key)));
118
127
  }
119
128
  if (key === Character.GLOBSTAR) {
120
129
  return Object.keys(data).flatMap((key)=>{
121
130
  const nextPath = currPath.concat(key);
122
131
  const value = data[key];
123
- const set = new Set([
124
- // recursively find matching sub-paths
125
- ...expandPathInternal(value, arrayToPath(segments), nextPath),
126
- // skip the first remaining segment, if it matches the current key
127
- ...rest[0] === key ? expandPathInternal(value, arrayToPath(rest.slice(1)), nextPath) : []
128
- ]);
129
- return [
130
- ...set
131
- ];
132
+ // recursively find matching sub-paths & skip the first remaining segment, if it matches the current key
133
+ const children = expandPathVerboseInternal(value, arrayToPath(segments), nextPath, [
134
+ key
135
+ ]).concat(rest[0] === key ? expandPathVerboseInternal(value, arrayToPath(rest.slice(1)), nextPath, []) : []);
136
+ const pathMatches = [];
137
+ const output = [];
138
+ for(let i = 0; i < children.length; i++){
139
+ /* istanbul ignore next */ if (pathMatches.indexOf(children[i].value) !== -1) {
140
+ continue;
141
+ }
142
+ pathMatches.push(children[i].value);
143
+ output.push({
144
+ value: children[i].value,
145
+ matches: children[i].matches.length > 0 ? [
146
+ ...currMatches,
147
+ children[i].matches.flat()
148
+ ] : currMatches
149
+ });
150
+ }
151
+ return output;
132
152
  });
133
153
  }
134
- return expandPathInternal(data[key], rest, currPath.concat(key));
154
+ return expandPathVerboseInternal(data[key], rest, currPath.concat(key), currMatches);
155
+ }
156
+ /**
157
+ * Verbose expand wildcard and glob patterns.
158
+ * Track wildcard/glob pattern matches.
159
+ *
160
+ * @param data
161
+ * @param path
162
+ */ function expandPathVerbose(data, path) {
163
+ return expandPathVerboseInternal(data, path);
135
164
  }
136
165
  /**
137
166
  * Expand wildcard and glob patterns to paths.
@@ -139,7 +168,7 @@ function expandPathInternal(data, path, currPath = []) {
139
168
  * @param data
140
169
  * @param path
141
170
  */ function expandPath(data, path) {
142
- return expandPathInternal(data, path);
171
+ return expandPathVerbose(data, path).map((el)=>el.value);
143
172
  }
144
173
 
145
174
  function getPathValue(data, path) {
@@ -166,6 +195,35 @@ function getPathValue(data, path) {
166
195
  return res;
167
196
  }
168
197
 
198
+ const NUMBER_REGEX = /^\d+$/;
199
+ function setPathValue(data, path, value) {
200
+ const parts = Array.isArray(path) ? path : pathToArray(path);
201
+ let temp = data;
202
+ let index = 0;
203
+ while(index < parts.length){
204
+ /* istanbul ignore next */ if (!Array.isArray(temp) && !isObject(temp)) {
205
+ break;
206
+ }
207
+ const key = parts[index];
208
+ // [foo, '0']
209
+ if (typeof temp[key] === 'undefined') {
210
+ const match = NUMBER_REGEX.test(key);
211
+ if (match) {
212
+ temp[key] = [];
213
+ } else {
214
+ temp[key] = {};
215
+ }
216
+ }
217
+ if (index === parts.length - 1) {
218
+ temp[key] = value;
219
+ break;
220
+ }
221
+ index++;
222
+ temp = temp[key];
223
+ }
224
+ return data;
225
+ }
226
+
169
227
  class PathInfo {
170
228
  get value() {
171
229
  if (typeof this._value !== 'undefined') {
@@ -228,34 +286,5 @@ function getPathInfo(data, path) {
228
286
  return new PathInfo(data, path);
229
287
  }
230
288
 
231
- const NUMBER_REGEX = /^\d+$/;
232
- function setPathValue(data, path, value) {
233
- const parts = Array.isArray(path) ? path : pathToArray(path);
234
- let temp = data;
235
- let index = 0;
236
- while(index < parts.length){
237
- /* istanbul ignore next */ if (!Array.isArray(temp) && !isObject(temp)) {
238
- break;
239
- }
240
- const key = parts[index];
241
- // [foo, '0']
242
- if (typeof temp[key] === 'undefined') {
243
- const match = NUMBER_REGEX.test(key);
244
- if (match) {
245
- temp[key] = [];
246
- } else {
247
- temp[key] = {};
248
- }
249
- }
250
- if (index === parts.length - 1) {
251
- temp[key] = value;
252
- break;
253
- }
254
- index++;
255
- temp = temp[key];
256
- }
257
- return data;
258
- }
259
-
260
- export { BRACKET_NUMBER_REGEX, arrayToPath, expandPath, getPathInfo, getPathValue, pathToArray, setPathValue };
289
+ export { BRACKET_NUMBER_REGEX, PathInfo, arrayToPath, expandPath, expandPathVerbose, getPathInfo, getPathValue, pathToArray, setPathValue };
261
290
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/helpers/array-to-path.ts","../src/helpers/path-to-array.ts","../src/constants.ts","../src/utils/is-object.ts","../src/expand-path.ts","../src/get-path-value.ts","../src/path-info.ts","../src/get-path-info.ts","../src/set-path-value.ts"],"sourcesContent":["/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\n/**\n * @see https://github.com/express-validator/express-validator/blob/bec1dcbaa29002dcd21093ec84818c4671063b5d/src/field-selection.ts#L214\n * @param parts\n */\nexport function arrayToPath(parts: readonly string[]) : string {\n return parts.reduce((prev, segment) => {\n let part = '';\n\n segment = segment.replace(/^\\[(\\d+)]$/g, '\\\\[$1]');\n segment = segment.replace(/\\./g, '\\\\.');\n\n if (/^\\d+$/.test(segment)) {\n // Index access\n part = `[${segment}]`;\n } else if (prev) {\n // Object key access\n part = `.${segment}`;\n } else {\n // Top level key\n part = segment;\n }\n\n return prev + part;\n }, '');\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport const BRACKET_NUMBER_REGEX = /(?<!\\\\)\\[(\\d+)]$/;\n\n/**\n * Convert string to property path array.\n *\n * @see https://github.com/lodash/lodash/blob/main/src/.internal/stringToPath.ts\n * @see https://github.com/chaijs/pathval\n *\n * @param segment\n */\nexport function pathToArray(segment: string) : string[] {\n const str = segment.replace(/([^\\\\])\\[/g, '$1.[');\n const parts = str.match(/(\\\\\\.|[^.]+?)+/g);\n if (!parts) {\n return [];\n }\n\n const result : string[] = [];\n\n for (let i = 0; i < parts.length; i++) {\n if (\n parts[i] === 'constructor' ||\n parts[i] === '__proto__' ||\n parts[i] === 'prototype'\n ) {\n continue;\n }\n\n const regex = BRACKET_NUMBER_REGEX.exec(parts[i]);\n if (regex) {\n result.push(regex[1]);\n } else {\n result.push(parts[i].replace(/\\\\([.[\\]])/g, '$1'));\n }\n }\n\n return result;\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum Character {\n WILDCARD = '*',\n GLOBSTAR = '**',\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function isObject(input: unknown) : input is Record<string, any> {\n return !!input &&\n typeof input === 'object' &&\n !Array.isArray(input);\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { Character } from './constants';\nimport { isObject } from './utils';\nimport { arrayToPath, pathToArray } from './helpers';\n\nfunction expandPathInternal(\n data: Record<string, any>,\n path: string | string[],\n currPath: readonly string[] = [],\n): string[] {\n const segments = Array.isArray(path) ? path : pathToArray(path);\n if (!segments.length) {\n // no more paths to traverse\n return [arrayToPath(currPath)];\n }\n\n const key = segments[0];\n const rest = segments.slice(1);\n\n if (\n typeof data !== 'undefined' &&\n data !== null &&\n !isObject(data) &&\n !Array.isArray(data)\n ) {\n if (key === Character.GLOBSTAR) {\n if (!rest.length) {\n // globstar leaves are always selected\n return [arrayToPath(currPath)];\n }\n\n return [];\n }\n\n if (key === Character.WILDCARD) {\n return [];\n }\n\n // value is a primitive, paths being traversed from here might be in their prototype,\n // return the entire path\n return [arrayToPath([...currPath, ...segments])];\n }\n\n // Use a non-null value so that non-existing fields are still selected\n data = data || {};\n\n if (key === Character.WILDCARD) {\n return Object.keys(data)\n .flatMap((key) => expandPathInternal(data[key], arrayToPath(rest), currPath.concat(key)));\n }\n\n if (key === Character.GLOBSTAR) {\n return Object.keys(data)\n .flatMap((key) => {\n const nextPath = currPath.concat(key);\n const value = data[key];\n const set = new Set([\n // recursively find matching sub-paths\n ...expandPathInternal(value, arrayToPath(segments), nextPath),\n // skip the first remaining segment, if it matches the current key\n ...(rest[0] === key ? expandPathInternal(value, arrayToPath(rest.slice(1)), nextPath) : []),\n ]);\n\n return [...set];\n });\n }\n\n return expandPathInternal(data[key], rest, currPath.concat(key));\n}\n\n/**\n * Expand wildcard and glob patterns to paths.\n *\n * @param data\n * @param path\n */\nexport function expandPath(\n data: Record<string, any>,\n path: string | string[],\n): string[] {\n return expandPathInternal(data, path);\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { pathToArray } from './helpers';\n\nexport function getPathValue(\n data: unknown,\n path: string | string[],\n): unknown {\n const parts = Array.isArray(path) ?\n path :\n pathToArray(path);\n\n let res : unknown | undefined;\n let temp = data;\n let index = 0;\n while (index < parts.length) {\n if (temp === null || typeof temp === 'undefined') {\n break;\n }\n\n if (parts[index] in Object(temp)) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n temp = temp[parts[index]];\n } else {\n break;\n }\n\n if (index === parts.length - 1) {\n res = temp;\n }\n\n index++;\n }\n\n return res;\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { getPathValue } from './get-path-value';\nimport { pathToArray } from './helpers';\n\nexport class PathInfo {\n protected data: unknown;\n\n protected pathParts: string[];\n\n protected _value: unknown;\n\n protected _parent: PathInfo | null | undefined;\n\n protected _exists: boolean | undefined;\n\n constructor(data: unknown, path: string | string[]) {\n this.data = data;\n\n if (Array.isArray(path)) {\n this.pathParts = path;\n } else {\n this.pathParts = pathToArray(path);\n }\n }\n\n get value() {\n if (typeof this._value !== 'undefined') {\n return this._value;\n }\n\n if (this.pathParts.length > 0) {\n this._value = getPathValue(this.data, this.pathParts);\n } else {\n this._value = this.data;\n }\n\n return this._value;\n }\n\n get name() : string | null {\n if (this.pathParts.length > 0) {\n return this.pathParts[this.pathParts.length - 1];\n }\n\n return null;\n }\n\n get parent() : PathInfo | null {\n if (typeof this._parent !== 'undefined') {\n return this._parent;\n }\n\n if (this.pathParts.length === 0) {\n this._parent = null;\n return this._parent;\n }\n\n if (this.pathParts.length > 1) {\n this._parent = new PathInfo(\n this.data,\n this.pathParts.slice(0, this.pathParts.length - 1),\n );\n } else {\n this._parent = new PathInfo(this.data, []);\n }\n\n return this._parent;\n }\n\n get exists() : boolean {\n if (typeof this._exists !== 'undefined') {\n return this._exists;\n }\n\n if (!this.name || !this.parent) {\n this._exists = true;\n return this._exists;\n }\n\n if (\n this.parent.value !== null &&\n typeof this.parent.value !== 'undefined'\n ) {\n this._exists = this.name in Object(this.parent.value);\n } else {\n this._exists = false;\n }\n\n return this._exists;\n }\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { PathInfo } from './path-info';\n\nexport function getPathInfo(\n data: Record<string, any>,\n path: string | string[],\n) : PathInfo {\n return new PathInfo(data, path);\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { pathToArray } from './helpers';\nimport { isObject } from './utils';\n\nconst NUMBER_REGEX = /^\\d+$/;\n\nexport function setPathValue(\n data: Record<string, any> | Record<string, any>[],\n path: string | string[],\n value: unknown,\n) {\n const parts = Array.isArray(path) ?\n path :\n pathToArray(path);\n\n let temp = data;\n let index = 0;\n while (index < parts.length) {\n /* istanbul ignore next */\n if (!Array.isArray(temp) && !isObject(temp)) {\n break;\n }\n\n const key = parts[index] as keyof typeof temp;\n\n // [foo, '0']\n if (typeof temp[key] === 'undefined') {\n const match = NUMBER_REGEX.test(key);\n if (match) {\n (temp as Record<string, any>)[key] = [];\n } else {\n temp[key] = {};\n }\n }\n\n if (index === parts.length - 1) {\n temp[key] = value;\n break;\n }\n\n index++;\n temp = temp[key];\n }\n\n return data;\n}\n"],"names":["arrayToPath","parts","reduce","prev","segment","part","replace","test","BRACKET_NUMBER_REGEX","pathToArray","str","match","result","i","length","regex","exec","push","Character","isObject","input","Array","isArray","expandPathInternal","data","path","currPath","segments","key","rest","slice","GLOBSTAR","WILDCARD","Object","keys","flatMap","concat","nextPath","value","set","Set","expandPath","getPathValue","res","temp","index","PathInfo","_value","pathParts","name","parent","_parent","exists","_exists","constructor","getPathInfo","NUMBER_REGEX","setPathValue"],"mappings":"AAAA;;;;;;;;IAWO,SAASA,WAAAA,CAAYC,KAAwB,EAAA;AAChD,IAAA,OAAOA,KAAMC,CAAAA,MAAM,CAAC,CAACC,IAAMC,EAAAA,OAAAA,GAAAA;AACvB,QAAA,IAAIC,IAAO,GAAA,EAAA,CAAA;QAEXD,OAAUA,GAAAA,OAAAA,CAAQE,OAAO,CAAC,aAAe,EAAA,QAAA,CAAA,CAAA;QACzCF,OAAUA,GAAAA,OAAAA,CAAQE,OAAO,CAAC,KAAO,EAAA,KAAA,CAAA,CAAA;QAEjC,IAAI,OAAA,CAAQC,IAAI,CAACH,OAAU,CAAA,EAAA;;AAEvBC,YAAAA,IAAAA,GAAO,CAAC,CAAC,EAAED,OAAAA,CAAQ,CAAC,CAAC,CAAA;AACzB,SAAA,MAAO,IAAID,IAAM,EAAA;;AAEbE,YAAAA,IAAAA,GAAO,CAAC,CAAC,EAAED,OAAAA,CAAQ,CAAC,CAAA;SACjB,MAAA;;YAEHC,IAAOD,GAAAA,OAAAA,CAAAA;AACX,SAAA;A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Ac,EAAA;AAEd,IAAA,MAAMrC,QAAQoB,KAAMC,CAAAA,OAAO,CAACG,IAAAA,CAAAA,GACxBA,OACAhB,WAAYgB,CAAAA,IAAAA,CAAAA,CAAAA;AAEhB,IAAA,IAAImB,IAAOpB,GAAAA,IAAAA,CAAAA;AACX,IAAA,IAAIqB,KAAQ,GAAA,CAAA,CAAA;IACZ,MAAOA,KAAAA,GAAQ5C,KAAMa,CAAAA,MAAM,CAAE;mCAEzB,IAAI,CAACO,KAAAA,CAAMC,OAAO,CAACsB,IAAAA,CAAAA,IAAS,CAACzB,QAAAA,CAASyB,IAAO,CAAA,EAAA;AACzC,YAAA,MAAA;AACJ,SAAA;QAEA,MAAMhB,GAAAA,GAAM3B,KAAK,CAAC4C,KAAM,CAAA,CAAA;;AAGxB,QAAA,IAAI,OAAOD,IAAI,CAAChB,GAAAA,CAAI,KAAK,WAAa,EAAA;YAClC,MAAMjB,KAAAA,GAAQ6C,YAAajD,CAAAA,IAAI,CAACqB,GAAAA,CAAAA,CAAAA;AAChC,YAAA,IAAIjB,KAAO,EAAA;gBACNiC,IAA4B,CAAChB,GAAI,CAAA,GAAG,EAAE,CAAA;aACpC,MAAA;gBACHgB,IAAI,CAAChB,GAAI,CAAA,GAAG,EAAC,CAAA;AACjB,aAAA;AACJ,SAAA;AAEA,QAAA,IAAIiB,KAAU5C,KAAAA,KAAAA,CAAMa,MAAM,GAAG,CAAG,EAAA;YAC5B8B,IAAI,CAAChB,IAAI,GAAGU,KAAAA,CAAAA;AACZ,YAAA,MAAA;AACJ,SAAA;AAEAO,QAAAA,KAAAA,EAAAA,CAAAA;QACAD,IAAOA,GAAAA,IAAI,CAAChB,GAAI,CAAA,CAAA;AACpB,KAAA;IAEA,OAAOJ,IAAAA,CAAAA;AACX;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../src/helpers/array-to-path.ts","../src/helpers/path-to-array.ts","../src/path-expand/constants.ts","../src/utils/is-object.ts","../src/path-expand/module.ts","../src/path-value/get.ts","../src/path-value/set.ts","../src/path-info/module.ts","../src/path-info/helper.ts"],"sourcesContent":["/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\n/**\n * @see https://github.com/express-validator/express-validator/blob/bec1dcbaa29002dcd21093ec84818c4671063b5d/src/field-selection.ts#L214\n * @param parts\n */\nexport function arrayToPath(parts: readonly string[]) : string {\n return parts.reduce((prev, segment) => {\n let part = '';\n\n segment = segment.replace(/^\\[(\\d+)]$/g, '\\\\[$1]');\n segment = segment.replace(/\\./g, '\\\\.');\n\n if (/^\\d+$/.test(segment)) {\n // Index access\n part = `[${segment}]`;\n } else if (prev) {\n // Object key access\n part = `.${segment}`;\n } else {\n // Top level key\n part = segment;\n }\n\n return prev + part;\n }, '');\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport const BRACKET_NUMBER_REGEX = /(?<!\\\\)\\[(\\d+)]$/;\n\n/**\n * Convert string to property path array.\n *\n * @see https://github.com/lodash/lodash/blob/main/src/.internal/stringToPath.ts\n * @see https://github.com/chaijs/pathval\n *\n * @param segment\n */\nexport function pathToArray(segment: string) : string[] {\n const str = segment.replace(/([^\\\\])\\[/g, '$1.[');\n const parts = str.match(/(\\\\\\.|[^.]+?)+/g);\n if (!parts) {\n return [];\n }\n\n const result : string[] = [];\n\n for (let i = 0; i < parts.length; i++) {\n if (\n parts[i] === 'constructor' ||\n parts[i] === '__proto__' ||\n parts[i] === 'prototype'\n ) {\n continue;\n }\n\n const regex = BRACKET_NUMBER_REGEX.exec(parts[i]);\n if (regex) {\n result.push(regex[1]);\n } else {\n result.push(parts[i].replace(/\\\\([.[\\]])/g, '$1'));\n }\n }\n\n return result;\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum Character {\n WILDCARD = '*',\n GLOBSTAR = '**',\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function isObject(input: unknown) : input is Record<string, any> {\n return !!input &&\n typeof input === 'object' &&\n !Array.isArray(input);\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { Character } from './constants';\nimport type { PathExpanded } from './types';\nimport { isObject } from '../utils';\nimport { arrayToPath, pathToArray } from '../helpers';\n\nfunction expandPathVerboseInternal(\n data: Record<string, any>,\n path: string | string[],\n currPath: readonly string[] = [],\n currMatches: readonly (string | string[])[] = [],\n): PathExpanded[] {\n const segments = Array.isArray(path) ? path : pathToArray(path);\n if (!segments.length) {\n // no more paths to traverse\n return [\n {\n value: arrayToPath(currPath),\n matches: currMatches,\n },\n ];\n }\n\n const key = segments[0];\n const rest = segments.slice(1);\n\n if (\n typeof data !== 'undefined' &&\n data !== null &&\n !isObject(data) &&\n !Array.isArray(data)\n ) {\n if (key === Character.GLOBSTAR) {\n if (!rest.length) {\n // globstar leaves are always selected\n return [\n {\n value: arrayToPath(currPath),\n matches: currMatches,\n },\n ];\n }\n\n return [];\n }\n\n if (key === Character.WILDCARD) {\n return [];\n }\n\n // value is a primitive, paths being traversed from here might be in their prototype,\n // return the entire path\n return [{ value: arrayToPath([...currPath, ...segments]), matches: currMatches }];\n }\n\n // Use a non-null value so that non-existing fields are still selected\n data = data || {};\n\n if (key === Character.WILDCARD) {\n return Object.keys(data)\n .flatMap((key) => expandPathVerboseInternal(\n data[key],\n arrayToPath(rest),\n currPath.concat(key),\n currMatches.concat(key),\n ));\n }\n\n if (key === Character.GLOBSTAR) {\n return Object.keys(data)\n .flatMap((key) => {\n const nextPath = currPath.concat(key);\n const value = data[key];\n\n // recursively find matching sub-paths & skip the first remaining segment, if it matches the current key\n const children = expandPathVerboseInternal(value, arrayToPath(segments), nextPath, [key])\n .concat(rest[0] === key ? expandPathVerboseInternal(value, arrayToPath(rest.slice(1)), nextPath, []) : []);\n\n const pathMatches : string[] = [];\n const output : PathExpanded[] = [];\n for (let i = 0; i < children.length; i++) {\n /* istanbul ignore next */\n if (pathMatches.indexOf(children[i].value) !== -1) {\n continue;\n }\n\n pathMatches.push(children[i].value);\n\n output.push({\n value: children[i].value,\n matches: children[i].matches.length > 0 ?\n [...currMatches, children[i].matches.flat()] :\n currMatches,\n });\n }\n\n return output;\n });\n }\n\n return expandPathVerboseInternal(data[key], rest, currPath.concat(key), currMatches);\n}\n\n/**\n * Verbose expand wildcard and glob patterns.\n * Track wildcard/glob pattern matches.\n *\n * @param data\n * @param path\n */\nexport function expandPathVerbose(\n data: Record<string, any>,\n path: string | string[],\n): PathExpanded[] {\n return expandPathVerboseInternal(data, path);\n}\n\n/**\n * Expand wildcard and glob patterns to paths.\n *\n * @param data\n * @param path\n */\nexport function expandPath(\n data: Record<string, any>,\n path: string | string[],\n): string[] {\n return expandPathVerbose(data, path)\n .map((el) => el.value);\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { pathToArray } from '../helpers';\n\nexport function getPathValue(\n data: unknown,\n path: string | string[],\n): unknown {\n const parts = Array.isArray(path) ?\n path :\n pathToArray(path);\n\n let res : unknown | undefined;\n let temp = data;\n let index = 0;\n while (index < parts.length) {\n if (temp === null || typeof temp === 'undefined') {\n break;\n }\n\n if (parts[index] in Object(temp)) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n temp = temp[parts[index]];\n } else {\n break;\n }\n\n if (index === parts.length - 1) {\n res = temp;\n }\n\n index++;\n }\n\n return res;\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { pathToArray } from '../helpers';\nimport { isObject } from '../utils';\n\nconst NUMBER_REGEX = /^\\d+$/;\n\nexport function setPathValue(\n data: Record<string, any> | Record<string, any>[],\n path: string | string[],\n value: unknown,\n) {\n const parts = Array.isArray(path) ?\n path :\n pathToArray(path);\n\n let temp = data;\n let index = 0;\n while (index < parts.length) {\n /* istanbul ignore next */\n if (!Array.isArray(temp) && !isObject(temp)) {\n break;\n }\n\n const key = parts[index] as keyof typeof temp;\n\n // [foo, '0']\n if (typeof temp[key] === 'undefined') {\n const match = NUMBER_REGEX.test(key);\n if (match) {\n (temp as Record<string, any>)[key] = [];\n } else {\n temp[key] = {};\n }\n }\n\n if (index === parts.length - 1) {\n temp[key] = value;\n break;\n }\n\n index++;\n temp = temp[key];\n }\n\n return data;\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { getPathValue } from '../path-value/get';\nimport { pathToArray } from '../helpers';\n\nexport class PathInfo {\n protected data: unknown;\n\n protected pathParts: string[];\n\n protected _value: unknown;\n\n protected _parent: PathInfo | null | undefined;\n\n protected _exists: boolean | undefined;\n\n constructor(data: unknown, path: string | string[]) {\n this.data = data;\n\n if (Array.isArray(path)) {\n this.pathParts = path;\n } else {\n this.pathParts = pathToArray(path);\n }\n }\n\n get value() {\n if (typeof this._value !== 'undefined') {\n return this._value;\n }\n\n if (this.pathParts.length > 0) {\n this._value = getPathValue(this.data, this.pathParts);\n } else {\n this._value = this.data;\n }\n\n return this._value;\n }\n\n get name() : string | null {\n if (this.pathParts.length > 0) {\n return this.pathParts[this.pathParts.length - 1];\n }\n\n return null;\n }\n\n get parent() : PathInfo | null {\n if (typeof this._parent !== 'undefined') {\n return this._parent;\n }\n\n if (this.pathParts.length === 0) {\n this._parent = null;\n return this._parent;\n }\n\n if (this.pathParts.length > 1) {\n this._parent = new PathInfo(\n this.data,\n this.pathParts.slice(0, this.pathParts.length - 1),\n );\n } else {\n this._parent = new PathInfo(this.data, []);\n }\n\n return this._parent;\n }\n\n get exists() : boolean {\n if (typeof this._exists !== 'undefined') {\n return this._exists;\n }\n\n if (!this.name || !this.parent) {\n this._exists = true;\n return this._exists;\n }\n\n if (\n this.parent.value !== null &&\n typeof this.parent.value !== 'undefined'\n ) {\n this._exists = this.name in Object(this.parent.value);\n } else {\n this._exists = false;\n }\n\n return this._exists;\n }\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { PathInfo } from './module';\n\nexport function getPathInfo(\n data: Record<string, any>,\n path: string | string[],\n) : PathInfo {\n return new PathInfo(data, path);\n}\n"],"names":["arrayToPath","parts","reduce","prev","segment","part","replace","test","BRACKET_NUMBER_REGEX","pathToArray","str","match","result","i","length","regex","exec","push","Character","isObject","input","Array","isArray","expandPathVerboseInternal","data","path","currPath","currMatches","segments","value","matches","key","rest","slice","GLOBSTAR","WILDCARD","Object","keys","flatMap","concat","nextPath","children","pathMatches","output","indexOf","flat","expandPathVerbose","expandPath","map","el","getPathValue","res","temp","index","NUMBER_REGEX","setPathValue","PathInfo","_value","pathParts","name","parent","_parent","exists","_exists","constructor","getPathInfo"],"mappings":"AAAA;;;;;;;;IAWO,SAASA,WAAAA,CAAYC,KAAwB,EAAA;AAChD,IAAA,OAAOA,KAAMC,CAAAA,MAAM,CAAC,CAACC,IAAMC,EAAAA,OAAAA,GAAAA;AACvB,QAAA,IAAIC,IAAO,GAAA,EAAA,CAAA;QAEXD,OAAUA,GAAAA,OAAAA,CAAQE,OAAO,CAAC,aAAe,EAAA,QAAA,CAAA,CAAA;QACzCF,OAAUA,GAAAA,OAAAA,CAAQE,OAAO,CAAC,KAAO,EAAA,KAAA,CAAA,CAAA;QAEjC,IAAI,OAAA,CAAQC,IAAI,CAACH,OAAU,CAAA,EAAA;;AAEvBC,YAAAA,IAAAA,GAAO,CAA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AACjC,SAAA;AACJ,KAAA;AAmEJ;;ACvFO,SAASwC,WAAAA,CACZzC,IAAyB,EACzBC,IAAuB,EAAA;IAEvB,OAAO,IAAI+B,SAAShC,IAAMC,EAAAA,IAAAA,CAAAA,CAAAA;AAC9B;;;;"}
@@ -0,0 +1,2 @@
1
+ export * from './module';
2
+ export * from './types';
@@ -0,0 +1,16 @@
1
+ import type { PathExpanded } from './types';
2
+ /**
3
+ * Verbose expand wildcard and glob patterns.
4
+ * Track wildcard/glob pattern matches.
5
+ *
6
+ * @param data
7
+ * @param path
8
+ */
9
+ export declare function expandPathVerbose(data: Record<string, any>, path: string | string[]): PathExpanded[];
10
+ /**
11
+ * Expand wildcard and glob patterns to paths.
12
+ *
13
+ * @param data
14
+ * @param path
15
+ */
16
+ export declare function expandPath(data: Record<string, any>, path: string | string[]): string[];
@@ -0,0 +1,4 @@
1
+ export type PathExpanded = {
2
+ value: string;
3
+ matches: readonly (string | string[])[];
4
+ };
@@ -1,2 +1,2 @@
1
- import { PathInfo } from './path-info';
1
+ import { PathInfo } from './module';
2
2
  export declare function getPathInfo(data: Record<string, any>, path: string | string[]): PathInfo;
@@ -0,0 +1,2 @@
1
+ export * from './helper';
2
+ export * from './module';
@@ -0,0 +1,2 @@
1
+ export * from './get';
2
+ export * from './set';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pathtrace",
3
- "version": "1.0.0-beta.2",
3
+ "version": "1.0.0",
4
4
  "description": "Simplifies working with nested objects and arrays by providing easy methods to retrieve, set, and check values at any path.",
5
5
  "exports": {
6
6
  "./package.json": "./package.json",
@@ -26,11 +26,13 @@
26
26
  "lint:fix": "npm run lint -- --fix"
27
27
  },
28
28
  "keywords": [
29
- "nested-objects",
30
29
  "path",
31
- "path-retrival",
32
- "javascript",
33
30
  "path-info",
31
+ "path-value",
32
+ "expand-path",
33
+ "path-retrival",
34
+ "get-path",
35
+ "nested-objects",
34
36
  "deep-access"
35
37
  ],
36
38
  "author": {
@@ -51,18 +53,18 @@
51
53
  "@rollup/plugin-node-resolve": "^15.2.3",
52
54
  "@rollup/plugin-swc": "^0.3.1",
53
55
  "@swc/jest": "^0.2.36",
54
- "@tada5hi/commitlint-config": "^1.2.1",
55
- "@tada5hi/eslint-config-typescript": "^1.2.11",
56
+ "@tada5hi/commitlint-config": "^1.2.2",
57
+ "@tada5hi/eslint-config-typescript": "^1.2.12",
56
58
  "@tada5hi/semantic-release": "^0.3.1",
57
59
  "@tada5hi/tsconfig": "^0.5.1",
58
60
  "@types/jest": "^29.5.12",
59
- "@types/node": "^22.5.0",
61
+ "@types/node": "^22.5.2",
60
62
  "@types/pathval": "^1.1.2",
61
63
  "cross-env": "^7.0.3",
62
64
  "eslint": "^8.37.0",
63
65
  "husky": "^9.0.11",
64
66
  "jest": "^29.7.0",
65
- "rollup": "^4.21.1",
67
+ "rollup": "^4.21.2",
66
68
  "semantic-release": "^22.0.12",
67
69
  "ts-jest": "^29.2.5",
68
70
  "typescript": "^5.5.4"
@@ -1,7 +0,0 @@
1
- /**
2
- * Expand wildcard and glob patterns to paths.
3
- *
4
- * @param data
5
- * @param path
6
- */
7
- export declare function expandPath(data: Record<string, any>, path: string | string[]): string[];
File without changes