MCPcopy Create free account
hub / github.com/AdbAutoPlayer/AdbAutoPlayer / asNonEmptyStringArray

Function asNonEmptyStringArray

src/lib/form/types.ts:50–76  ·  view source on GitHub ↗
(
  schema: any,
)

Source from the content-addressed store, hash-verified

48}
49
50export function asNonEmptyStringArray(
51 schema: any,
52): NonEmptyArray<string> | null {
53 const arraySchema = asArraySchema(schema);
54
55 if (!arraySchema) {
56 return null;
57 }
58
59 // For TaskList: items is an object with a "name" property holding the enum
60 const items = arraySchema.items as any;
61 if (items?.type === "object" && items?.properties?.name?.enum) {
62 const choices = items.properties.name.enum;
63 if (isStringArray(choices) && choices.length > 0) {
64 return choices as NonEmptyArray<string>;
65 }
66 return null;
67 }
68
69 const choices = arraySchema.items.enum;
70
71 if (!isStringArray(choices) || choices.length === 0) {
72 return null;
73 }
74
75 return choices as NonEmptyArray<string>;
76}
77
78const isStringArray = (arr: any): arr is string[] =>
79 Array.isArray(arr) && arr.every((i) => typeof i === "string");

Callers

nothing calls this directly

Calls 2

asArraySchemaFunction · 0.85
isStringArrayFunction · 0.85

Tested by

no test coverage detected