( params: FlattenParams, properties: string | Array<string>, options?: GetOptions, )
| 10 | * @returns {FlattenParams} |
| 11 | */ |
| 12 | const selectParams = ( |
| 13 | params: FlattenParams, |
| 14 | properties: string | Array<string>, |
| 15 | options?: GetOptions, |
| 16 | ): FlattenParams => { |
| 17 | const propertyArray = Array.isArray(properties) ? properties : [properties] |
| 18 | const selected = propertyArray |
| 19 | .filter((propertyPath) => !!propertyPath) |
| 20 | .reduce((globalMemo, propertyPath) => { |
| 21 | const regex = propertyKeyRegex(propertyPath, options) |
| 22 | const filtered = Object.keys(params) |
| 23 | // filter all keys which starts with property path |
| 24 | .filter((key) => key.match(regex)) |
| 25 | .reduce((memo, key) => { |
| 26 | memo[key] = (params[key] as string) |
| 27 | return memo |
| 28 | }, {} as FlattenParams) |
| 29 | return { |
| 30 | ...globalMemo, |
| 31 | ...filtered, |
| 32 | } |
| 33 | }, {} as FlattenParams) |
| 34 | return selected |
| 35 | } |
| 36 | |
| 37 | export { selectParams } |
no test coverage detected
searching dependent graphs…