MCPcopy
hub / github.com/surgioproject/surgio / pickAndFormatStringList

Function pickAndFormatStringList

src/utils/index.ts:398–433  ·  view source on GitHub ↗
(
  obj: Record<string, any>,
  keyList: readonly string[],
  options: {
    keyFormat?: 'camelCase' | 'snakeCase' | 'kebabCase'
    stringifyValue?: boolean
  } = {},
)

Source from the content-addressed store, hash-verified

396}
397
398export 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

Callers 5

nodeListMapperFunction · 0.90
nodeListMapperFunction · 0.90
getSurgeWireguardNodesFunction · 0.85
nodeListMapperFunction · 0.85
appendCommonConfigFunction · 0.85

Calls 1

changeCaseFunction · 0.85

Tested by

no test coverage detected