@jxsuite/parser 0.28.2 → 0.28.4
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/content.js +32 -16
- package/dist/csv.js +15 -11
- package/dist/markdown.js +516 -336
- package/dist/serialize.js +379 -254
- package/package.json +3 -3
- package/src/content.ts +41 -20
- package/src/csv.ts +18 -10
- package/src/html-to-jx.ts +23 -9
- package/src/markdown.ts +19 -10
- package/src/md.ts +57 -34
- package/src/serialize.ts +401 -246
- package/src/transpile.ts +114 -53
- package/src/types.ts +1 -3
package/dist/content.js
CHANGED
|
@@ -50,28 +50,39 @@ var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
|
50
50
|
function evaluateFilterRule(rule, entry) {
|
|
51
51
|
const actual = rule.field === "id" ? entry.id : entry.data[rule.field];
|
|
52
52
|
switch (rule.op) {
|
|
53
|
-
case "==":
|
|
53
|
+
case "==": {
|
|
54
54
|
return actual === rule.value;
|
|
55
|
-
|
|
55
|
+
}
|
|
56
|
+
case "!=": {
|
|
56
57
|
return actual !== rule.value;
|
|
57
|
-
|
|
58
|
+
}
|
|
59
|
+
case "empty": {
|
|
58
60
|
return actual == null || actual === "" || Array.isArray(actual) && actual.length === 0;
|
|
59
|
-
|
|
61
|
+
}
|
|
62
|
+
case "not empty": {
|
|
60
63
|
return actual != null && actual !== "" && !(Array.isArray(actual) && actual.length === 0);
|
|
61
|
-
|
|
64
|
+
}
|
|
65
|
+
case "contains": {
|
|
62
66
|
return typeof actual === "string" && actual.includes(String(rule.value ?? ""));
|
|
63
|
-
|
|
67
|
+
}
|
|
68
|
+
case "not contains": {
|
|
64
69
|
return typeof actual === "string" && !actual.includes(String(rule.value ?? ""));
|
|
65
|
-
|
|
70
|
+
}
|
|
71
|
+
case ">": {
|
|
66
72
|
return Number(actual) > Number(rule.value);
|
|
67
|
-
|
|
73
|
+
}
|
|
74
|
+
case "<": {
|
|
68
75
|
return Number(actual) < Number(rule.value);
|
|
69
|
-
|
|
76
|
+
}
|
|
77
|
+
case ">=": {
|
|
70
78
|
return Number(actual) >= Number(rule.value);
|
|
71
|
-
|
|
79
|
+
}
|
|
80
|
+
case "<=": {
|
|
72
81
|
return Number(actual) <= Number(rule.value);
|
|
73
|
-
|
|
82
|
+
}
|
|
83
|
+
default: {
|
|
74
84
|
return true;
|
|
85
|
+
}
|
|
75
86
|
}
|
|
76
87
|
}
|
|
77
88
|
function queryContentType(entries, query = {}) {
|
|
@@ -97,10 +108,12 @@ function queryContentType(entries, query = {}) {
|
|
|
97
108
|
for (const { field, order = "asc" } of sortRules) {
|
|
98
109
|
const aVal = field === "id" ? a.id : a.data[field] ?? "";
|
|
99
110
|
const bVal = field === "id" ? b.id : b.data[field] ?? "";
|
|
100
|
-
if (aVal < bVal)
|
|
111
|
+
if (aVal < bVal) {
|
|
101
112
|
return order === "asc" ? -1 : 1;
|
|
102
|
-
|
|
113
|
+
}
|
|
114
|
+
if (aVal > bVal) {
|
|
103
115
|
return order === "asc" ? 1 : -1;
|
|
116
|
+
}
|
|
104
117
|
}
|
|
105
118
|
return 0;
|
|
106
119
|
});
|
|
@@ -122,8 +135,9 @@ class ContentCollection {
|
|
|
122
135
|
resolve() {
|
|
123
136
|
const { contentType, filter, sort, limit, _project } = this.config;
|
|
124
137
|
const entries = _project?.contentTypes?.get(contentType ?? "");
|
|
125
|
-
if (!entries)
|
|
138
|
+
if (!entries) {
|
|
126
139
|
return [];
|
|
140
|
+
}
|
|
127
141
|
return queryContentType(entries, {
|
|
128
142
|
...filter != null && {
|
|
129
143
|
filter
|
|
@@ -144,15 +158,17 @@ class ContentEntry {
|
|
|
144
158
|
resolve() {
|
|
145
159
|
const { contentType, id, field, _project, _document } = this.config;
|
|
146
160
|
const entries = _project?.contentTypes?.get(contentType ?? "");
|
|
147
|
-
if (!entries)
|
|
161
|
+
if (!entries) {
|
|
148
162
|
return null;
|
|
163
|
+
}
|
|
149
164
|
let resolvedId = id;
|
|
150
165
|
if (resolvedId && typeof resolvedId === "object" && resolvedId.$ref?.startsWith("#/$params/")) {
|
|
151
166
|
const paramName = resolvedId.$ref.replace("#/$params/", "");
|
|
152
167
|
resolvedId = _document?.route?._pathParams?.[paramName];
|
|
153
168
|
}
|
|
154
|
-
if (!resolvedId)
|
|
169
|
+
if (!resolvedId) {
|
|
155
170
|
return null;
|
|
171
|
+
}
|
|
156
172
|
if (field && field !== "id") {
|
|
157
173
|
return entries.find((e) => e.data[field] === resolvedId) ?? null;
|
|
158
174
|
}
|
package/dist/csv.js
CHANGED
|
@@ -58,7 +58,7 @@ function parseCSV(csv) {
|
|
|
58
58
|
current += ch;
|
|
59
59
|
if (inQuotes && csv[i + 1] === '"') {
|
|
60
60
|
current += csv[i + 1];
|
|
61
|
-
i
|
|
61
|
+
i += 1;
|
|
62
62
|
} else {
|
|
63
63
|
inQuotes = !inQuotes;
|
|
64
64
|
}
|
|
@@ -67,16 +67,19 @@ function parseCSV(csv) {
|
|
|
67
67
|
`) && !inQuotes) {
|
|
68
68
|
lines.push(current);
|
|
69
69
|
current = "";
|
|
70
|
-
if (ch === "\r")
|
|
71
|
-
i
|
|
70
|
+
if (ch === "\r") {
|
|
71
|
+
i += 1;
|
|
72
|
+
}
|
|
72
73
|
} else {
|
|
73
74
|
current += ch;
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
|
-
if (current.trim())
|
|
77
|
+
if (current.trim()) {
|
|
77
78
|
lines.push(current);
|
|
78
|
-
|
|
79
|
+
}
|
|
80
|
+
if (lines.length === 0) {
|
|
79
81
|
return [];
|
|
82
|
+
}
|
|
80
83
|
const parseRow = (line) => {
|
|
81
84
|
const fields = [];
|
|
82
85
|
let field = "";
|
|
@@ -86,7 +89,7 @@ function parseCSV(csv) {
|
|
|
86
89
|
if (ch === '"') {
|
|
87
90
|
if (q && line[i + 1] === '"') {
|
|
88
91
|
field += '"';
|
|
89
|
-
i
|
|
92
|
+
i += 1;
|
|
90
93
|
} else {
|
|
91
94
|
q = !q;
|
|
92
95
|
}
|
|
@@ -116,16 +119,17 @@ function coerceCSVRows(rows, schema, idField) {
|
|
|
116
119
|
const data = { ...row };
|
|
117
120
|
if (schema?.properties) {
|
|
118
121
|
for (const [key, def] of Object.entries(schema.properties)) {
|
|
119
|
-
if (!(key in data))
|
|
122
|
+
if (!(key in data)) {
|
|
120
123
|
continue;
|
|
124
|
+
}
|
|
121
125
|
if (def.type === "number") {
|
|
122
126
|
const raw = String(data[key] ?? "").trim();
|
|
123
127
|
if (raw === "") {
|
|
124
128
|
data[key] = null;
|
|
125
129
|
} else {
|
|
126
|
-
const cleaned = raw.
|
|
130
|
+
const cleaned = raw.replaceAll(/[$€£¥,\s]/g, "");
|
|
127
131
|
const n = Number(cleaned);
|
|
128
|
-
data[key] = isNaN(n) ? null : n;
|
|
132
|
+
data[key] = Number.isNaN(n) ? null : n;
|
|
129
133
|
}
|
|
130
134
|
} else if (def.type === "boolean") {
|
|
131
135
|
data[key] = data[key] === "true";
|
|
@@ -136,7 +140,7 @@ function coerceCSVRows(rows, schema, idField) {
|
|
|
136
140
|
}
|
|
137
141
|
}
|
|
138
142
|
const id = (idField ? data[idField] : undefined) ?? data.id ?? data.sku ?? data.slug ?? data.Slug ?? String(i);
|
|
139
|
-
return {
|
|
143
|
+
return { body: null, data, id };
|
|
140
144
|
});
|
|
141
145
|
}
|
|
142
146
|
|
|
@@ -170,7 +174,7 @@ class Csv {
|
|
|
170
174
|
return Csv.parse(await response.text(), options);
|
|
171
175
|
}
|
|
172
176
|
const { readFileSync } = await import("node:fs");
|
|
173
|
-
return Csv.parse(readFileSync(path, "
|
|
177
|
+
return Csv.parse(readFileSync(path, "utf8"), options);
|
|
174
178
|
}
|
|
175
179
|
async resolve() {
|
|
176
180
|
const { src, basePath, ...options } = this.config;
|