Skip to content

Commit 0c13f9c

Browse files
committed
chore: remove unused helpers
1 parent c35fe96 commit 0c13f9c

File tree

1 file changed

+22
-40
lines changed

1 file changed

+22
-40
lines changed

src/Common/Helper.tsx

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -618,27 +618,25 @@ export const getFilteredChartVersions = (charts, selectedChartType) =>
618618
}))
619619

620620
/**
621-
* This function takes a list of strings and checks if the strings
622-
* have prefix matches in the list of prefixes
623-
* @param strings check if a @string has a prefix match in @prefixes
624-
* @param prefixes list of prefixes
625-
* @returns array of booleans corresponding to each string in @strings
621+
* Removes nulls from the arrays in the provided object
622+
* @param {object} object from which we need to delete nulls in its arrays
623+
* @returns object after removing (in-place) the null items in arrays
626624
*/
627-
export const getPrefixMatches = (strings: string[], prefixes: string[]) => {
628-
// NOTE: a trie could have been used but it would have been memory inefficient
629-
const set = new Set(prefixes)
630-
return strings.map((string) => {
631-
for (let index = 0; index <= string.length; index++) {
632-
// NOTE: slice in v8 is O(1) https://mrale.ph/blog/2016/11/23/making-less-dart-faster.html
633-
// due to using SlicedString construct that only keeps pointer to original string
634-
// alternative tries would be tree structure (hard to cache)
635-
const slice = string.slice(0, index)
636-
if (set.has(slice)) {
637-
return true
638-
}
639-
}
640-
return false
625+
export const recursivelyRemoveNullsFromArraysInObject = (object: object) => {
626+
// NOTE: typeof null === 'object'
627+
if (typeof object !== 'object' || !object) {
628+
return object
629+
}
630+
if (Array.isArray(object)) {
631+
return object.filter((item) => {
632+
recursivelyRemoveNullsFromArraysInObject(item)
633+
return !!item
634+
})
635+
}
636+
Object.keys(object).forEach((key) => {
637+
object[key] = recursivelyRemoveNullsFromArraysInObject(object[key])
641638
})
639+
return object
642640
}
643641

644642
const _joinObjects = (A: object, B: object) => {
@@ -655,8 +653,8 @@ const _joinObjects = (A: object, B: object) => {
655653
}
656654

657655
/**
658-
* Merges @objects into one
659-
* @param objects list of js objects
656+
* Merges the objects into one object
657+
* @param {object[]} objects list of js objects
660658
* @returns object after the merge
661659
*/
662660
export const joinObjects = (objects: object[]) => {
@@ -679,11 +677,10 @@ const buildObjectFromPathTokens = (index: number, tokens: string[], value: any)
679677
: { [key]: buildObjectFromPathTokens(index + 1, tokens, value) }
680678
}
681679

682-
// TODO: learn how to write js doc comments
683680
/**
684-
* Builds an object from the provided @path
685-
* @param path JSON pointer path of the form /path/to/1/...
686-
* @param value property value
681+
* Builds an object from the provided path
682+
* @param {string} path JSON pointer path of the form /path/to/1/...
683+
* @param {any} value property value
687684
* @returns final object formed from the path
688685
*/
689686
export const buildObjectFromPath = (path: string, value: any) => {
@@ -708,21 +705,6 @@ export const getRegexMatchPositions = (string: string, regex: RegExp): number[]
708705
return [pos, ...getRegexMatchPositions(nextToken, regex).map((n) => n + pos + 1)]
709706
}
710707

711-
// TODO: write js doc comment
712-
export const powerSetOfSubstringsFromStart = (strings: string[]) =>
713-
strings.flatMap((key) => {
714-
const _keys = [key]
715-
const positions = getRegexMatchPositions(key, /\.|\[|\]/g)
716-
positions.forEach((position) => {
717-
const ch = key.charAt(position)
718-
if (ch === ']') {
719-
return
720-
}
721-
_keys.push(key.slice(0, position))
722-
})
723-
return _keys
724-
})
725-
726708
/**
727709
* Returns a debounced variant of the function
728710
*/

0 commit comments

Comments
 (0)