MCPcopy Index your code
hub / github.com/callstack/agent-device / parseStringMember

Function parseStringMember

src/utils/string-enum.ts:22–39  ·  view source on GitHub ↗
(
  values: T,
  value: string | undefined,
  options: {
    normalize?: (raw: string) => string;
    message?: string | ((raw: string | undefined) => string);
  } = {},
)

Source from the content-addressed store, hash-verified

20 * device rotation `left` -> `landscape-left`) keep their own logic.
21 */
22export function parseStringMember<const T extends readonly string[]>(
23 values: T,
24 value: string | undefined,
25 options: {
26 normalize?: (raw: string) => string;
27 message?: string | ((raw: string | undefined) => string);
28 } = {},
29): T[number] {
30 const normalized = value === undefined ? undefined : (options.normalize?.(value) ?? value);
31 if (normalized !== undefined && isStringMember(values, normalized)) {
32 return normalized;
33 }
34 const message = typeof options.message === 'function' ? options.message(value) : options.message;
35 throw new AppError(
36 'INVALID_ARGS',
37 message ?? `Invalid value: ${value}. Use ${values.join('|')}.`,
38 );
39}
40
41export function defineStringEnum<const T extends readonly string[]>(
42 values: T,

Callers 6

readLogsActionFunction · 0.90
readNetworkIncludeFunction · 0.90
readAudioActionFunction · 0.90
readAudioProbeActionFunction · 0.90
parseGestureDirectionFunction · 0.90
defineStringEnumFunction · 0.85

Calls 1

isStringMemberFunction · 0.85

Tested by

no test coverage detected