Flave
raw JSON → 1.5.3 verified Fri May 01 auth: no javascript
Flave (Full Logic Access View Engine) is a Razor-like view transpiler for JavaScript that compiles template files into plain JavaScript functions returning strings. Version 1.5.3 is the current stable release, with irregular cadence. Unlike many templating engines that restrict logic, Flave gives full access to JavaScript via code blocks and expressions. It is isomorphic (no DOM required), supports custom configuration for quoting, whitespace, and exports, and integrates with editors like VSCode and Atom through community extensions.
Common errors
error ReferenceError: flave is not defined ↓
cause The package was not imported or the require path is incorrect.
fix
Use
const flave = require('flave'); with correct path. error TypeError: flave.transpile is not a function ↓
cause The imported object does not have a 'transpile' method (wrong import pattern).
fix
Ensure you import the module correctly:
const flave = require('flave'); then call flave.transpile(). error SyntaxError: Unexpected token 'class' ↓
cause The .flave file uses the `class` keyword incorrectly or has a syntax error that resembles JavaScript classes.
fix
Wrap your view/function definitions in a class if you want namespacing, but ensure the syntax follows Flave rules:
class name { view viewname { } }. Warnings
gotcha The transpiled output uses a variable named `$O` by default for HTML string accumulation. If your view uses '$O' as a data property, it will conflict. ↓
fix Set the `output` config option to a unique variable name, e.g., `output: '__html'`.
gotcha The `export` configuration option (default true) auto-adds `module.exports`. If you are transpiling for the browser, set `export: false` to avoid Node.js specific code. ↓
fix Set `export: false` in config when targeting browser environments.
gotcha The `format` option defaults to `true`, but its indentation may not work correctly with complex code blocks. Disable it if the output looks malformed. ↓
fix Set `format: false` in config to get unformatted but consistent JavaScript.
gotcha Comments in `view` and `function` blocks are stripped by default (stripcomments: true). Retaining them may affect output. ↓
fix Set `stripcomments: false` to preserve comments.
Install
npm install flave yarn add flave pnpm add flave Imports
- flave wrong
const { flave } = require('flave');correctconst flave = require('flave'); - transpile wrong
flave(flavestring, config);correctflave.transpile(flavestring, config); - type imports wrong
import * as flave from 'flave';correctimport flave from 'flave';
Quickstart
const flave = require('flave');
const fs = require('fs');
const config = {
quote: '"',
stripcomments: true,
output: '$O',
trim: true,
newlines: true,
format: false,
export: true
};
fs.readFile('template.flave', 'utf8', (err, data) => {
if (err) throw err;
const jsCode = flave.transpile(data, config);
console.log(jsCode);
});