Registry / serialization / prepr
library2.0.1jsnpmunverified

String preprocessor implementing C/GLSL preprocessor-style directives (#define, #if, #ifdef, #elif, #else, #endif) for JavaScript environments. Version 2.0+ uses ESM and uses 'subscript' for expression evaluation. Designed for glsl-transpiler, it supports variable interpolation and macro functions. Lightweight, no external dependencies. Ideal for preprocessing GLSL shader code or any string that benefits from compile-time conditionals.

npm install prepr
INSTALL
IMPORT
SIG · PREPR
P
prepr
serializationjavascriptv2.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

default
import prepr from 'prepr';
const prepr = require('prepr');
ESM-only since v2.0.0. CommonJS require will fail.
default with type
import prepr from 'prepr';
import { prepr } from 'prepr';
No named export; must use default import.

Demonstrates basic usage of prepr with #define, #ifdef, and variable interpolation.

import prepr from 'prepr'; const input = ` #define A 2 #ifdef A var a = A; #endif var b = myVar; `; const result = prepr(input, { myVar: 1 }); console.log(result); // Output: // // var a = 2; // var b = 1; //
Debug
Known issues
breakingv2.0.0 changed from CommonJS to ESM. `require('prepr')` no longer works.
fix
Use `import prepr from 'prepr'` in an ESM context or use dynamic import.
affects: >=2.0.0
breakingv2.0.0 replaced `expression-eval` with `subscript` for expression evaluation. Some edge cases in expressions may behave differently.
fix
Test expressions with new evaluator; avoid unsupported features.
affects: >=2.0.0
gotchaThe preprocessor does not support recursive macro expansion or concatenation (e.g., ## operator).
fix
Use provided variables or macros directly; do not rely on full C preprocessor.
affects: >=0.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/prepr/index.js from /path/to/user/code.js not supported.
Using CommonJS require() on an ESM-only package after v2.0.0.
fix
Change to import: `import prepr from 'prepr'` and ensure project type: module or use .mjs extension.
SyntaxError: Unexpected token 'export'
Trying to require() prepr in a CommonJS file without ESM support.
fix
Either convert to ESM or use dynamic import: `const prepr = (await import('prepr')).default`
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
prepr — npm install prepr · libregistry