@gregorlohaus/tdir 0.1.7 → 0.1.8
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/README.md +2 -0
- package/dist/index.js +9 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -60,6 +60,7 @@ render("./output", {
|
|
|
60
60
|
|---|---|
|
|
61
61
|
| `<@if(context.x)>` | Conditional block — boolean check (must end with `<@endif>`) |
|
|
62
62
|
| `<@if(eq(context.x,"value"))>` | Conditional block — string equality check |
|
|
63
|
+
| `<@if(neq(context.x,"value"))>` | Conditional block — string inequality check |
|
|
63
64
|
| `<@elseif(context.y)>` | Else-if branch (same forms as `@if`) |
|
|
64
65
|
| `<@else>` | Else branch |
|
|
65
66
|
| `<@endif>` | End conditional block |
|
|
@@ -72,6 +73,7 @@ render("./output", {
|
|
|
72
73
|
|---|---|
|
|
73
74
|
| `<@if(context.x)>dirname` | Conditionally include directory/file (boolean check) |
|
|
74
75
|
| `<@if(eq(context.x,"value"))>dirname` | Conditionally include by string equality |
|
|
76
|
+
| `<@if(neq(context.x,"value"))>dirname` | Conditionally include by string inequality |
|
|
75
77
|
| `<@var(context.x)>` | Dynamic directory/file name |
|
|
76
78
|
|
|
77
79
|
These can be combined: `<@if(context.web.create)><@var(context.web.dir)>` creates a directory named by `context.web.dir` only if `context.web.create` is true.
|
package/dist/index.js
CHANGED
|
@@ -8,14 +8,14 @@ import { TextDecoder } from "node:util";
|
|
|
8
8
|
var IF_RE = /<@(?:if|elseif)\((.+?)\)>/g;
|
|
9
9
|
var VAR_RE = /<@var\(context\.(.+?)(?::(\w+))?\)>/g;
|
|
10
10
|
var DIRECTIVE_RE = /<@(if|elseif|else|endif)(?:\((.+?)\))?>/g;
|
|
11
|
-
var
|
|
11
|
+
var STRING_COMPARE_RE = /^(?:eq|neq)\(context\.(.+?),\s*"(.*)"\)$/;
|
|
12
12
|
var PATH_RE = /^context\.(.+)$/;
|
|
13
13
|
function extractCondition(expr, vars) {
|
|
14
14
|
if (!expr)
|
|
15
15
|
throw new Error("Missing condition expression");
|
|
16
|
-
const
|
|
17
|
-
if (
|
|
18
|
-
vars.push({ path:
|
|
16
|
+
const stringCompareMatch = expr.match(STRING_COMPARE_RE);
|
|
17
|
+
if (stringCompareMatch) {
|
|
18
|
+
vars.push({ path: stringCompareMatch[1], type: "string" });
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
21
21
|
const pathMatch = expr.match(PATH_RE);
|
|
@@ -122,14 +122,15 @@ import { TextDecoder as TextDecoder2 } from "node:util";
|
|
|
122
122
|
var IF_PATH_RE = /^<@if\((.+?)\)>(.*)$/;
|
|
123
123
|
var VAR_RE2 = /<@var\(context\.(.+?)(?::(\w+))?\)>/g;
|
|
124
124
|
var DIRECTIVE_RE2 = /<@(if|elseif|else|endif)(?:\((.+?)\))?>/g;
|
|
125
|
-
var
|
|
125
|
+
var STRING_COMPARE_RE2 = /^(eq|neq)\(context\.(.+?),\s*"(.*)"\)$/;
|
|
126
126
|
var PATH_RE2 = /^context\.(.+)$/;
|
|
127
127
|
function evalCondition(expr, context) {
|
|
128
128
|
if (!expr)
|
|
129
129
|
throw new Error("Missing condition expression");
|
|
130
|
-
const
|
|
131
|
-
if (
|
|
132
|
-
|
|
130
|
+
const stringCompareMatch = expr.match(STRING_COMPARE_RE2);
|
|
131
|
+
if (stringCompareMatch) {
|
|
132
|
+
const result = resolveContext(context, stringCompareMatch[2]) === stringCompareMatch[3];
|
|
133
|
+
return stringCompareMatch[1] === "eq" ? result : !result;
|
|
133
134
|
}
|
|
134
135
|
const pathMatch = expr.match(PATH_RE2);
|
|
135
136
|
if (pathMatch) {
|