Registry / serialization / babel-plugin-spectypes

babel-plugin-spectypes

JSON →
library2.1.11jsnpmunverified

Babel plugin (v2.1.11) that compiles spectypes validators at build time, producing fast, eval-free runtime validation for TypeScript/JavaScript. Current stable version is 2.1.11 with bi-monthly releases. Key differentiators: compiles validators into simple if/else statements (no eval or new Function), can outperform ajv in benchmarks, detailed error messages with failure paths, TypeScript type inference, and extensive property-based testing. Requires @babel/core as a peer dependency and spectypes runtime package.

npm install babel-plugin-spectypes
INSTALL
IMPORT
SIG · BABEL-PLUGIN-SPECT
B
babel-plugin-spectypes
serializationjavascriptv2.1.11
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

array
import { array } from 'spectypes'
import { array } from 'babel-plugin-spectypes'
Validators are imported from 'spectypes', not the plugin package.
number
import { number } from 'spectypes'
const number = require('spectypes').number
CommonJS require is supported but ESM import is preferred.
struct
import { struct } from 'spectypes'
Named export, also supports aliases like import { struct as myStruct } from 'spectypes'.

Shows installation, Babel configuration, and basic usage with array, number, and struct validators compiled by the plugin.

// Install: npm i spectypes && npm i -D babel-plugin-spectypes // .babelrc { "plugins": ["babel-plugin-spectypes"] } // source.ts import { array, number, struct } from 'spectypes' const NumberArray = array(number) const User = struct({ name: string(), age: number() }) // The plugin transforms the variable declarations into compiled validators at build time. // No runtime compilation needed.
Debug
Known issues
breakingVersion 2.0.0 introduced major breaking changes; ensure your code is compatible before upgrading from v1.
fix
Review the changelog and update your validator usage accordingly.
affects: >=2.0.0
gotchaThe plugin only transforms imports from the 'spectypes' package; custom validators or renamed imports require careful setup.
fix
Ensure all validators are imported directly from 'spectypes' and that the Babel plugin is configured correctly.
affects: >=1.0.0
deprecatedSome older validators may be deprecated in future versions; check the documentation for updates.
fix
Upgrade to the latest version and replace deprecated validators with their modern equivalents.
affects: <2.0.0
gotchaThe plugin runs at build time and may not work correctly if used with other Babel transforms that modify imports before this plugin processes them.
fix
Ensure babel-plugin-spectypes runs after any import transformation plugins, or use 'plugin ordering' to control execution order.
affects: >=1.0.0
gotchaTypeScript users must ensure that Babel is configured to handle TypeScript (e.g., @babel/preset-typescript) for the plugin to process .ts files.
fix
Add '@babel/preset-typescript' to your Babel presets if you are using TypeScript.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'spectypes'
Missing runtime dependency 'spectypes'.
fix
Run 'npm install spectypes' to install the runtime package.
SyntaxError: Unexpected token import
Running code directly with Node.js without build step or using CommonJS require incorrectly.
fix
Ensure you are using a build step with Babel and Webpack/Rollup, or use CommonJS require correctly: const { array } = require('spectypes').
ReferenceError: array is not defined
Forgetting to import validators from 'spectypes' or import path incorrect.
fix
Add 'import { array } from \"spectypes\"' at the top of your file.
Error: Plugin babel-plugin-spectypes not found
The babel-plugin-spectypes package is not installed or not listed in Babel config correctly.
fix
Run 'npm install --save-dev babel-plugin-spectypes' and ensure your .babelrc or babel.config.js includes '\"plugins\": [\"babel-plugin-spectypes\"]'.
Upgrade
Version history
2.1.11latest on npm
Audit
Dependencies
@babel/corerequiredpeer dependency required for Babel plugin transformation
spectypesrequiredruntime library containing validators and helpers, must be installed separately
Agent activity
15 hits · last 30 days
node
14
OpenAI (training)
1
Resources
babel-plugin-spectypes — npm install babel-plugin-spectypes · libregistry