UNPKG

@thi.ng/parse

Version:

Purely functional parser combinators & AST generation for generic inputs

16 lines (15 loc) 459 B
import { isPlainObject } from "@thi.ng/checks/is-plain-object"; import { isSet } from "@thi.ng/checks/is-set"; import { satisfy, satisfyD } from "./satisfy.js"; const oneOfP = (opts) => isSet(opts) ? (x) => opts.has(x) : isPlainObject(opts) ? (x) => opts[x] : (x) => opts.includes(x); function oneOf(opts, id = "oneOf") { return satisfy(oneOfP(opts), id); } function oneOfD(opts) { return satisfyD(oneOfP(opts)); } export { oneOf, oneOfD, oneOfP };