{"id":26098,"library":"prepr","title":"prepr","description":"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.","status":"active","version":"2.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/dy/prepr","tags":["javascript","glsl","c","preprocessor","preprocess","macro","macros","define"],"install":[{"cmd":"npm install prepr","lang":"bash","label":"npm"},{"cmd":"yarn add prepr","lang":"bash","label":"yarn"},{"cmd":"pnpm add prepr","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only since v2.0.0. CommonJS require will fail.","wrong":"const prepr = require('prepr');","symbol":"default","correct":"import prepr from 'prepr';"},{"note":"No named export; must use default import.","wrong":"import { prepr } from 'prepr';","symbol":"default with type","correct":"import prepr from 'prepr';"}],"quickstart":{"code":"import prepr from 'prepr';\n\nconst input = `\n  #define A 2\n  #ifdef A\n    var a = A;\n  #endif\n  var b = myVar;\n`;\n\nconst result = prepr(input, {\n  myVar: 1\n});\n\nconsole.log(result);\n// Output:\n//\n//   var a = 2;\n//   var b = 1;\n//","lang":"typescript","description":"Demonstrates basic usage of prepr with #define, #ifdef, and variable interpolation."},"warnings":[{"fix":"Use `import prepr from 'prepr'` in an ESM context or use dynamic import.","message":"v2.0.0 changed from CommonJS to ESM. `require('prepr')` no longer works.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Test expressions with new evaluator; avoid unsupported features.","message":"v2.0.0 replaced `expression-eval` with `subscript` for expression evaluation. Some edge cases in expressions may behave differently.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Use provided variables or macros directly; do not rely on full C preprocessor.","message":"The preprocessor does not support recursive macro expansion or concatenation (e.g., ## operator).","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Change to import: `import prepr from 'prepr'` and ensure project type: module or use .mjs extension.","cause":"Using CommonJS require() on an ESM-only package after v2.0.0.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/prepr/index.js from /path/to/user/code.js not supported."},{"fix":"Either convert to ESM or use dynamic import: `const prepr = (await import('prepr')).default`","cause":"Trying to require() prepr in a CommonJS file without ESM support.","error":"SyntaxError: Unexpected token 'export'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}