A lightweight TypeScript parser for a subset of the CUE configuration language. Produces a fully typed AST. Zero runtime dependencies. Works in the browser and Node.js.
pnpm add cue-tsimport { parse } from "cue-ts";
const ast = parse(`
name: string
age: int & >=0
role: "admin" | "user"
`);
// ast.kind === "file"
// ast.declarations contains CueField nodesimport { parse, CueParseError } from "cue-ts";
try {
parse("invalid: {");
} catch (e) {
if (e instanceof CueParseError) {
console.log(e.line, e.column, e.message);
}
}| Construct | Example |
|---|---|
| Literals | "hello", 42, 3.14, true, false, null |
| Multi-line strings | """ ... """ |
| Type keywords | string, int, float, bool, number, bytes |
| Top / Bottom | _, _|_ |
| Structs | { name: "Alice" } |
| Optional fields | name?: string |
| Definitions | #Name: { ... } |
| Lists | [1, 2, 3], [...string] |
| Constraints | int & >=0, string & =~"pattern" |
| Disjunctions | "a" | "b" | "c" |
| Comments | // single line |
| Quoted labels | "my-key": value |
Every node has a kind discriminant for exhaustive matching:
CueFile-- top-level containerCueField--label: value(withoptionalflag)CueStruct--{ fields }CueList--[elements]CueLiteral-- string, number, bool, or nullCueIdent-- identifier referenceCueType-- type keyword (string,int,top, etc.)CueUnaryExpr-- constraint operator (>=,<,=~, etc.)CueBinaryExpr-- conjunction (&)CueDisjunction-- alternatives (|)CueDefinition--#Name: valueCueComment--// textCueEllipsis--...or...type
All types are exported and available for import.
This is a subset parser. It does not support:
- CUE evaluation or unification
- Import/package resolution
- Constraint solving
- Comprehensions
- Interpolation
- Parenthesized expressions
pnpm install
pnpm test # vitest
pnpm build # tsup (dual CJS/ESM + types)
pnpm lint # biomeSee CHANGELOG.md for release history.
This project uses Conventional Commits and git-cliff for automated changelog generation.