Download admin-bro/src/utils/flat/select-params.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/admin-bro/src/utils/flat/select-params.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/admin-bro/src/utils/flat/select-params.ts
-
curl -L -o select-params.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/admin-bro/src/utils/flat/select-params.ts
1.13 kB
| import { propertyKeyRegex } from './property-key-regex.js' | |
| import { FlattenParams, GetOptions } from './flat.types.js' | |
| /** | |
| * @load ./select-params.doc.md | |
| * @memberof module:flat | |
| * @param {FlattenParams} params | |
| * @param {string | Array<string>} properties | |
| * @param {GetOptions} [options] | |
| * @returns {FlattenParams} | |
| */ | |
| const selectParams = ( | |
| params: FlattenParams, | |
| properties: string | Array<string>, | |
| options?: GetOptions, | |
| ): FlattenParams => { | |
| const propertyArray = Array.isArray(properties) ? properties : [properties] | |
| const selected = propertyArray | |
| .filter((propertyPath) => !!propertyPath) | |
| .reduce((globalMemo, propertyPath) => { | |
| const regex = propertyKeyRegex(propertyPath, options) | |
| const filtered = Object.keys(params) | |
| // filter all keys which starts with property path | |
| .filter((key) => key.match(regex)) | |
| .reduce((memo, key) => { | |
| memo[key] = (params[key] as string) | |
| return memo | |
| }, {} as FlattenParams) | |
| return { | |
| ...globalMemo, | |
| ...filtered, | |
| } | |
| }, {} as FlattenParams) | |
| return selected | |
| } | |
| export { selectParams } | |