(
obj: Record<string, any>,
keyList: readonly string[],
options: {
keyFormat?: 'camelCase' | 'snakeCase' | 'kebabCase'
stringifyValue?: boolean
} = {},
)
| 396 | } |
| 397 | |
| 398 | export const pickAndFormatStringList = ( |
| 399 | obj: Record<string, any>, |
| 400 | keyList: readonly string[], |
| 401 | options: { |
| 402 | keyFormat?: 'camelCase' | 'snakeCase' | 'kebabCase' |
| 403 | stringifyValue?: boolean |
| 404 | } = {}, |
| 405 | ): readonly string[] => { |
| 406 | const result: string[] = [] |
| 407 | const { keyFormat, stringifyValue } = options |
| 408 | |
| 409 | keyList.forEach((key) => { |
| 410 | if (Object.hasOwn(obj, key) && obj[key] !== undefined) { |
| 411 | const propertyKey = keyFormat ? changeCase(key, keyFormat) : key |
| 412 | const propertyValue = obj[key] |
| 413 | |
| 414 | if (Array.isArray(propertyValue)) { |
| 415 | result.push( |
| 416 | `${propertyKey}=${ |
| 417 | stringifyValue |
| 418 | ? JSON.stringify(propertyValue.join(',')) |
| 419 | : propertyValue.join(',') |
| 420 | }`, |
| 421 | ) |
| 422 | } else { |
| 423 | result.push( |
| 424 | `${propertyKey}=${ |
| 425 | stringifyValue ? JSON.stringify(propertyValue) : propertyValue |
| 426 | }`, |
| 427 | ) |
| 428 | } |
| 429 | } |
| 430 | }) |
| 431 | |
| 432 | return result |
| 433 | } |
| 434 | |
| 435 | /** |
| 436 | * Pick and format keys from an object |
no test coverage detected