https://github.com/dy/prepr
C/GLSL-preprocessor in JS
https://github.com/dy/prepr
Last synced: 9 months ago
JSON representation
C/GLSL-preprocessor in JS
- Host: GitHub
- URL: https://github.com/dy/prepr
- Owner: dy
- Created: 2016-03-26T19:59:45.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2023-01-30T16:36:11.000Z (over 3 years ago)
- Last Synced: 2025-08-18T05:29:11.860Z (10 months ago)
- Language: JavaScript
- Homepage: https://npmjs.org/package/prepr
- Size: 84 KB
- Stars: 8
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
> Preprocess any string in C/GLSL-preprocessor fashion.
[](https://npmjs.org/package/prepr/)
```js
import prepr from 'prepr';
prepr(`
#define A 2;
#ifdef A
var a = A;
#endif
#if A > 40
//too far
#elif A < 1
//too close
#else
//about right
#endif
var b = myVar;
var c = myMacro('xyz');
`, {
myVar: 1,
myMacro: function (arg) { return arg; }
});
// ↓
`
var a = 2;
//about right
var b = 1;
var c = 'xyz';
`
```
The primary purpose is to preprocess code for [glsl-transpiler](https://github.com/stackgl/glsl-transpiler), so some [C-preprocessor](https://gcc.gnu.org/onlinedocs/cpp/index.html#Top) functionality is absent, but the project is welcome to forks and PRs.
## Related
* [compile-js-like-c](https://github.com/ParksProjets/compile-js-like-c) — another C preprocessor for js.