( obj: Record<string, any>, include: Array<string | RegExp> )
| 563 | * @public |
| 564 | */ |
| 565 | export function only( |
| 566 | obj: Record<string, any>, |
| 567 | include: Array<string | RegExp> |
| 568 | ): Record<string, any> { |
| 569 | const clean: Record<string, any> = {} |
| 570 | const exps = include.filter((n) => n instanceof RegExp) as RegExp[] |
| 571 | include.forEach((key) => { |
| 572 | if (!(key instanceof RegExp)) { |
| 573 | clean[key] = obj[key] |
| 574 | } |
| 575 | }) |
| 576 | Object.keys(obj).forEach((key) => { |
| 577 | if (exps.some((exp) => exp.test(key))) { |
| 578 | clean[key] = obj[key] |
| 579 | } |
| 580 | }) |
| 581 | return clean |
| 582 | } |
| 583 | |
| 584 | /** |
| 585 | * This converts kebab-case to camelCase. It ONLY converts from kebab to camel. |
no outgoing calls
no test coverage detected