janja 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -115,15 +115,16 @@ ${output
115
115
  });
116
116
  }
117
117
  in() {
118
- const len = this.contexts.push(`${this.context}_${this.index++}`);
119
- return (this.context = this.contexts[len - 1]);
118
+ this.context = `${this.context}_${this.index++}`;
119
+ this.contexts.push(this.context);
120
+ return this.context;
120
121
  }
121
122
  out() {
122
123
  if (this.context === CONTEXT) {
123
124
  return;
124
125
  }
125
126
  this.contexts.pop();
126
- this.context = this.contexts[this.contexts.length - 1];
127
+ this.context = this.contexts.at(-1) ?? CONTEXT;
127
128
  }
128
129
  expect(name) {
129
130
  this.expected.push(name);
@@ -288,32 +289,32 @@ ${output
288
289
  value: options
289
290
  });
290
291
  }
291
- async compile(tagToken, filepath) {
292
+ async compile(tag, filepath) {
292
293
  const ctx = new Context(this.options);
293
294
  const out = new OutScript(this.options);
294
295
  const sourcemap = new SourceMap(this.options);
295
296
  out.start();
296
- while (tagToken) {
297
- const compilers = (this.options.compilers[tagToken.name] ?? []);
297
+ while (tag) {
298
+ const compilers = (this.options.compilers[tag.name] ?? []);
298
299
  for (const compiler of compilers) {
299
300
  try {
300
301
  const r = await compiler.compile({
301
- token: tagToken,
302
+ tag,
302
303
  ctx,
303
304
  out,
304
305
  });
305
306
  if (r !== false) {
306
307
  if (r) {
307
- sourcemap.addMapping(tagToken, r);
308
+ sourcemap.addMapping(tag, r);
308
309
  }
309
310
  break;
310
311
  }
311
312
  }
312
313
  catch (error) {
313
- throw new CompileError(error.message, tagToken, filepath);
314
+ throw new CompileError(error.message, tag, filepath);
314
315
  }
315
316
  }
316
- tagToken = tagToken.next;
317
+ tag = tag.next;
317
318
  }
318
319
  try {
319
320
  ctx.validate();
@@ -526,6 +527,7 @@ ${output
526
527
  const expTokenOperators = {
527
528
  AND: '&&',
528
529
  OR: '||',
530
+ IS: '',
529
531
  NOT: '!',
530
532
  EQ: '===',
531
533
  NE: '!==',
@@ -548,11 +550,9 @@ ${output
548
550
  COMMA: ',',
549
551
  DOT: '.',
550
552
  ID: '',
551
- STR: '',
552
- NUM: '',
553
+ LIT: '',
553
554
  IF: '',
554
555
  ELSE: '',
555
- BOOL: '',
556
556
  };
557
557
 
558
558
  class ExpCompiler {
@@ -581,18 +581,16 @@ ${output
581
581
  return this.compileNot(expression);
582
582
  case 'ID':
583
583
  return this.compileId(expression);
584
- case 'STR':
585
- return this.compileStr(expression);
586
- case 'NUM':
587
- return this.compileNum(expression);
588
- case 'BOOL':
589
- return this.compileBool(expression);
584
+ case 'LIT':
585
+ return this.compileLit(expression);
590
586
  case 'PIPE':
591
587
  return this.compilePipe(expression);
592
588
  case 'OF':
593
589
  return this.compileOf(expression);
594
590
  case 'SET':
595
591
  return this.compileSet(expression);
592
+ case 'IS':
593
+ return this.compileIs(expression);
596
594
  case 'AND':
597
595
  case 'OR':
598
596
  case 'EQ':
@@ -628,14 +626,8 @@ ${output
628
626
  }
629
627
  return s;
630
628
  }
631
- compileStr({ value }) {
632
- return JSON.stringify(value);
633
- }
634
- compileNum({ value }) {
635
- return value.toString();
636
- }
637
- compileBool({ value }) {
638
- return value.toString();
629
+ compileLit({ value }) {
630
+ return value === undefined ? 'undefined' : JSON.stringify(value);
639
631
  }
640
632
  compileSeq({ elements }) {
641
633
  return elements.map(element => this.compileExp(element)).toString();
@@ -662,6 +654,9 @@ ${output
662
654
  // destructuring
663
655
  return `Object.assign(${this.context},${this.filters}.pick.call(${this.context},${this.compileExp(right)},[${left.elements.map(({ value }) => `"${value}"`).join(',')}]));`;
664
656
  }
657
+ compileIs({ left, right }) {
658
+ return `(typeof ${this.compileExp(left)}===${this.compileExp(right)})`;
659
+ }
665
660
  compileBinary({ type, left, right }) {
666
661
  const ret = `(${this.compileExp(left)}${expTokenOperators[type]}${this.compileExp(right)})`;
667
662
  return type === 'NI' ? `(!${ret})` : ret;
@@ -680,6 +675,7 @@ ${output
680
675
  RP: 20,
681
676
  OR: 25,
682
677
  AND: 30,
678
+ IS: 40,
683
679
  EQ: 40,
684
680
  NE: 40,
685
681
  GT: 40,
@@ -698,15 +694,14 @@ ${output
698
694
  PIPE: 80,
699
695
  DOT: 90,
700
696
  ID: 90,
701
- STR: 90,
702
- NUM: 90,
703
- BOOL: 90,
697
+ LIT: 90,
704
698
  };
705
699
 
706
700
  const expTokenTypes = {
707
701
  'and': 'AND',
708
702
  'or': 'OR',
709
703
  'not': 'NOT',
704
+ 'is': 'IS',
710
705
  'eq': 'EQ',
711
706
  'ne': 'NE',
712
707
  'gt': 'GT',
@@ -723,8 +718,10 @@ ${output
723
718
  '%': 'MOD',
724
719
  'if': 'IF',
725
720
  'else': 'ELSE',
726
- 'true': 'BOOL',
727
- 'false': 'BOOL',
721
+ 'true': 'LIT',
722
+ 'false': 'LIT',
723
+ 'null': 'LIT',
724
+ 'undefined': 'LIT',
728
725
  '|': 'PIPE',
729
726
  '=': 'SET',
730
727
  '(': 'LP',
@@ -838,7 +835,7 @@ ${output
838
835
  // skip closing quote char
839
836
  this.cursor++;
840
837
  this.tokens.push({
841
- type: 'STR',
838
+ type: 'LIT',
842
839
  value,
843
840
  start,
844
841
  end: this.cursor,
@@ -864,7 +861,7 @@ ${output
864
861
  this.cursor++;
865
862
  }
866
863
  this.tokens.push({
867
- type: 'NUM',
864
+ type: 'LIT',
868
865
  value: Number.parseFloat(value),
869
866
  start,
870
867
  end: this.cursor,
@@ -886,7 +883,17 @@ ${output
886
883
  const type = value in expTokenTypes ? expTokenTypes[value] : 'ID';
887
884
  this.tokens.push({
888
885
  type,
889
- value: type === 'BOOL' ? value === 'true' : value,
886
+ value: type === 'LIT'
887
+ ? value === 'true'
888
+ ? true
889
+ : value === 'false'
890
+ ? false
891
+ : value === 'null'
892
+ ? null
893
+ : value === 'undefined'
894
+ ? undefined
895
+ : value
896
+ : value,
890
897
  start,
891
898
  end: this.cursor,
892
899
  raw: value,
@@ -1040,27 +1047,10 @@ ${output
1040
1047
  }
1041
1048
  continue;
1042
1049
  }
1043
- if (token.type === 'STR') {
1044
- left = {
1045
- ...token,
1046
- type: 'STR',
1047
- value: token.value,
1048
- };
1049
- continue;
1050
- }
1051
- if (token.type === 'NUM') {
1052
- left = {
1053
- ...token,
1054
- type: 'NUM',
1055
- value: token.value,
1056
- };
1057
- continue;
1058
- }
1059
- if (token.type === 'BOOL') {
1050
+ if (token.type === 'LIT') {
1060
1051
  left = {
1061
1052
  ...token,
1062
- type: 'BOOL',
1063
- value: token.value,
1053
+ type: 'LIT',
1064
1054
  };
1065
1055
  continue;
1066
1056
  }
@@ -1098,6 +1088,7 @@ ${output
1098
1088
  }
1099
1089
  if (token.type === 'AND'
1100
1090
  || token.type === 'OR'
1091
+ || token.type === 'IS'
1101
1092
  || token.type === 'EQ'
1102
1093
  || token.type === 'NE'
1103
1094
  || token.type === 'GT'
@@ -1276,7 +1267,7 @@ ${output
1276
1267
  */
1277
1268
  const tag$7 = {
1278
1269
  names: [CALL, ENDCALL],
1279
- async compile({ token: { name, value }, ctx, out }) {
1270
+ async compile({ tag: { name, value }, ctx, out }) {
1280
1271
  if (name === CALL) {
1281
1272
  if (value?.type !== 'ID') {
1282
1273
  throw new Error(`"${CALL}" tag must specify a "macro" name`);
@@ -1302,7 +1293,7 @@ ${output
1302
1293
  */
1303
1294
  const tag$6 = {
1304
1295
  names: [COMMENT, '#', ENDCOMMENT],
1305
- async compile({ token: { name, value }, ctx, out }) {
1296
+ async compile({ tag: { name, value }, ctx, out }) {
1306
1297
  // inline comment
1307
1298
  if (name === '#') {
1308
1299
  if (!value.value || out.options.stripComments) {
@@ -1331,7 +1322,7 @@ ${output
1331
1322
  */
1332
1323
  const tag$5 = {
1333
1324
  names: [EXPRESSION],
1334
- compile({ token: { value }, ctx: { context }, out }) {
1325
+ compile({ tag: { value }, ctx: { context }, out }) {
1335
1326
  return out.pushVar(compiler.compile(value, context, FILTERS));
1336
1327
  },
1337
1328
  };
@@ -1346,15 +1337,16 @@ ${output
1346
1337
  */
1347
1338
  const tag$4 = {
1348
1339
  names: [FOR, BREAK, CONTINUE, ENDFOR],
1349
- async compile({ token: { name, value }, ctx, out }) {
1340
+ async compile({ tag: { name, value }, ctx, out }) {
1350
1341
  if (name === FOR) {
1351
1342
  if (!value) {
1352
1343
  throw new Error(`"${FOR}" tag must have expression`);
1353
1344
  }
1354
1345
  ctx.expect(ENDFOR);
1355
1346
  const { context } = ctx;
1356
- if (value.left.type === 'SEQ') {
1357
- return out.pushLine(`{`, `for(${compiler.compile(value, context, FILTERS)}){`, `const ${ctx.in()}={`, `...${context},`, `${value.left.elements.map(({ value }) => value).join(',')}`, `};`);
1347
+ const { type, elements } = value.left;
1348
+ if (type === 'SEQ') {
1349
+ return out.pushLine(`{`, `for(${compiler.compile(value, context, FILTERS)}){`, `const ${ctx.in()}={`, `...${context},`, elements.map(({ value }) => value).join(','), `};`);
1358
1350
  }
1359
1351
  return out.pushLine(`{`, `for(${compiler.compile(value, context, FILTERS)}){`, `const ${ctx.in()}={`, `...${context},`, `${value.left.value},`, `};`);
1360
1352
  }
@@ -1389,7 +1381,7 @@ ${output
1389
1381
  */
1390
1382
  const tag$3 = {
1391
1383
  names: [IF, ELIF, ELSE, ENDIF],
1392
- async compile({ token: { name, value }, ctx, out }) {
1384
+ async compile({ tag: { name, value }, ctx, out }) {
1393
1385
  if (name === IF) {
1394
1386
  if (!value) {
1395
1387
  throw new Error(`"${IF}" tag must have expression`);
@@ -1426,25 +1418,29 @@ ${output
1426
1418
  const MACRO = 'macro';
1427
1419
  const CALLER = 'caller';
1428
1420
  const ENDMACRO = 'endmacro';
1421
+ const CALLER_PN = '_c';
1429
1422
  /**
1430
1423
  * @example {{ macro my_macro = (x, y) }}...{{ caller }}{{ endmacro }}{{ my_macro("foo", 1) }}
1431
1424
  */
1432
1425
  const tag$2 = {
1433
1426
  names: [MACRO, CALLER, ENDMACRO],
1434
- async compile({ token: { name, value }, ctx, out }) {
1427
+ async compile({ tag: { name, value }, ctx, out }) {
1435
1428
  if (name === MACRO) {
1436
1429
  if (value?.type !== 'SET') {
1437
1430
  throw new Error(`"${MACRO}" tag must have "SET" expression`);
1438
1431
  }
1439
1432
  ctx.expect(ENDMACRO);
1440
1433
  const { context } = ctx;
1441
- return out.pushLine(`${compiler.compile(value, context, FILTERS)}=>async(_c)=>{`, `const ${ctx.in()}={`, `...${context},`, `${(value.right.elements).map(el => el.type === 'SET' ? `${el.left.value}` : el.value).join(',')}`, `};`);
1434
+ const { elements } = value.right;
1435
+ return out.pushLine(`${compiler.compile(value, context, FILTERS)}=>async(${CALLER_PN})=>{`, `const ${ctx.in()}={`, `...${context},`, elements.map(el => el.type === 'SET'
1436
+ ? el.left.value
1437
+ : el.value).join(','), `};`);
1442
1438
  }
1443
1439
  if (name === CALLER) {
1444
1440
  if (!ctx.matchAny(ENDMACRO)) {
1445
1441
  throw new Error(`"${CALLER}" tag must inside a "${MACRO}" tag`);
1446
1442
  }
1447
- return out.pushLine(`await _c?.();`);
1443
+ return out.pushLine(`await ${CALLER_PN}?.();`);
1448
1444
  }
1449
1445
  if (name === ENDMACRO) {
1450
1446
  if (!ctx.consume(ENDMACRO)) {
@@ -1462,7 +1458,7 @@ ${output
1462
1458
  */
1463
1459
  const tag$1 = {
1464
1460
  names: [RAW],
1465
- async compile({ token: { raw, previous, next }, out }) {
1461
+ async compile({ tag: { raw, previous, next }, out }) {
1466
1462
  return out.pushStr(raw, {
1467
1463
  trimStart: previous?.stripAfter,
1468
1464
  trimEnd: next?.stripBefore,
@@ -1478,7 +1474,7 @@ ${output
1478
1474
  */
1479
1475
  const tag = {
1480
1476
  names: [SET, ENDSET],
1481
- async compile({ token: { name, value }, ctx, out }) {
1477
+ async compile({ tag: { name, value }, ctx, out }) {
1482
1478
  if (name === SET) {
1483
1479
  if (!value) {
1484
1480
  throw new Error(`"${SET}" tag must have expression`);
@@ -1586,30 +1582,29 @@ ${output
1586
1582
  let match;
1587
1583
  while ((match = tagRe.exec(template))) {
1588
1584
  if (match.index > this.index) {
1589
- this.strToken(this.index, match.index);
1585
+ this.addRaw(this.index, match.index);
1590
1586
  }
1591
- await this.tagToken(match);
1587
+ await this.addTag(match);
1592
1588
  this.index = match.index + match[0].length;
1593
1589
  }
1594
1590
  if (this.index < template.length) {
1595
- this.strToken(this.index, template.length);
1591
+ this.addRaw(this.index, template.length);
1596
1592
  }
1597
1593
  this.cursor = this.first;
1598
1594
  this.rebuildBlocks();
1599
1595
  return this.cursor;
1600
1596
  }
1601
- strToken(start, end) {
1602
- const raw = this.template.slice(start, end);
1597
+ addRaw(start, end) {
1603
1598
  this.push({
1604
1599
  name: RAW$1,
1605
- raw,
1600
+ raw: this.template.slice(start, end),
1606
1601
  previous: null,
1607
1602
  next: null,
1608
1603
  start,
1609
1604
  end,
1610
1605
  });
1611
1606
  }
1612
- async tagToken(match) {
1607
+ async addTag(match) {
1613
1608
  const start = match.index;
1614
1609
  const end = start + match[0].length;
1615
1610
  const base = {
@@ -1626,7 +1621,7 @@ ${output
1626
1621
  ...base,
1627
1622
  name: match[2],
1628
1623
  value: {
1629
- type: 'STR',
1624
+ type: 'LIT',
1630
1625
  value: unescapeTag(match[3]),
1631
1626
  },
1632
1627
  });
@@ -1657,7 +1652,7 @@ ${output
1657
1652
  }
1658
1653
  async layout(value) {
1659
1654
  const exp = parser.parse(value);
1660
- if (exp?.type !== 'STR' || !exp.value) {
1655
+ if (exp?.type !== 'LIT' || typeof exp.value !== 'string' || !exp.value) {
1661
1656
  throw new ParseError(`"layout" tag must have a file path`, {
1662
1657
  source: this.template,
1663
1658
  range: {
@@ -1670,7 +1665,7 @@ ${output
1670
1665
  }
1671
1666
  async include(value) {
1672
1667
  const exp = parser.parse(value.replace(/\?$/, ''));
1673
- if (exp?.type !== 'STR' || !exp.value) {
1668
+ if (exp?.type !== 'LIT' || typeof exp.value !== 'string' || !exp.value) {
1674
1669
  throw new ParseError(`"include" tag must have a file path`, {
1675
1670
  source: this.template,
1676
1671
  range: {
@@ -1701,9 +1696,9 @@ ${output
1701
1696
  cursor = cursor.next;
1702
1697
  }
1703
1698
  }
1704
- push(token) {
1705
- if (token.name === BLOCK) {
1706
- const { type, value } = token.value;
1699
+ push(tag) {
1700
+ if (tag.name === BLOCK) {
1701
+ const { type, value } = tag.value;
1707
1702
  if (type !== 'ID') {
1708
1703
  throw new ParseError(`"${BLOCK}" tag must have a title`, {
1709
1704
  source: this.template,
@@ -1716,31 +1711,31 @@ ${output
1716
1711
  this.group = value;
1717
1712
  // child blocks
1718
1713
  if (this.blocks[value]) {
1719
- this.blocks[value].push([token]);
1714
+ this.blocks[value].push([tag]);
1720
1715
  return;
1721
1716
  }
1722
1717
  // parent block
1723
- this.blocks[value] = [[token]];
1718
+ this.blocks[value] = [[tag]];
1724
1719
  }
1725
1720
  else if (this.group) {
1726
1721
  const chunks = this.blocks[this.group];
1727
- if (token.name === ENDBLOCK) {
1722
+ if (tag.name === ENDBLOCK) {
1728
1723
  this.group = '';
1729
1724
  }
1730
- chunks.at(-1).push(token);
1725
+ chunks.at(-1).push(tag);
1731
1726
  // child blocks
1732
1727
  if (chunks.length > 1) {
1733
1728
  return;
1734
1729
  }
1735
1730
  }
1736
1731
  if (this.cursor) {
1737
- token.previous = this.cursor;
1738
- this.cursor.next = token;
1732
+ tag.previous = this.cursor;
1733
+ this.cursor.next = tag;
1739
1734
  }
1740
1735
  else {
1741
- this.first = token;
1736
+ this.first = tag;
1742
1737
  }
1743
- this.cursor = token;
1738
+ this.cursor = tag;
1744
1739
  }
1745
1740
  /**
1746
1741
  * @note Block tags are hoisted to top level
@@ -1778,29 +1773,29 @@ ${output
1778
1773
  return [];
1779
1774
  }
1780
1775
  const chunk = [];
1781
- child.forEach((token) => {
1782
- if (token.name === SUPER) {
1776
+ child.forEach((tag) => {
1777
+ if (tag.name === SUPER) {
1783
1778
  this.rebuildBlockBody(parents.pop(), parents).forEach(t => chunk.push(t));
1784
1779
  }
1785
1780
  else {
1786
- chunk.push(token);
1781
+ chunk.push(tag);
1787
1782
  }
1788
1783
  });
1789
1784
  return chunk;
1790
1785
  }
1791
- rebuildBlockChain(tokens, previous, next) {
1792
- for (let i = 0; i < tokens.length; i++) {
1793
- tokens[i].previous = tokens[i - 1] || previous;
1794
- tokens[i].next = tokens[i + 1] || next;
1786
+ rebuildBlockChain(tags, previous, next) {
1787
+ for (let i = 0; i < tags.length; i++) {
1788
+ tags[i].previous = tags[i - 1] || previous;
1789
+ tags[i].next = tags[i + 1] || next;
1795
1790
  }
1796
1791
  if (previous) {
1797
- [previous.next] = tokens;
1792
+ [previous.next] = tags;
1798
1793
  }
1799
1794
  if (next) {
1800
- next.previous = tokens[tokens.length - 1];
1795
+ next.previous = tags[tags.length - 1];
1801
1796
  }
1802
1797
  if (!this.first) {
1803
- [this.first] = tokens;
1798
+ [this.first] = tags;
1804
1799
  this.cursor = this.first;
1805
1800
  }
1806
1801
  }
package/package.json CHANGED
@@ -1,15 +1,9 @@
1
1
  {
2
2
  "name": "janja",
3
3
  "type": "module",
4
- "version": "1.0.0",
5
- "packageManager": "yarn@4.9.2",
4
+ "version": "1.1.0",
6
5
  "description": "A simple, fast, lightweight, and extensible template engine for Node.js and browsers.",
7
6
  "license": "MIT",
8
- "workspaces": [
9
- "perf",
10
- "repl",
11
- "."
12
- ],
13
7
  "exports": {
14
8
  "types": "./dist/index.d.ts",
15
9
  "import": "./dist/index.esm.js",
@@ -23,30 +17,16 @@
23
17
  "dist"
24
18
  ],
25
19
  "scripts": {
26
- "build": "rm -rf dist && rollup -c",
27
- "dev": "vitest watch",
28
- "test": "vitest",
29
- "repl": "yarn workspace repl run start",
30
- "perf": "yarn workspace perf run start",
31
- "lint": "oxlint && eslint . --ext .ts",
32
- "prepare": "husky"
20
+ "build": "rm -rf dist && rollup -c"
33
21
  },
34
22
  "devDependencies": {
35
- "@antfu/eslint-config": "^6.1.0",
36
23
  "@rollup/plugin-commonjs": "^28.0.9",
37
24
  "@rollup/plugin-node-resolve": "^16.0.3",
38
25
  "@rollup/plugin-typescript": "^12.3.0",
39
26
  "@types/node": "^24.9.1",
40
- "@vitest/coverage-v8": "4.0.3",
41
- "@vitest/ui": "4.0.3",
42
- "eslint": "^9.38.0",
43
- "husky": "^9.1.7",
44
- "oxlint": "^1.24.0",
45
27
  "rollup": "^4.52.5",
46
28
  "rollup-plugin-dts": "^6.2.3",
47
29
  "tslib": "^2.8.1",
48
- "typescript": "^5.9.3",
49
- "vite": "^7.1.12",
50
- "vitest": "^4.0.3"
30
+ "typescript": "^5.9.3"
51
31
  }
52
32
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 李文富
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/README.md DELETED
@@ -1,39 +0,0 @@
1
- # Janja
2
-
3
- <p align="center">A simple, fast, lightweight, and extensible template engine for Node.js and browsers.</p>
4
-
5
- <p align="center">
6
- <a href="https://github.com/vvenv/janja/actions/workflows/test.yml"><img src="https://github.com/vvenv/janja/actions/workflows/test.yml/badge.svg" alt="test"></a>
7
- </p>
8
-
9
- <p align="center">
10
- <a href="./README-zh-CN.md">中文</a>
11
- </p>
12
-
13
- ## Key Features
14
-
15
- - 📝 **Intuitive Template Syntax**: Simple syntax for variables, conditionals, and loops.
16
- - 🔗 **Custom global variables**: Supports definition of global variables.
17
- - 🛠️ **Built-in Tags and Filters**: A collection of built-in tags and filters.
18
- - 🎨 **Custom Tags and Filters**: Ability to define custom tags and filters.
19
- - 🚀 **Pre-compilation**: Enhance rendering performance by precompiling.
20
- - 🐛 **Error Handling and Debugging**: Provides detailed error reporting and debugging support.
21
- - 🛡️ **Security**: Sandbox mode, and automatic escaping.
22
- - 🛫 **Asynchronous Data Loading**: Supports fetching and displaying remote data asynchronously.
23
-
24
- ## Getting Started
25
-
26
- ```javascript
27
- const engine = new Engine()
28
- const html = await engine.render('Hello, {{= name }}!', { name: 'World' })
29
- // or
30
- // const html = await engine.renderFile('./template.html', { name: 'World' })
31
-
32
- document.body.innerHTML = html
33
- ```
34
-
35
- [Documentation](./documentation.md)
36
-
37
- ## License
38
-
39
- `Janja` is released under the [MIT License](https://opensource.org/licenses/MIT). You are free to use, modify, and distribute it as long as you comply with the license terms.