@ztl-uwu/nuxt-content 2.13.5
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/LICENSE +21 -0
- package/README.md +64 -0
- package/dist/module.d.mts +1176 -0
- package/dist/module.json +12 -0
- package/dist/module.mjs +696 -0
- package/dist/runtime/app.vue +3 -0
- package/dist/runtime/app.vue.d.ts +2 -0
- package/dist/runtime/components/ContentDoc.vue +108 -0
- package/dist/runtime/components/ContentDoc.vue.d.ts +118 -0
- package/dist/runtime/components/ContentList.vue +59 -0
- package/dist/runtime/components/ContentList.vue.d.ts +59 -0
- package/dist/runtime/components/ContentNavigation.vue +61 -0
- package/dist/runtime/components/ContentNavigation.vue.d.ts +35 -0
- package/dist/runtime/components/ContentQuery.vue +212 -0
- package/dist/runtime/components/ContentQuery.vue.d.ts +0 -0
- package/dist/runtime/components/ContentRenderer.vue +78 -0
- package/dist/runtime/components/ContentRenderer.vue.d.ts +56 -0
- package/dist/runtime/components/ContentRendererMarkdown.vue +69 -0
- package/dist/runtime/components/ContentRendererMarkdown.vue.d.ts +73 -0
- package/dist/runtime/components/ContentSlot.vue +25 -0
- package/dist/runtime/components/ContentSlot.vue.d.ts +37 -0
- package/dist/runtime/components/DocumentDrivenEmpty.vue +18 -0
- package/dist/runtime/components/DocumentDrivenEmpty.vue.d.ts +17 -0
- package/dist/runtime/components/DocumentDrivenNotFound.vue +9 -0
- package/dist/runtime/components/DocumentDrivenNotFound.vue.d.ts +5 -0
- package/dist/runtime/components/Markdown.vue +29 -0
- package/dist/runtime/components/Markdown.vue.d.ts +31 -0
- package/dist/runtime/components/Prose/ProseCode.vue +32 -0
- package/dist/runtime/components/Prose/ProseCode.vue.d.ts +110 -0
- package/dist/runtime/components/Prose/ProseCodeInline.vue +3 -0
- package/dist/runtime/components/Prose/ProseCodeInline.vue.d.ts +14 -0
- package/dist/runtime/components/Prose/ProsePre.vue +42 -0
- package/dist/runtime/components/Prose/ProsePre.vue.d.ts +146 -0
- package/dist/runtime/composables/client-db.d.ts +14 -0
- package/dist/runtime/composables/client-db.js +105 -0
- package/dist/runtime/composables/content.d.ts +19 -0
- package/dist/runtime/composables/content.js +41 -0
- package/dist/runtime/composables/head.d.ts +4 -0
- package/dist/runtime/composables/head.js +94 -0
- package/dist/runtime/composables/helpers.d.ts +7 -0
- package/dist/runtime/composables/helpers.js +66 -0
- package/dist/runtime/composables/navigation.d.ts +2 -0
- package/dist/runtime/composables/navigation.js +34 -0
- package/dist/runtime/composables/preview.d.ts +5 -0
- package/dist/runtime/composables/preview.js +41 -0
- package/dist/runtime/composables/query.d.ts +10 -0
- package/dist/runtime/composables/query.js +64 -0
- package/dist/runtime/composables/search.d.ts +130 -0
- package/dist/runtime/composables/search.js +59 -0
- package/dist/runtime/composables/useUnwrap.d.ts +5 -0
- package/dist/runtime/composables/useUnwrap.js +5 -0
- package/dist/runtime/composables/utils.d.ts +6 -0
- package/dist/runtime/composables/utils.js +36 -0
- package/dist/runtime/composables/web-socket.d.ts +3 -0
- package/dist/runtime/composables/web-socket.js +65 -0
- package/dist/runtime/legacy/composables/client-db.d.ts +12 -0
- package/dist/runtime/legacy/composables/client-db.js +105 -0
- package/dist/runtime/legacy/composables/navigation.d.ts +2 -0
- package/dist/runtime/legacy/composables/navigation.js +34 -0
- package/dist/runtime/legacy/composables/query.d.ts +10 -0
- package/dist/runtime/legacy/composables/query.js +61 -0
- package/dist/runtime/legacy/plugins/documentDriven.d.ts +2 -0
- package/dist/runtime/legacy/plugins/documentDriven.js +231 -0
- package/dist/runtime/legacy/server.d.ts +3 -0
- package/dist/runtime/legacy/server.js +3 -0
- package/dist/runtime/legacy/types.d.ts +5 -0
- package/dist/runtime/pages/document-driven.vue +27 -0
- package/dist/runtime/pages/document-driven.vue.d.ts +2 -0
- package/dist/runtime/plugins/documentDriven.d.ts +2 -0
- package/dist/runtime/plugins/documentDriven.js +222 -0
- package/dist/runtime/plugins/ws.d.ts +2 -0
- package/dist/runtime/plugins/ws.js +7 -0
- package/dist/runtime/query/match/index.d.ts +6 -0
- package/dist/runtime/query/match/index.js +123 -0
- package/dist/runtime/query/match/pipeline-legacy.d.ts +2 -0
- package/dist/runtime/query/match/pipeline-legacy.js +22 -0
- package/dist/runtime/query/match/pipeline.d.ts +2 -0
- package/dist/runtime/query/match/pipeline.js +104 -0
- package/dist/runtime/query/match/utils.d.ts +35 -0
- package/dist/runtime/query/match/utils.js +65 -0
- package/dist/runtime/query/query.d.ts +12 -0
- package/dist/runtime/query/query.js +61 -0
- package/dist/runtime/server/api/cache.d.ts +7 -0
- package/dist/runtime/server/api/cache.js +18 -0
- package/dist/runtime/server/api/navigation-qid-params.d.ts +1 -0
- package/dist/runtime/server/api/navigation-qid-params.js +1 -0
- package/dist/runtime/server/api/navigation-qid.d.ts +1 -0
- package/dist/runtime/server/api/navigation-qid.js +1 -0
- package/dist/runtime/server/api/navigation.d.ts +2 -0
- package/dist/runtime/server/api/navigation.js +42 -0
- package/dist/runtime/server/api/query-qid-params.d.ts +1 -0
- package/dist/runtime/server/api/query-qid-params.js +1 -0
- package/dist/runtime/server/api/query-qid.d.ts +1 -0
- package/dist/runtime/server/api/query-qid.js +1 -0
- package/dist/runtime/server/api/query.d.ts +2 -0
- package/dist/runtime/server/api/query.js +32 -0
- package/dist/runtime/server/api/search.d.ts +8 -0
- package/dist/runtime/server/api/search.js +16 -0
- package/dist/runtime/server/content-index.d.ts +4 -0
- package/dist/runtime/server/content-index.js +37 -0
- package/dist/runtime/server/index.d.ts +1 -0
- package/dist/runtime/server/index.js +1 -0
- package/dist/runtime/server/navigation.d.ts +5 -0
- package/dist/runtime/server/navigation.js +96 -0
- package/dist/runtime/server/plugins/refresh-cache.d.ts +2 -0
- package/dist/runtime/server/plugins/refresh-cache.js +15 -0
- package/dist/runtime/server/preview.d.ts +5 -0
- package/dist/runtime/server/preview.js +9 -0
- package/dist/runtime/server/search.d.ts +14 -0
- package/dist/runtime/server/search.js +70 -0
- package/dist/runtime/server/storage.d.ts +35 -0
- package/dist/runtime/server/storage.js +238 -0
- package/dist/runtime/transformers/component-resolver.d.ts +2 -0
- package/dist/runtime/transformers/component-resolver.js +44 -0
- package/dist/runtime/transformers/csv/create-tokenizer.d.ts +39 -0
- package/dist/runtime/transformers/csv/create-tokenizer.js +307 -0
- package/dist/runtime/transformers/csv/from-csv.d.ts +13 -0
- package/dist/runtime/transformers/csv/from-csv.js +203 -0
- package/dist/runtime/transformers/csv/index.d.ts +2 -0
- package/dist/runtime/transformers/csv/index.js +50 -0
- package/dist/runtime/transformers/csv/parser.d.ts +24 -0
- package/dist/runtime/transformers/csv/parser.js +154 -0
- package/dist/runtime/transformers/index.d.ts +7 -0
- package/dist/runtime/transformers/index.js +50 -0
- package/dist/runtime/transformers/json.d.ts +2 -0
- package/dist/runtime/transformers/json.js +29 -0
- package/dist/runtime/transformers/markdown.d.ts +2 -0
- package/dist/runtime/transformers/markdown.js +88 -0
- package/dist/runtime/transformers/path-meta.d.ts +27 -0
- package/dist/runtime/transformers/path-meta.js +59 -0
- package/dist/runtime/transformers/utils.d.ts +3 -0
- package/dist/runtime/transformers/utils.js +12 -0
- package/dist/runtime/transformers/yaml.d.ts +2 -0
- package/dist/runtime/transformers/yaml.js +21 -0
- package/dist/runtime/utils/config.d.ts +4 -0
- package/dist/runtime/utils/config.js +7 -0
- package/dist/runtime/utils/html-tags.d.ts +2 -0
- package/dist/runtime/utils/html-tags.js +119 -0
- package/dist/runtime/utils/json.d.ts +10 -0
- package/dist/runtime/utils/json.js +20 -0
- package/dist/runtime/utils/query.d.ts +5 -0
- package/dist/runtime/utils/query.js +77 -0
- package/dist/runtime/virtual/transformers.d.ts +2 -0
- package/dist/types.d.mts +9 -0
- package/dist/web-types.json +572 -0
- package/package.json +111 -0
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { markdownLineEnding } from "micromark-util-character";
|
|
2
|
+
import { push, splice } from "micromark-util-chunked";
|
|
3
|
+
import { resolveAll } from "micromark-util-resolve-all";
|
|
4
|
+
export function createTokenizer(parser, initialize, from) {
|
|
5
|
+
let point = Object.assign(
|
|
6
|
+
from ? Object.assign({}, from) : {
|
|
7
|
+
line: 1,
|
|
8
|
+
column: 1,
|
|
9
|
+
offset: 0
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
_index: 0,
|
|
13
|
+
_bufferIndex: -1
|
|
14
|
+
}
|
|
15
|
+
);
|
|
16
|
+
const columnStart = {};
|
|
17
|
+
const resolveAllConstructs = [];
|
|
18
|
+
let chunks = [];
|
|
19
|
+
let stack = [];
|
|
20
|
+
let consumed = true;
|
|
21
|
+
const effects = {
|
|
22
|
+
consume,
|
|
23
|
+
enter,
|
|
24
|
+
exit,
|
|
25
|
+
attempt: constructFactory(onsuccessfulconstruct),
|
|
26
|
+
check: constructFactory(onsuccessfulcheck),
|
|
27
|
+
interrupt: constructFactory(onsuccessfulcheck, {
|
|
28
|
+
interrupt: true
|
|
29
|
+
})
|
|
30
|
+
};
|
|
31
|
+
const context = {
|
|
32
|
+
previous: null,
|
|
33
|
+
code: null,
|
|
34
|
+
containerState: {},
|
|
35
|
+
events: [],
|
|
36
|
+
parser,
|
|
37
|
+
sliceStream,
|
|
38
|
+
sliceSerialize,
|
|
39
|
+
now,
|
|
40
|
+
defineSkip,
|
|
41
|
+
write
|
|
42
|
+
};
|
|
43
|
+
let state = initialize.tokenize.call(context, effects);
|
|
44
|
+
let expectedCode;
|
|
45
|
+
if (initialize.resolveAll) {
|
|
46
|
+
resolveAllConstructs.push(initialize);
|
|
47
|
+
}
|
|
48
|
+
return context;
|
|
49
|
+
function write(slice) {
|
|
50
|
+
chunks = push(chunks, slice);
|
|
51
|
+
main();
|
|
52
|
+
if (chunks[chunks.length - 1] !== null) {
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
addResult(initialize, 0);
|
|
56
|
+
context.events = resolveAll(resolveAllConstructs, context.events, context);
|
|
57
|
+
return context.events;
|
|
58
|
+
}
|
|
59
|
+
function sliceSerialize(token, expandTabs) {
|
|
60
|
+
return serializeChunks(sliceStream(token), expandTabs);
|
|
61
|
+
}
|
|
62
|
+
function sliceStream(token) {
|
|
63
|
+
return sliceChunks(chunks, token);
|
|
64
|
+
}
|
|
65
|
+
function now() {
|
|
66
|
+
return Object.assign({}, point);
|
|
67
|
+
}
|
|
68
|
+
function defineSkip(value) {
|
|
69
|
+
columnStart[value.line] = value.column;
|
|
70
|
+
accountForPotentialSkip();
|
|
71
|
+
}
|
|
72
|
+
function main() {
|
|
73
|
+
let chunkIndex;
|
|
74
|
+
while (point._index < chunks.length) {
|
|
75
|
+
const chunk = chunks[point._index];
|
|
76
|
+
if (typeof chunk === "string") {
|
|
77
|
+
chunkIndex = point._index;
|
|
78
|
+
if (point._bufferIndex < 0) {
|
|
79
|
+
point._bufferIndex = 0;
|
|
80
|
+
}
|
|
81
|
+
while (point._index === chunkIndex && point._bufferIndex < chunk.length) {
|
|
82
|
+
go(chunk.charCodeAt(point._bufferIndex));
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
go(chunk);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function go(code) {
|
|
90
|
+
consumed = void 0;
|
|
91
|
+
expectedCode = code;
|
|
92
|
+
state = state(code);
|
|
93
|
+
}
|
|
94
|
+
function consume(code) {
|
|
95
|
+
if (markdownLineEnding(code)) {
|
|
96
|
+
point.line++;
|
|
97
|
+
point.column = 1;
|
|
98
|
+
point.offset += code === -3 ? 2 : 1;
|
|
99
|
+
accountForPotentialSkip();
|
|
100
|
+
} else if (code !== -1) {
|
|
101
|
+
point.column++;
|
|
102
|
+
point.offset++;
|
|
103
|
+
}
|
|
104
|
+
if (point._bufferIndex < 0) {
|
|
105
|
+
point._index++;
|
|
106
|
+
} else {
|
|
107
|
+
point._bufferIndex++;
|
|
108
|
+
if (point._bufferIndex === chunks[point._index].length) {
|
|
109
|
+
point._bufferIndex = -1;
|
|
110
|
+
point._index++;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
context.previous = code;
|
|
114
|
+
consumed = true;
|
|
115
|
+
}
|
|
116
|
+
function enter(type, fields) {
|
|
117
|
+
const token = fields || {};
|
|
118
|
+
token.type = type;
|
|
119
|
+
token.start = now();
|
|
120
|
+
context.events.push(["enter", token, context]);
|
|
121
|
+
stack.push(token);
|
|
122
|
+
return token;
|
|
123
|
+
}
|
|
124
|
+
function exit(type) {
|
|
125
|
+
const token = stack.pop();
|
|
126
|
+
token.end = now();
|
|
127
|
+
context.events.push(["exit", token, context]);
|
|
128
|
+
return token;
|
|
129
|
+
}
|
|
130
|
+
function onsuccessfulconstruct(construct, info) {
|
|
131
|
+
addResult(construct, info.from);
|
|
132
|
+
}
|
|
133
|
+
function onsuccessfulcheck(_, info) {
|
|
134
|
+
info.restore();
|
|
135
|
+
}
|
|
136
|
+
function constructFactory(onreturn, fields) {
|
|
137
|
+
return hook;
|
|
138
|
+
function hook(constructs, returnState, bogusState) {
|
|
139
|
+
let listOfConstructs;
|
|
140
|
+
let constructIndex;
|
|
141
|
+
let currentConstruct;
|
|
142
|
+
let info;
|
|
143
|
+
return Array.isArray(constructs) ? (
|
|
144
|
+
/* c8 ignore next 1 */
|
|
145
|
+
handleListOfConstructs(constructs)
|
|
146
|
+
) : "tokenize" in constructs ? handleListOfConstructs([constructs]) : handleMapOfConstructs(constructs);
|
|
147
|
+
function handleMapOfConstructs(map) {
|
|
148
|
+
return start;
|
|
149
|
+
function start(code) {
|
|
150
|
+
const def = code !== null && map[code];
|
|
151
|
+
const all = code !== null && map.null;
|
|
152
|
+
const list = [
|
|
153
|
+
// To do: add more extension tests.
|
|
154
|
+
/* c8 ignore next 2 */
|
|
155
|
+
...Array.isArray(def) ? def : def ? [def] : [],
|
|
156
|
+
...Array.isArray(all) ? all : all ? [all] : []
|
|
157
|
+
];
|
|
158
|
+
return handleListOfConstructs(list)(code);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function handleListOfConstructs(list) {
|
|
162
|
+
listOfConstructs = list;
|
|
163
|
+
constructIndex = 0;
|
|
164
|
+
if (list.length === 0) {
|
|
165
|
+
return bogusState;
|
|
166
|
+
}
|
|
167
|
+
return handleConstruct(list[constructIndex]);
|
|
168
|
+
}
|
|
169
|
+
function handleConstruct(construct) {
|
|
170
|
+
return start;
|
|
171
|
+
function start(code) {
|
|
172
|
+
info = store();
|
|
173
|
+
currentConstruct = construct;
|
|
174
|
+
if (!construct.partial) {
|
|
175
|
+
context.currentConstruct = construct;
|
|
176
|
+
}
|
|
177
|
+
if (construct.name && context.parser.constructs.disable.null.includes(construct.name)) {
|
|
178
|
+
return nok(code);
|
|
179
|
+
}
|
|
180
|
+
return construct.tokenize.call(
|
|
181
|
+
// If we do have fields, create an object w/ `context` as its
|
|
182
|
+
// prototype.
|
|
183
|
+
// This allows a “live binding”, which is needed for `interrupt`.
|
|
184
|
+
fields ? Object.assign(Object.create(context), fields) : context,
|
|
185
|
+
effects,
|
|
186
|
+
ok,
|
|
187
|
+
nok
|
|
188
|
+
)(code);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
function ok(code) {
|
|
192
|
+
consumed = true;
|
|
193
|
+
onreturn(currentConstruct, info);
|
|
194
|
+
return returnState;
|
|
195
|
+
}
|
|
196
|
+
function nok(code) {
|
|
197
|
+
consumed = true;
|
|
198
|
+
info.restore();
|
|
199
|
+
if (++constructIndex < listOfConstructs.length) {
|
|
200
|
+
return handleConstruct(listOfConstructs[constructIndex]);
|
|
201
|
+
}
|
|
202
|
+
return bogusState;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function addResult(construct, from2) {
|
|
207
|
+
if (construct.resolveAll && !resolveAllConstructs.includes(construct)) {
|
|
208
|
+
resolveAllConstructs.push(construct);
|
|
209
|
+
}
|
|
210
|
+
if (construct.resolve) {
|
|
211
|
+
splice(
|
|
212
|
+
context.events,
|
|
213
|
+
from2,
|
|
214
|
+
context.events.length - from2,
|
|
215
|
+
construct.resolve(context.events.slice(from2), context)
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
if (construct.resolveTo) {
|
|
219
|
+
context.events = construct.resolveTo(context.events, context);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
function store() {
|
|
223
|
+
const startPoint = now();
|
|
224
|
+
const startPrevious = context.previous;
|
|
225
|
+
const startCurrentConstruct = context.currentConstruct;
|
|
226
|
+
const startEventsIndex = context.events.length;
|
|
227
|
+
const startStack = Array.from(stack);
|
|
228
|
+
return {
|
|
229
|
+
restore,
|
|
230
|
+
from: startEventsIndex
|
|
231
|
+
};
|
|
232
|
+
function restore() {
|
|
233
|
+
point = startPoint;
|
|
234
|
+
context.previous = startPrevious;
|
|
235
|
+
context.currentConstruct = startCurrentConstruct;
|
|
236
|
+
context.events.length = startEventsIndex;
|
|
237
|
+
stack = startStack;
|
|
238
|
+
accountForPotentialSkip();
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function accountForPotentialSkip() {
|
|
242
|
+
if (point.line in columnStart && point.column < 2) {
|
|
243
|
+
point.column = columnStart[point.line];
|
|
244
|
+
point.offset += columnStart[point.line] - 1;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function sliceChunks(chunks, token) {
|
|
249
|
+
const startIndex = token.start._index;
|
|
250
|
+
const startBufferIndex = token.start._bufferIndex;
|
|
251
|
+
const endIndex = token.end._index;
|
|
252
|
+
const endBufferIndex = token.end._bufferIndex;
|
|
253
|
+
let view;
|
|
254
|
+
if (startIndex === endIndex) {
|
|
255
|
+
view = [chunks[startIndex].slice(startBufferIndex, endBufferIndex)];
|
|
256
|
+
} else {
|
|
257
|
+
view = chunks.slice(startIndex, endIndex);
|
|
258
|
+
if (startBufferIndex > -1) {
|
|
259
|
+
view[0] = view[0].slice(startBufferIndex);
|
|
260
|
+
}
|
|
261
|
+
if (endBufferIndex > 0) {
|
|
262
|
+
view.push(chunks[endIndex].slice(0, endBufferIndex));
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return view;
|
|
266
|
+
}
|
|
267
|
+
function serializeChunks(chunks, expandTabs) {
|
|
268
|
+
let index = -1;
|
|
269
|
+
const result = [];
|
|
270
|
+
let atTab;
|
|
271
|
+
while (++index < chunks.length) {
|
|
272
|
+
const chunk = chunks[index];
|
|
273
|
+
let value;
|
|
274
|
+
if (typeof chunk === "string") {
|
|
275
|
+
value = chunk;
|
|
276
|
+
} else
|
|
277
|
+
switch (chunk) {
|
|
278
|
+
case -5: {
|
|
279
|
+
value = "\r";
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
case -4: {
|
|
283
|
+
value = "\n";
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
case -3: {
|
|
287
|
+
value = "\r\n";
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
case -2: {
|
|
291
|
+
value = expandTabs ? " " : " ";
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
case -1: {
|
|
295
|
+
if (!expandTabs && atTab) continue;
|
|
296
|
+
value = " ";
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
default: {
|
|
300
|
+
value = String.fromCharCode(chunk);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
atTab = chunk === -2;
|
|
304
|
+
result.push(value);
|
|
305
|
+
}
|
|
306
|
+
return result.join("");
|
|
307
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Point as MPoint } from 'micromark-util-types';
|
|
2
|
+
type Point = Omit<MPoint, '_index' | '_bufferIndex'>;
|
|
3
|
+
type Node = {
|
|
4
|
+
type: string;
|
|
5
|
+
children: Array<Node>;
|
|
6
|
+
position?: {
|
|
7
|
+
start?: Point;
|
|
8
|
+
end?: Point;
|
|
9
|
+
};
|
|
10
|
+
value?: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const fromCSV: (value: any, encoding?: any, options?: any) => Node;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { toString } from "mdast-util-to-string";
|
|
2
|
+
import { preprocess, postprocess } from "micromark";
|
|
3
|
+
import { stringifyPosition } from "unist-util-stringify-position";
|
|
4
|
+
import { parse } from "./parser.js";
|
|
5
|
+
const own = {}.hasOwnProperty;
|
|
6
|
+
const initialPoint = {
|
|
7
|
+
line: 1,
|
|
8
|
+
column: 1,
|
|
9
|
+
offset: 0
|
|
10
|
+
};
|
|
11
|
+
export const fromCSV = function(value, encoding, options) {
|
|
12
|
+
if (typeof encoding !== "string") {
|
|
13
|
+
options = encoding;
|
|
14
|
+
encoding = void 0;
|
|
15
|
+
}
|
|
16
|
+
return compiler()(
|
|
17
|
+
postprocess(
|
|
18
|
+
parse(options).write(preprocess()(value, encoding, true))
|
|
19
|
+
)
|
|
20
|
+
);
|
|
21
|
+
};
|
|
22
|
+
function compiler() {
|
|
23
|
+
const config = {
|
|
24
|
+
enter: {
|
|
25
|
+
column: opener(openColumn),
|
|
26
|
+
row: opener(openRow),
|
|
27
|
+
data: onenterdata,
|
|
28
|
+
quotedData: onenterdata
|
|
29
|
+
},
|
|
30
|
+
exit: {
|
|
31
|
+
row: closer(),
|
|
32
|
+
column: closer(),
|
|
33
|
+
data: onexitdata,
|
|
34
|
+
quotedData: onexitQuotedData
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
return compile;
|
|
38
|
+
function compile(events) {
|
|
39
|
+
const tree = {
|
|
40
|
+
type: "root",
|
|
41
|
+
children: []
|
|
42
|
+
};
|
|
43
|
+
const stack = [tree];
|
|
44
|
+
const tokenStack = [];
|
|
45
|
+
const context = {
|
|
46
|
+
stack,
|
|
47
|
+
tokenStack,
|
|
48
|
+
config,
|
|
49
|
+
enter,
|
|
50
|
+
exit,
|
|
51
|
+
resume
|
|
52
|
+
};
|
|
53
|
+
let index = -1;
|
|
54
|
+
while (++index < events.length) {
|
|
55
|
+
const handler = config[events[index][0]];
|
|
56
|
+
if (own.call(handler, events[index][1].type)) {
|
|
57
|
+
handler[events[index][1].type].call(
|
|
58
|
+
Object.assign(
|
|
59
|
+
{
|
|
60
|
+
sliceSerialize: events[index][2].sliceSerialize
|
|
61
|
+
},
|
|
62
|
+
context
|
|
63
|
+
),
|
|
64
|
+
events[index][1]
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (tokenStack.length > 0) {
|
|
69
|
+
const tail = tokenStack[tokenStack.length - 1];
|
|
70
|
+
const handler = tail[1] || defaultOnError;
|
|
71
|
+
handler.call(context, void 0, tail[0]);
|
|
72
|
+
}
|
|
73
|
+
tree.position = {
|
|
74
|
+
start: point(
|
|
75
|
+
events.length > 0 ? events[0][1].start : initialPoint
|
|
76
|
+
),
|
|
77
|
+
end: point(
|
|
78
|
+
events.length > 0 ? events[events.length - 2][1].end : initialPoint
|
|
79
|
+
)
|
|
80
|
+
};
|
|
81
|
+
return tree;
|
|
82
|
+
}
|
|
83
|
+
function point(d) {
|
|
84
|
+
return {
|
|
85
|
+
line: d.line,
|
|
86
|
+
column: d.column,
|
|
87
|
+
offset: d.offset
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function opener(create, and) {
|
|
91
|
+
return open;
|
|
92
|
+
function open(token) {
|
|
93
|
+
enter.call(this, create(token), token);
|
|
94
|
+
if (and) {
|
|
95
|
+
and.call(this, token);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function enter(node, token, errorHandler) {
|
|
100
|
+
const parent = this.stack[this.stack.length - 1];
|
|
101
|
+
parent.children.push(node);
|
|
102
|
+
this.stack.push(node);
|
|
103
|
+
this.tokenStack.push([token, errorHandler]);
|
|
104
|
+
node.position = {
|
|
105
|
+
start: point(token.start)
|
|
106
|
+
};
|
|
107
|
+
return node;
|
|
108
|
+
}
|
|
109
|
+
function closer(and) {
|
|
110
|
+
return close;
|
|
111
|
+
function close(token) {
|
|
112
|
+
if (and) {
|
|
113
|
+
and.call(this, token);
|
|
114
|
+
}
|
|
115
|
+
exit.call(this, token);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function exit(token, onExitError) {
|
|
119
|
+
const node = this.stack.pop();
|
|
120
|
+
const open = this.tokenStack.pop();
|
|
121
|
+
if (!open) {
|
|
122
|
+
throw new Error(
|
|
123
|
+
"Cannot close `" + token.type + "` (" + stringifyPosition({
|
|
124
|
+
start: token.start,
|
|
125
|
+
end: token.end
|
|
126
|
+
}) + "): it\u2019s not open"
|
|
127
|
+
);
|
|
128
|
+
} else if (open[0].type !== token.type) {
|
|
129
|
+
if (onExitError) {
|
|
130
|
+
onExitError.call(this, token, open[0]);
|
|
131
|
+
} else {
|
|
132
|
+
const handler = open[1] || defaultOnError;
|
|
133
|
+
handler.call(this, token, open[0]);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
node.position.end = point(token.end);
|
|
137
|
+
return node;
|
|
138
|
+
}
|
|
139
|
+
function resume() {
|
|
140
|
+
return toString(this.stack.pop());
|
|
141
|
+
}
|
|
142
|
+
function onenterdata(token) {
|
|
143
|
+
const parent = this.stack[this.stack.length - 1];
|
|
144
|
+
let tail = parent.children[parent.children.length - 1];
|
|
145
|
+
if (!tail || tail.type !== "text") {
|
|
146
|
+
tail = text();
|
|
147
|
+
tail.position = {
|
|
148
|
+
start: point(token.start)
|
|
149
|
+
};
|
|
150
|
+
parent.children.push(tail);
|
|
151
|
+
}
|
|
152
|
+
this.stack.push(tail);
|
|
153
|
+
}
|
|
154
|
+
function onexitdata(token) {
|
|
155
|
+
const tail = this.stack.pop();
|
|
156
|
+
tail.value += this.sliceSerialize(token).trim().replace(/""/g, '"');
|
|
157
|
+
tail.position.end = point(token.end);
|
|
158
|
+
}
|
|
159
|
+
function onexitQuotedData(token) {
|
|
160
|
+
const tail = this.stack.pop();
|
|
161
|
+
const value = this.sliceSerialize(token);
|
|
162
|
+
tail.value += this.sliceSerialize(token).trim().substring(1, value.length - 1).replace(/""/g, '"');
|
|
163
|
+
tail.position.end = point(token.end);
|
|
164
|
+
}
|
|
165
|
+
function text() {
|
|
166
|
+
return {
|
|
167
|
+
type: "text",
|
|
168
|
+
value: ""
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function openColumn() {
|
|
172
|
+
return {
|
|
173
|
+
type: "column",
|
|
174
|
+
children: []
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function openRow() {
|
|
178
|
+
return {
|
|
179
|
+
type: "row",
|
|
180
|
+
children: []
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function defaultOnError(left, right) {
|
|
185
|
+
if (left) {
|
|
186
|
+
throw new Error(
|
|
187
|
+
"Cannot close `" + left.type + "` (" + stringifyPosition({
|
|
188
|
+
start: left.start,
|
|
189
|
+
end: left.end
|
|
190
|
+
}) + "): a different token (`" + right.type + "`, " + stringifyPosition({
|
|
191
|
+
start: right.start,
|
|
192
|
+
end: right.end
|
|
193
|
+
}) + ") is open"
|
|
194
|
+
);
|
|
195
|
+
} else {
|
|
196
|
+
throw new Error(
|
|
197
|
+
"Cannot close document, a token (`" + right.type + "`, " + stringifyPosition({
|
|
198
|
+
start: right.start,
|
|
199
|
+
end: right.end
|
|
200
|
+
}) + ") is still open"
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { unified } from "unified";
|
|
2
|
+
import { defineTransformer } from "../utils.js";
|
|
3
|
+
import { fromCSV } from "./from-csv.js";
|
|
4
|
+
function csvParse(options) {
|
|
5
|
+
const parser = (doc) => {
|
|
6
|
+
return fromCSV(doc, options);
|
|
7
|
+
};
|
|
8
|
+
Object.assign(this, { Parser: parser });
|
|
9
|
+
const toJsonObject = (tree) => {
|
|
10
|
+
const [header, ...rows] = tree.children;
|
|
11
|
+
const columns = header.children.map((col) => col.children[0].value);
|
|
12
|
+
const data = rows.map((row) => {
|
|
13
|
+
return row.children.reduce((acc, col, i) => {
|
|
14
|
+
acc[String(columns[i])] = col.children[0]?.value;
|
|
15
|
+
return acc;
|
|
16
|
+
}, {});
|
|
17
|
+
});
|
|
18
|
+
return data;
|
|
19
|
+
};
|
|
20
|
+
const toJsonArray = (tree) => {
|
|
21
|
+
const data = tree.children.map((row) => {
|
|
22
|
+
return row.children.map((col) => col.children[0]?.value);
|
|
23
|
+
});
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
const compiler = (doc) => {
|
|
27
|
+
if (options.json) {
|
|
28
|
+
return toJsonObject(doc);
|
|
29
|
+
}
|
|
30
|
+
return toJsonArray(doc);
|
|
31
|
+
};
|
|
32
|
+
Object.assign(this, { Compiler: compiler });
|
|
33
|
+
}
|
|
34
|
+
export default defineTransformer({
|
|
35
|
+
name: "csv",
|
|
36
|
+
extensions: [".csv"],
|
|
37
|
+
parse: async (_id, content, options = {}) => {
|
|
38
|
+
const stream = unified().use(csvParse, {
|
|
39
|
+
delimiter: ",",
|
|
40
|
+
json: true,
|
|
41
|
+
...options
|
|
42
|
+
});
|
|
43
|
+
const { result } = await stream.process(content);
|
|
44
|
+
return {
|
|
45
|
+
_id,
|
|
46
|
+
_type: "csv",
|
|
47
|
+
body: result
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
declare module 'micromark-util-types' {
|
|
2
|
+
interface TokenTypeMap {
|
|
3
|
+
row: 'row';
|
|
4
|
+
column: 'column';
|
|
5
|
+
columnSeparator: 'columnSeparator';
|
|
6
|
+
newline: 'newline';
|
|
7
|
+
quotedData: 'quotedData';
|
|
8
|
+
quotedDataChunk: 'quotedDataChunk';
|
|
9
|
+
quoteFence: 'quoteFence';
|
|
10
|
+
emptyLine: 'emptyLine';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export declare const parse: (options: any) => {
|
|
14
|
+
previous: null;
|
|
15
|
+
code: null;
|
|
16
|
+
containerState: {};
|
|
17
|
+
events: never[];
|
|
18
|
+
parser: any;
|
|
19
|
+
sliceStream: (token: any) => any;
|
|
20
|
+
sliceSerialize: (token: any, expandTabs: any) => string;
|
|
21
|
+
now: () => any;
|
|
22
|
+
defineSkip: (value: any) => void;
|
|
23
|
+
write: (slice: any) => never[];
|
|
24
|
+
};
|