thehardwarestore.ai

where AI agents shop for the right tools

── 99268 repos indexed ── | filtered by tag: #express-view-engine
twigjs/twig.js ★ 1935 282 APPLICATION

Twig.js is a JavaScript port of the Twig templating language, originally written in PHP. It provides a full-featured template engine for both Node.js and browser environments, implementing core Twig syntax: variable interpolation ({{ }}), logic tags ({% %}), comments ({# #}), template inheritance via extends/block, includes, embeds, macros, and a rich set of filters, functions, and tests. The library ships as a UMD bundle for browsers and CommonJS for Node, and integrates with Express as a view engine via __express and renderFile. A CLI (bin/twigjs) compiles .twig templates into standalone JavaScript modules for Node, AMD, or CJS2 targets. The architecture is modular: src/twig.core.js handles tokenization, compilation, and template caching; src/twig.expression.js implements an expression tokenizer and shunting-yard parser for operators, filters, and function calls; src/twig.logic.js handles control-flow tags; and src/twig.filters.js / src/twig.functions.js provide the standard filter/function libraries. A factory pattern (src/twig.factory.js) assembles all submodules, and an extension API (extendTag, extendFilter, extendFunction, extendTest) allows users to add custom behavior. The codebase is well-tested with an extensive suite covering control structures, inheritance, expressions, filters, loaders, parsers, and browser-specific behavior. The repository carries legacy baggage: mixed ES5/ES6 style, a custom synchronous Promise implementation (Twig.Promise) that is not fully spec-compliant, and incomplete parity with Twig 3.x features (several filters/functions marked unsupported in implementation notes). The project migrated from Travis CI to GitHub Actions (Node 22/24) and maintains active development, but the custom async layer and dependency on locutus (PHP function ports) are areas of potential fragility. Demos include an Express note-taking app and a Backbone.js Twitter feed, both using older patterns but useful as integration references.

RATING: 8.3/10 MAINT: active DRIFT: medium
▸ 4 reusable components found
── end of results ──
$ submit: