# @scaffdog/engine

> A module of scaffdog template engine.

Latest version **4.1.0** (published 2024-09-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install @scaffdog/engine
pnpm add @scaffdog/engine
yarn add @scaffdog/engine
bun add @scaffdog/engine
```

## Health

**Score 45/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 4.1.0 |
| Published | 2024-09-16 |
| First published | 2021-01-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 6 |
| Unpacked size | 119.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 774 |
| Author | wadackel |
| Maintainers | wadackel |
| Keywords | scaffdog, markdown, template |

## Links

- npm: https://www.npmjs.com/package/@scaffdog/engine
- Repository: https://github.com/scaffdog/scaffdog
- Homepage: https://github.com/scaffdog/scaffdog/tree/main/packages/@scaffdog/engine
- Issues: https://github.com/scaffdog/scaffdog/issues
- npm.io page: https://npm.io/package/@scaffdog/engine

## Dependencies (6)

- [plur](https://npm.io/package/plur.md) 5.1.0
- [dayjs](https://npm.io/package/dayjs.md) ^1.10.4
- [change-case](https://npm.io/package/change-case.md) ^5.0.0
- [is-plain-obj](https://npm.io/package/is-plain-obj.md) ^4.1.0
- [@scaffdog/error](https://npm.io/package/@scaffdog/error.md) 4.1.0
- [@scaffdog/types](https://npm.io/package/@scaffdog/types.md) 4.1.0

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 4.1.0 (latest) — 2024-09-16
- 3.0.0-canary.1 (canary) — 2023-07-17
- 4.0.0 — 2024-04-28
- 3.0.0 — 2023-07-30
- 3.0.0-canary.0 — 2023-07-15
- 2.5.1 — 2023-06-25
- 2.5.0 — 2023-02-25
- 2.5.0-canary.3 — 2023-02-25
- 2.5.0-canary.2 — 2023-02-25
- 2.5.0-canary.1 — 2023-02-23
- 2.5.0-canary.0 — 2023-02-19
- 2.4.0 — 2022-09-25
- 2.4.0-canary.0 — 2022-09-24
- 2.3.1 — 2022-09-22
- 2.3.0 — 2022-09-20
- … 31 more at https://npm.io/package/@scaffdog/engine/versions

## README

# @scaffdog/engine

A module of scaffdog template engine.

## Install

Install via npm:

```bash
$ npm install @scaffdog/engine
```

## Usage

The following code is a basic example:

```typescript
import { render, createContext } from '@scaffdog/engine';

const context = createContext({
  variables: new Map([['name', 'scaffdog']]),
  helpers: new Map([['greet', (_, name: string) => `Hi ${name}!`]]),
});

const output = render(`OUTPUT: {{ name | greet }}`, context);
// --> "OUTPUT: Hi scaffdog!"
```

### Custom Tags

You can change the tag delimiter with `context.tags`:

```typescript
import { render, createContext } from '@scaffdog/engine';

const context = createContext({
  tags: ['<%=', '=%>'],
});

render(`<%= "custom tag" =%>`, context);
```

## Language Specification

scaffdog uses the template engine inpired by [ECMAScript](https://tc39.es/ecma262/) and [Go text/template](https://pkg.go.dev/text/template).

```ebnf
SourceCharacter ::= #x0000-#x10FFFF
WhiteSpace ::= "<TAB>" | "<LF>" | "<CR>" | " "

Comment ::= "/*" CommentChars? "*/"
CommentChars ::= NotAsteriskChar CommentChars? | "*" PostAsteriskCommentChars?
PostAsteriskCommentChars ::= NotForwardSlashOrAsteriskChar CommentChars? | "*" PostAsteriskCommentChars?
NotAsteriskChar ::= [^*]
NotForwardSlashOrAsteriskChar ::= [^/*]
NonZeroDigit ::= "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
Digit ::= "0" | NonZeroDigit

NullLiteral ::= "null"
UndefinedLiteral ::= "undefined"
BooleanLiteral ::= "true" | "false"
NumericLiteral ::= DecimalLiteral | BinaryIntegerLiteral | OctalIntegerLiteral | HexIntegerLiteral
DecimalLiteral ::= DecimalIntegerLiteral "." DecimalDigits? ExponentPart?
  | "." DecimalDigits ExponentPart?
  | DecimalIntegerLiteral ExponentPart?
DecimalIntegerLiteral ::= "0"
  | NonZeroDigit
  | NonZeroDigit DecimalDigits
DecimalDigits ::= Digit | DecimalDigits Digit
ExponentPart ::= ExponentIndicator SignedInteger
ExponentIndicator ::= "e" | "E"
SignedInteger ::= DecimalDigits | "+" DecimalDigits | "-" DecimalDigits
BinaryIntegerLiteral ::= "0b" BinaryDigits | "0B" BinaryDigits
BinaryDigits ::= BinaryDigit | BinaryDigits BinaryDigit
BinaryDigit ::= "0" | "1"
OctalIntegerLiteral ::= "0o" OctalDigits | "0O" OctalDigits
OctalDigits ::= OctalDigit | OctalDigits OctalDigit
OctalDigit ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7"
HexIntegerLiteral ::= "0x" HexDigits | "0X" HexDigits
HexDigits ::= HexDigit | HexDigits HexDigit
HexDigit ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "a" | "b" | "c" | "d" | "e" | "f" | "A" | "B" | "C" | "D" | "E" | "F"
StringLiteral ::= DoubleStringLiteral | SingleStringLiteral
DoubleStringLiteral ::= '"' DoubleStringChars '"'
DoubleStringChars ::= DoubleStringChar | DoubleStringChar DoubleStringChars
DoubleStringChar ::= EscapeChar | SourceCharacter - '"'
SingleStringLiteral ::= '"' SingleStringChars '"'
SingleStringChars ::= SingleStringChar | SingleStringChar SingleStringChars
SingleStringChar ::= EscapeChar | SourceCharacter - "'"
EscapeChar ::= '\"' | "\'"

Literal ::= NullLiteral | UndefinedLiteral | BooleanLiteral | NumericLiteral | StringLiteral

ReservedWord ::= "null" | "true" | "false" | "undefined" | "if" | "else" | "break" | "continue" | "end" | "for"

/* Expressions */
Identifier ::= IdentifierName - ReservedWord
IdentifierName ::= IdentifierStart | IdentifierName IdentifierPart
IdentifierStart ::= "$" | "_" | UnicodeIDStart
IdentifierPart ::= "$" | "_" | UnicodeIDContinue
UnicodeIDStart ::= /* any Unicode code point with the Unicode property “ID_Start” */
UnicodeIDContinue ::= /* any Unicode code point with the Unicode property “ID_Continue” */

PrimaryExpression ::= Identifier
  | Literal
  | ParenthesizedExpression

StaticMemberAccessor ::= Identifier | NumericLiteral
MemberExpression ::= PrimaryExpression
  | MemberExpression "[" Expression "]"
  | MemberExpression "." StaticMemberAccessor

CallExpression ::= MemberExpression Arguments
  | CallExpression Arguments
  | CallExpression "[" Expression "]"
  | CallExpression "." StaticMemberAccessor

LeftHandSideExpression ::= CallExpression | MemberExpression
UpdateExpression ::= LeftHandSideExpression
  | LeftHandSideExpression "++"
  | LeftHandSideExpression "--"
  | "++" LeftHandSideExpression
  | "--" LeftHandSideExpression
UnaryExpression ::= UpdateExpression |
  | "+" UnaryExpression
  | "-" UnaryExpression
  | "~" UnaryExpression
  | "!" UnaryExpression

MultiplicativeOperator ::= [* / %]
MultiplicativeExpression ::= UnaryExpression
  | MultiplicativeExpression MultiplicativeOperator UnaryExpression
AdditiveExpression ::= MultiplicativeExpression
  | AdditiveExpression "+" MultiplicativeExpression
  | AdditiveExpression "-" MultiplicativeExpression
RelationalExpression::= AdditiveExpression
  | RelationalExpression "<" AdditiveExpression
  | RelationalExpression ">" AdditiveExpression
  | RelationalExpression "<=" AdditiveExpression
  | RelationalExpression ">=" AdditiveExpression

EqualityExpression ::= RelationalExpression
  | EqualityExpression "==" RelationalExpression
  | EqualityExpression "!=" RelationalExpression

LogicalANDExpression ::= LogicalANDExpression "&&" EqualityExpression
LogicalORExpression ::= LogicalORExpression "||" LogicalANDExpression

ConditionalExpression ::= LogicalORExpression
  | ConditionalExpression "?" ConditionalExpression ":" ConditionalExpression

ArgumentItem ::= ConditionalExpression | CallExpression
ArgumentList ::= ArgumentItem | ArgumentList "," ArgumentItem
Arguments ::= "(" ")" | "(" ArgumentList ")"

ParenthesizedExpression ::= "(" Expression ")"

PipeArgument ::= UnaryExpression
PipeArgumentList ::= PipeArgument | PipeArgumentList WhiteSpace PipeArgument
PipeHead ::= ConditionalExpression PipeArgumentList?
  | LeftHandSideExpression PipeArgumentList?
PipeBody ::= MemberExpression PipeArgumentList?
PipeExpression ::= PipeHead
  | PipeHead "|" PipeBody
  | PipeExpression "|" PipeBody

Expression ::= PipeExpression

/* Statements */
TagOpen ::= "{{" | "{{-"
TagClose ::= "}}" | "}}-"

ExpressionStatement ::= Expression
VariableStatement ::= Identifier ":=" Expression
EndStatement ::= "end"
ContinueStatement ::= "continue"
BreakStatement ::= "break"
ForBinding ::= Identifier | Identifier "," Identifier
ForStatement ::= "for" ForBinding "in" Expression TagClose Template TagOpen EndStatement
IfStatement ::= "if" Expression TagClose Template TagOpen EndStatement
  | "if" Expression TagClose Template TagOpen "else" TagClose Template TagOpen EndStatement
  | "if" Expression TagClose Template TagOpen "else" IfStatement
Statement ::= VariableStatement
  | IfStatement
  | ForStatement
  | ContinueStatement
  | BreakStatement
  | ExpressionStatement

/* Templates */
TagTemplate ::= TagOpen Statement TagClose

RawTemplateChar ::= SourceCharacter - TagOpen
RawTemplate ::= RawTemplateChar RawTemplate?

TemplateElement ::= TagTemplate | RawTemplate
Template ::= TemplateElement | Template TemplateElement

Program ::= Template? <EOF>
```

---
_Source: https://npm.io/package/@scaffdog/engine · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
