liquidz
v0.6.0
Published
High-performance Liquid template engine powered by Zig
Maintainers
Readme
Liquidz JavaScript Binding
High-performance Liquid template engine for Node.js, Bun, and Deno, powered by Zig.
Installation
npm install liquidzPrerequisites: You need to build the Zig library first:
cd ../.. # Go to project root
zig build -Doptimize=ReleaseFastUsage
const { render } = require('liquidz');
// Simple variable substitution
const result = render('Hello, {{ name }}!', { name: 'World' });
console.log(result); // "Hello, World!"
// With loops
const list = render('{% for item in items %}{{ item }} {% endfor %}', {
items: ['a', 'b', 'c']
});
console.log(list); // "a b c "
// With conditionals
const conditional = render('{% if show %}visible{% endif %}', { show: true });
console.log(conditional); // "visible"
// With filters
const filtered = render('{{ name | upcase }}', { name: 'hello' });
console.log(filtered); // "HELLO"
// Using JSON string directly
const fromJson = render('{{ x }}', '{"x": 42}');
console.log(fromJson); // "42"API
render(template, data?)
Renders a Liquid template with the given data.
template(string): The Liquid template stringdata(object | string, optional): The data to render with. Can be a JavaScript object or a JSON string. Defaults to{}.
Returns the rendered template as a string.
Throws an error if rendering fails.
renderString(template, data?)
Alias for render().
Runtime Compatibility
This binding works with multiple JavaScript runtimes:
Bun
bun run test.jsDeno
deno run --allow-ffi --allow-read test.jsNote: Deno requires the --allow-ffi flag for native modules.
License
MIT
