TS-Rex is published to the npm registry asDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/fajarnugraha37/ts-rex/llms.txt
Use this file to discover all available pages before exploring further.
@fajarnugraha37/ts-rex. You can install it with any Node.js-compatible package manager. The package ships prebuilt ESM and CJS bundles alongside TypeScript declaration files, so no additional build configuration is required.
Install the package
Choose your package manager and run the corresponding command:TypeScript requirement
TS-Rex uses advanced generic type inference features introduced in TypeScript 5.0. The phantom type state tracking and compile-time capture inference rely on these features and will not work correctly with earlier versions. You can check your current TypeScript version with:package.json:
Module formats
The package ships three output formats from thedist/ directory, so it works in any modern JavaScript environment without extra configuration:
| File | Format | Use case |
|---|---|---|
dist/index.mjs | ESM | Node.js with "type": "module", bundlers (Vite, esbuild, Rollup) |
dist/index.cjs | CJS | Node.js CommonJS, older bundlers |
dist/index.d.ts | Type declarations | TypeScript type checking in all environments |
package.json exports field maps these automatically based on your environment:
Import the library
Once installed, import therx factory function to start building patterns. This is the only named export you need for most use cases:
rx:
Zero runtime dependencies
TS-Rex has no runtime dependencies. ThedevDependencies in package.json include build tools (tsup, tsx), testing utilities (expect-type), and linting (eslint, typescript-eslint) — none of which are bundled into the distributed package.
Because TS-Rex depends only on native TypeScript and
RegExp, adding it to your project does not increase your production bundle size beyond the library itself.Next steps
Quickstart
Build your first type-safe regex pattern in under five minutes.
Core concepts
Understand the AST engine, immutability, and phantom type state.