MCPcopy Index your code
hub / github.com/SoftwareBrothers/adminjs / removePath

Function removePath

src/utils/flat/remove-path.ts:15–40  ·  view source on GitHub ↗
(params: FlattenParams, path: string)

Source from the content-addressed store, hash-verified

13 * @returns {FlattenParams}
14 */
15const removePath = (params: FlattenParams, path: string): FlattenParams => {
16 // by default simply filter out elements from the object
17 let filtered = filterOutParams(params, path)
18
19 // reverse means that we iterate from the closes parent
20 const parentPaths = pathToParts(path).reverse()
21
22 // but if one of the parent is an array
23 parentPaths.find((parentPath, parentIndex) => {
24 const parent = get(params, parentPath)
25 if (Array.isArray(parent)) {
26 // previous element is stringified index like 'property.1'
27 const previousPaths = parentPaths[parentIndex - 1].split(DELIMITER)
28 // so this is the index: 1
29 const previousPathIndex = previousPaths[previousPaths.length - 1]
30 parent.splice(+previousPathIndex, 1)
31 filtered = set(params, parentPath, parent)
32 // this works just for the firstly found array item, because in case of removing the last one
33 // it leaves `[]` as a value.
34 return true
35 }
36 return false
37 })
38
39 return filtered
40}
41
42export { removePath }

Callers 1

Calls 6

filterOutParamsFunction · 0.85
pathToPartsFunction · 0.85
getFunction · 0.85
setFunction · 0.85
findMethod · 0.80
isArrayMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…