Skip to content

Commit 675dbd7

Browse files
committed
feat: add utility func
1 parent 5395002 commit 675dbd7

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

package-lock.json

Lines changed: 0 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@
9292
"dependencies": {
9393
"ansi_up": "^5.2.1",
9494
"fast-json-patch": "^3.1.1",
95-
"jsonpath-plus": "^7.2.0",
9695
"react-monaco-editor": "^0.54.0",
9796
"sass": "^1.69.7",
9897
"tslib": "^2.4.1"

src/Common/Helper.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,23 @@ export const getRegexMatchPositions = (string: string, regex: RegExp): number[]
705705
return [pos, ...getRegexMatchPositions(nextToken, regex).map((n) => n + pos + 1)]
706706
}
707707

708+
/**
709+
* Returns all the substrings from 0th index to progressively next regex match position
710+
* Eg. Suppose a string is /path/to/folder then it will return [/path, /path/to, /path/to/folder]
711+
* @param strings list of strings
712+
* @param regex that matches the separators for the substrings
713+
* @returns set of substrings
714+
*/
715+
export const powerSetOfSubstringsFromStart = (strings: string[], regex: RegExp) =>
716+
strings.flatMap((key) => {
717+
const _keys = [key]
718+
const positions = getRegexMatchPositions(key, regex)
719+
positions.forEach((position) => {
720+
_keys.push(key.slice(0, position))
721+
})
722+
return _keys
723+
})
724+
708725
/**
709726
* Returns a debounced variant of the function
710727
*/

0 commit comments

Comments
 (0)