A
arktype4mo ago
Domin

Stringified array

Is there a type for stringified arrays i.e. elements joined with comma: "item1,item2,item3"?
2 Replies
CodyC
CodyC4mo ago
Not that I know of, but it's pretty easy to do with a pipe:
import { type } from "arktype"

const CSV = type("string").pipe(
(s) => s.split(/, ?/),
type("string[] > 2")
)

const Thing = type({
list: CSV
})

const out = Thing({
list: "foo, bar, baz"
})
import { type } from "arktype"

const CSV = type("string").pipe(
(s) => s.split(/, ?/),
type("string[] > 2")
)

const Thing = type({
list: CSV
})

const out = Thing({
list: "foo, bar, baz"
})
Domin
DominOP4mo ago
Thanks

Did you find this page helpful?