dtable-ui-component 0.1.71 → 0.1.75-beta
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/assets/dtable-font/dtable-font.eot +0 -0
- package/assets/dtable-font/dtable-font.svg +441 -405
- package/assets/dtable-font/dtable-font.ttf +0 -0
- package/assets/dtable-font/dtable-font.woff +0 -0
- package/assets/dtable-font/dtable-font.woff2 +0 -0
- package/assets/dtable-font.css +352 -11
- package/es/components/cell-formatter/collaborator-formatter.js +0 -1
- package/es/components/cell-formatter/creator-formatter.js +1 -2
- package/es/components/cell-formatter/last-modifier-formatter.js +1 -2
- package/es/components/cell-formatter/long-text-formatter.js +20 -98
- package/es/components/cell-formatter/multiple-select-formatter.js +1 -1
- package/es/components/cell-formatter/widgets/long-text-formatter/html-long-text-formatter.js +96 -0
- package/es/components/cell-formatter/widgets/long-text-formatter/simple-long-text-formatter.js +104 -0
- package/es/css/cell-formatter.css +6 -0
- package/es/utils/markdown2html.js +62 -0
- package/es/utils/normalize-long-text-value.js +8 -7
- package/es/utils/unified/index.js +470 -0
- package/es/utils/vfile/core.js +172 -0
- package/es/utils/vfile/index.js +48 -0
- package/package.json +19 -3
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* Dependencies. */
|
|
3
|
+
|
|
4
|
+
var extend = require('extend');
|
|
5
|
+
|
|
6
|
+
var bail = require('bail');
|
|
7
|
+
|
|
8
|
+
var vfile = require('../vfile');
|
|
9
|
+
|
|
10
|
+
var trough = require('trough');
|
|
11
|
+
|
|
12
|
+
var string = require('x-is-string');
|
|
13
|
+
|
|
14
|
+
var plain = require('is-plain-obj');
|
|
15
|
+
/* Expose a frozen processor. */
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
module.exports = unified().freeze();
|
|
19
|
+
var slice = [].slice;
|
|
20
|
+
var own = {}.hasOwnProperty;
|
|
21
|
+
/* Process pipeline. */
|
|
22
|
+
|
|
23
|
+
var pipeline = trough().use(pipelineParse).use(pipelineRun).use(pipelineStringify);
|
|
24
|
+
|
|
25
|
+
function pipelineParse(p, ctx) {
|
|
26
|
+
ctx.tree = p.parse(ctx.file);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function pipelineRun(p, ctx, next) {
|
|
30
|
+
p.run(ctx.tree, ctx.file, done);
|
|
31
|
+
|
|
32
|
+
function done(err, tree, file) {
|
|
33
|
+
if (err) {
|
|
34
|
+
next(err);
|
|
35
|
+
} else {
|
|
36
|
+
ctx.tree = tree;
|
|
37
|
+
ctx.file = file;
|
|
38
|
+
next();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function pipelineStringify(p, ctx) {
|
|
44
|
+
ctx.file.contents = p.stringify(ctx.tree, ctx.file);
|
|
45
|
+
}
|
|
46
|
+
/* Function to create the first processor. */
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
function unified() {
|
|
50
|
+
var attachers = [];
|
|
51
|
+
var transformers = trough();
|
|
52
|
+
var namespace = {};
|
|
53
|
+
var frozen = false;
|
|
54
|
+
var freezeIndex = -1;
|
|
55
|
+
/* Data management. */
|
|
56
|
+
|
|
57
|
+
processor.data = data;
|
|
58
|
+
/* Lock. */
|
|
59
|
+
|
|
60
|
+
processor.freeze = freeze;
|
|
61
|
+
/* Plug-ins. */
|
|
62
|
+
|
|
63
|
+
processor.attachers = attachers;
|
|
64
|
+
processor.use = use;
|
|
65
|
+
/* API. */
|
|
66
|
+
|
|
67
|
+
processor.parse = parse;
|
|
68
|
+
processor.stringify = stringify;
|
|
69
|
+
processor.run = run;
|
|
70
|
+
processor.runSync = runSync;
|
|
71
|
+
processor.process = process;
|
|
72
|
+
processor.processSync = processSync;
|
|
73
|
+
/* Expose. */
|
|
74
|
+
|
|
75
|
+
return processor;
|
|
76
|
+
/* Create a new processor based on the processor
|
|
77
|
+
* in the current scope. */
|
|
78
|
+
|
|
79
|
+
function processor() {
|
|
80
|
+
var destination = unified();
|
|
81
|
+
var length = attachers.length;
|
|
82
|
+
var index = -1;
|
|
83
|
+
|
|
84
|
+
while (++index < length) {
|
|
85
|
+
destination.use.apply(null, attachers[index]);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
destination.data(extend(true, {}, namespace));
|
|
89
|
+
return destination;
|
|
90
|
+
}
|
|
91
|
+
/* Freeze: used to signal a processor that has finished
|
|
92
|
+
* configuration.
|
|
93
|
+
*
|
|
94
|
+
* For example, take unified itself. It’s frozen.
|
|
95
|
+
* Plug-ins should not be added to it. Rather, it should
|
|
96
|
+
* be extended, by invoking it, before modifying it.
|
|
97
|
+
*
|
|
98
|
+
* In essence, always invoke this when exporting a
|
|
99
|
+
* processor. */
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
function freeze() {
|
|
103
|
+
var values;
|
|
104
|
+
var plugin;
|
|
105
|
+
var options;
|
|
106
|
+
var transformer;
|
|
107
|
+
|
|
108
|
+
if (frozen) {
|
|
109
|
+
return processor;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
while (++freezeIndex < attachers.length) {
|
|
113
|
+
values = attachers[freezeIndex];
|
|
114
|
+
plugin = values[0];
|
|
115
|
+
options = values[1];
|
|
116
|
+
transformer = null;
|
|
117
|
+
|
|
118
|
+
if (options === false) {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (options === true) {
|
|
123
|
+
values[1] = undefined;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
transformer = plugin.apply(processor, values.slice(1));
|
|
127
|
+
|
|
128
|
+
if (typeof transformer === 'function') {
|
|
129
|
+
transformers.use(transformer);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
frozen = true;
|
|
134
|
+
freezeIndex = Infinity;
|
|
135
|
+
return processor;
|
|
136
|
+
}
|
|
137
|
+
/* Data management.
|
|
138
|
+
* Getter / setter for processor-specific informtion. */
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
function data(key, value) {
|
|
142
|
+
if (string(key)) {
|
|
143
|
+
/* Set `key`. */
|
|
144
|
+
if (arguments.length === 2) {
|
|
145
|
+
assertUnfrozen('data', frozen);
|
|
146
|
+
namespace[key] = value;
|
|
147
|
+
return processor;
|
|
148
|
+
}
|
|
149
|
+
/* Get `key`. */
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
return own.call(namespace, key) && namespace[key] || null;
|
|
153
|
+
}
|
|
154
|
+
/* Set space. */
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
if (key) {
|
|
158
|
+
assertUnfrozen('data', frozen);
|
|
159
|
+
namespace = key;
|
|
160
|
+
return processor;
|
|
161
|
+
}
|
|
162
|
+
/* Get space. */
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
return namespace;
|
|
166
|
+
}
|
|
167
|
+
/* Plug-in management.
|
|
168
|
+
*
|
|
169
|
+
* Pass it:
|
|
170
|
+
* * an attacher and options,
|
|
171
|
+
* * a preset,
|
|
172
|
+
* * a list of presets, attachers, and arguments (list
|
|
173
|
+
* of attachers and options). */
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
function use(value) {
|
|
177
|
+
var settings;
|
|
178
|
+
assertUnfrozen('use', frozen);
|
|
179
|
+
|
|
180
|
+
if (value === null || value === undefined) {
|
|
181
|
+
/* Empty */
|
|
182
|
+
} else if (typeof value === 'function') {
|
|
183
|
+
addPlugin.apply(null, arguments);
|
|
184
|
+
} else if (typeof value === 'object') {
|
|
185
|
+
if ('length' in value) {
|
|
186
|
+
addList(value);
|
|
187
|
+
} else {
|
|
188
|
+
addPreset(value);
|
|
189
|
+
}
|
|
190
|
+
} else {
|
|
191
|
+
throw new Error('Expected usable value, not `' + value + '`');
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (settings) {
|
|
195
|
+
namespace.settings = extend(namespace.settings || {}, settings);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return processor;
|
|
199
|
+
|
|
200
|
+
function addPreset(result) {
|
|
201
|
+
addList(result.plugins);
|
|
202
|
+
|
|
203
|
+
if (result.settings) {
|
|
204
|
+
settings = extend(settings || {}, result.settings);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function add(value) {
|
|
209
|
+
if (typeof value === 'function') {
|
|
210
|
+
addPlugin(value);
|
|
211
|
+
} else if (typeof value === 'object') {
|
|
212
|
+
if ('length' in value) {
|
|
213
|
+
addPlugin.apply(null, value);
|
|
214
|
+
} else {
|
|
215
|
+
addPreset(value);
|
|
216
|
+
}
|
|
217
|
+
} else {
|
|
218
|
+
throw new Error('Expected usable value, not `' + value + '`');
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function addList(plugins) {
|
|
223
|
+
var length;
|
|
224
|
+
var index;
|
|
225
|
+
|
|
226
|
+
if (plugins === null || plugins === undefined) {
|
|
227
|
+
/* Empty */
|
|
228
|
+
} else if (typeof plugins === 'object' && 'length' in plugins) {
|
|
229
|
+
length = plugins.length;
|
|
230
|
+
index = -1;
|
|
231
|
+
|
|
232
|
+
while (++index < length) {
|
|
233
|
+
add(plugins[index]);
|
|
234
|
+
}
|
|
235
|
+
} else {
|
|
236
|
+
throw new Error('Expected a list of plugins, not `' + plugins + '`');
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function addPlugin(plugin, value) {
|
|
241
|
+
var entry = find(plugin);
|
|
242
|
+
|
|
243
|
+
if (entry) {
|
|
244
|
+
if (plain(entry[1]) && plain(value)) {
|
|
245
|
+
value = extend(entry[1], value);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
entry[1] = value;
|
|
249
|
+
} else {
|
|
250
|
+
attachers.push(slice.call(arguments));
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function find(plugin) {
|
|
256
|
+
var length = attachers.length;
|
|
257
|
+
var index = -1;
|
|
258
|
+
var entry;
|
|
259
|
+
|
|
260
|
+
while (++index < length) {
|
|
261
|
+
entry = attachers[index];
|
|
262
|
+
|
|
263
|
+
if (entry[0] === plugin) {
|
|
264
|
+
return entry;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/* Parse a file (in string or VFile representation)
|
|
269
|
+
* into a Unist node using the `Parser` on the
|
|
270
|
+
* processor. */
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
function parse(doc) {
|
|
274
|
+
var file = vfile(doc);
|
|
275
|
+
var Parser;
|
|
276
|
+
freeze();
|
|
277
|
+
Parser = processor.Parser;
|
|
278
|
+
assertParser('parse', Parser);
|
|
279
|
+
|
|
280
|
+
if (newable(Parser)) {
|
|
281
|
+
return new Parser(String(file), file).parse();
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
return Parser(String(file), file); // eslint-disable-line new-cap
|
|
285
|
+
}
|
|
286
|
+
/* Run transforms on a Unist node representation of a file
|
|
287
|
+
* (in string or VFile representation), async. */
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
function run(node, file, cb) {
|
|
291
|
+
assertNode(node);
|
|
292
|
+
freeze();
|
|
293
|
+
|
|
294
|
+
if (!cb && typeof file === 'function') {
|
|
295
|
+
cb = file;
|
|
296
|
+
file = null;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (!cb) {
|
|
300
|
+
return new Promise(executor);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
executor(null, cb);
|
|
304
|
+
|
|
305
|
+
function executor(resolve, reject) {
|
|
306
|
+
transformers.run(node, vfile(file), done);
|
|
307
|
+
|
|
308
|
+
function done(err, tree, file) {
|
|
309
|
+
tree = tree || node;
|
|
310
|
+
|
|
311
|
+
if (err) {
|
|
312
|
+
reject(err);
|
|
313
|
+
} else if (resolve) {
|
|
314
|
+
resolve(tree);
|
|
315
|
+
} else {
|
|
316
|
+
cb(null, tree, file);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
/* Run transforms on a Unist node representation of a file
|
|
322
|
+
* (in string or VFile representation), sync. */
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
function runSync(node, file) {
|
|
326
|
+
var complete = false;
|
|
327
|
+
var result;
|
|
328
|
+
run(node, file, done);
|
|
329
|
+
assertDone('runSync', 'run', complete);
|
|
330
|
+
return result;
|
|
331
|
+
|
|
332
|
+
function done(err, tree) {
|
|
333
|
+
complete = true;
|
|
334
|
+
bail(err);
|
|
335
|
+
result = tree;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
/* Stringify a Unist node representation of a file
|
|
339
|
+
* (in string or VFile representation) into a string
|
|
340
|
+
* using the `Compiler` on the processor. */
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
function stringify(node, doc) {
|
|
344
|
+
var file = vfile(doc);
|
|
345
|
+
var Compiler;
|
|
346
|
+
freeze();
|
|
347
|
+
Compiler = processor.Compiler;
|
|
348
|
+
assertCompiler('stringify', Compiler);
|
|
349
|
+
assertNode(node);
|
|
350
|
+
|
|
351
|
+
if (newable(Compiler)) {
|
|
352
|
+
return new Compiler(node, file).compile();
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return Compiler(node, file); // eslint-disable-line new-cap
|
|
356
|
+
}
|
|
357
|
+
/* Parse a file (in string or VFile representation)
|
|
358
|
+
* into a Unist node using the `Parser` on the processor,
|
|
359
|
+
* then run transforms on that node, and compile the
|
|
360
|
+
* resulting node using the `Compiler` on the processor,
|
|
361
|
+
* and store that result on the VFile. */
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
function process(doc, cb) {
|
|
365
|
+
freeze();
|
|
366
|
+
assertParser('process', processor.Parser);
|
|
367
|
+
assertCompiler('process', processor.Compiler);
|
|
368
|
+
|
|
369
|
+
if (!cb) {
|
|
370
|
+
return new Promise(executor);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
executor(null, cb);
|
|
374
|
+
|
|
375
|
+
function executor(resolve, reject) {
|
|
376
|
+
var file = vfile(doc);
|
|
377
|
+
pipeline.run(processor, {
|
|
378
|
+
file: file
|
|
379
|
+
}, done);
|
|
380
|
+
|
|
381
|
+
function done(err) {
|
|
382
|
+
if (err) {
|
|
383
|
+
reject(err);
|
|
384
|
+
} else if (resolve) {
|
|
385
|
+
resolve(file);
|
|
386
|
+
} else {
|
|
387
|
+
cb(null, file);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
/* Process the given document (in string or VFile
|
|
393
|
+
* representation), sync. */
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
function processSync(doc) {
|
|
397
|
+
var complete = false;
|
|
398
|
+
var file;
|
|
399
|
+
freeze();
|
|
400
|
+
assertParser('processSync', processor.Parser);
|
|
401
|
+
assertCompiler('processSync', processor.Compiler);
|
|
402
|
+
file = vfile(doc);
|
|
403
|
+
process(file, done);
|
|
404
|
+
assertDone('processSync', 'process', complete);
|
|
405
|
+
return file;
|
|
406
|
+
|
|
407
|
+
function done(err) {
|
|
408
|
+
complete = true;
|
|
409
|
+
bail(err);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
/* Check if `func` is a constructor. */
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
function newable(value) {
|
|
417
|
+
return typeof value === 'function' && keys(value.prototype);
|
|
418
|
+
}
|
|
419
|
+
/* Check if `value` is an object with keys. */
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
function keys(value) {
|
|
423
|
+
var key;
|
|
424
|
+
|
|
425
|
+
for (key in value) {
|
|
426
|
+
return true;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
return false;
|
|
430
|
+
}
|
|
431
|
+
/* Assert a parser is available. */
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
function assertParser(name, Parser) {
|
|
435
|
+
if (typeof Parser !== 'function') {
|
|
436
|
+
throw new Error('Cannot `' + name + '` without `Parser`');
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
/* Assert a compiler is available. */
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
function assertCompiler(name, Compiler) {
|
|
443
|
+
if (typeof Compiler !== 'function') {
|
|
444
|
+
throw new Error('Cannot `' + name + '` without `Compiler`');
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
/* Assert the processor is not frozen. */
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
function assertUnfrozen(name, frozen) {
|
|
451
|
+
if (frozen) {
|
|
452
|
+
throw new Error(['Cannot invoke `' + name + '` on a frozen processor.\nCreate a new ', 'processor first, by invoking it: use `processor()` instead of ', '`processor`.'].join(''));
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
/* Assert `node` is a Unist node. */
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
function assertNode(node) {
|
|
459
|
+
if (!node || !string(node.type)) {
|
|
460
|
+
throw new Error('Expected node, got `' + node + '`');
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
/* Assert that `complete` is `true`. */
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
function assertDone(name, asyncName, complete) {
|
|
467
|
+
if (!complete) {
|
|
468
|
+
throw new Error('`' + name + '` finished async. Use `' + asyncName + '` instead');
|
|
469
|
+
}
|
|
470
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var path = require('path');
|
|
4
|
+
|
|
5
|
+
var replace = require('replace-ext');
|
|
6
|
+
|
|
7
|
+
var buffer = require('is-buffer');
|
|
8
|
+
|
|
9
|
+
module.exports = VFile;
|
|
10
|
+
var own = {}.hasOwnProperty;
|
|
11
|
+
var proto = VFile.prototype;
|
|
12
|
+
proto.toString = toString;
|
|
13
|
+
/* Order of setting (least specific to most), we need this because
|
|
14
|
+
* otherwise `{stem: 'a', path: '~/b.js'}` would throw, as a path
|
|
15
|
+
* is needed before a stem can be set. */
|
|
16
|
+
|
|
17
|
+
var order = ['history', 'path', 'basename', 'stem', 'extname', 'dirname'];
|
|
18
|
+
/* Construct a new file. */
|
|
19
|
+
|
|
20
|
+
function VFile(options) {
|
|
21
|
+
var prop;
|
|
22
|
+
var index;
|
|
23
|
+
var length;
|
|
24
|
+
|
|
25
|
+
if (typeof options === 'number') {
|
|
26
|
+
options = options.toString();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!options) {
|
|
30
|
+
options = {};
|
|
31
|
+
} else if (typeof options === 'string' || buffer(options)) {
|
|
32
|
+
options = {
|
|
33
|
+
contents: options
|
|
34
|
+
};
|
|
35
|
+
} else if ('message' in options && 'messages' in options) {
|
|
36
|
+
return options;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!(this instanceof VFile)) {
|
|
40
|
+
return new VFile(options);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
this.data = {};
|
|
44
|
+
this.messages = [];
|
|
45
|
+
this.history = [];
|
|
46
|
+
this.cwd = process.cwd();
|
|
47
|
+
/* Set path related properties in the correct order. */
|
|
48
|
+
|
|
49
|
+
index = -1;
|
|
50
|
+
length = order.length;
|
|
51
|
+
|
|
52
|
+
while (++index < length) {
|
|
53
|
+
prop = order[index];
|
|
54
|
+
|
|
55
|
+
if (own.call(options, prop)) {
|
|
56
|
+
this[prop] = options[prop];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/* Set non-path related properties. */
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
for (prop in options) {
|
|
63
|
+
if (order.indexOf(prop) === -1) {
|
|
64
|
+
this[prop] = options[prop];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/* Access full path (`~/index.min.js`). */
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
Object.defineProperty(proto, 'path', {
|
|
72
|
+
get: function get() {
|
|
73
|
+
return this.history[this.history.length - 1];
|
|
74
|
+
},
|
|
75
|
+
set: function set(path) {
|
|
76
|
+
assertNonEmpty(path, 'path');
|
|
77
|
+
|
|
78
|
+
if (path !== this.path) {
|
|
79
|
+
this.history.push(path);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
/* Access parent path (`~`). */
|
|
84
|
+
|
|
85
|
+
Object.defineProperty(proto, 'dirname', {
|
|
86
|
+
get: function get() {
|
|
87
|
+
return typeof this.path === 'string' ? path.dirname(this.path) : undefined;
|
|
88
|
+
},
|
|
89
|
+
set: function set(dirname) {
|
|
90
|
+
assertPath(this.path, 'dirname');
|
|
91
|
+
this.path = path.join(dirname || '', this.basename);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
/* Access basename (`index.min.js`). */
|
|
95
|
+
|
|
96
|
+
Object.defineProperty(proto, 'basename', {
|
|
97
|
+
get: function get() {
|
|
98
|
+
return typeof this.path === 'string' ? path.basename(this.path) : undefined;
|
|
99
|
+
},
|
|
100
|
+
set: function set(basename) {
|
|
101
|
+
assertNonEmpty(basename, 'basename');
|
|
102
|
+
assertPart(basename, 'basename');
|
|
103
|
+
this.path = path.join(this.dirname || '', basename);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
/* Access extname (`.js`). */
|
|
107
|
+
|
|
108
|
+
Object.defineProperty(proto, 'extname', {
|
|
109
|
+
get: function get() {
|
|
110
|
+
return typeof this.path === 'string' ? path.extname(this.path) : undefined;
|
|
111
|
+
},
|
|
112
|
+
set: function set(extname) {
|
|
113
|
+
var ext = extname || '';
|
|
114
|
+
assertPart(ext, 'extname');
|
|
115
|
+
assertPath(this.path, 'extname');
|
|
116
|
+
|
|
117
|
+
if (ext) {
|
|
118
|
+
if (ext.charAt(0) !== '.') {
|
|
119
|
+
throw new Error('`extname` must start with `.`');
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (ext.indexOf('.', 1) !== -1) {
|
|
123
|
+
throw new Error('`extname` cannot contain multiple dots');
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
this.path = replace(this.path, ext);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
/* Access stem (`index.min`). */
|
|
131
|
+
|
|
132
|
+
Object.defineProperty(proto, 'stem', {
|
|
133
|
+
get: function get() {
|
|
134
|
+
return typeof this.path === 'string' ? path.basename(this.path, this.extname) : undefined;
|
|
135
|
+
},
|
|
136
|
+
set: function set(stem) {
|
|
137
|
+
assertNonEmpty(stem, 'stem');
|
|
138
|
+
assertPart(stem, 'stem');
|
|
139
|
+
this.path = path.join(this.dirname || '', stem + (this.extname || ''));
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
/* Get the value of the file. */
|
|
143
|
+
|
|
144
|
+
function toString(encoding) {
|
|
145
|
+
var value = this.contents || '';
|
|
146
|
+
return buffer(value) ? value.toString(encoding) : String(value);
|
|
147
|
+
}
|
|
148
|
+
/* Assert that `part` is not a path (i.e., does
|
|
149
|
+
* not contain `path.sep`). */
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
function assertPart(part, name) {
|
|
153
|
+
if (part.indexOf(path.sep) !== -1) {
|
|
154
|
+
throw new Error('`' + name + '` cannot be a path: did not expect `' + path.sep + '`');
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/* Assert that `part` is not empty. */
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
function assertNonEmpty(part, name) {
|
|
161
|
+
if (!part) {
|
|
162
|
+
throw new Error('`' + name + '` cannot be empty');
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/* Assert `path` exists. */
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
function assertPath(path, name) {
|
|
169
|
+
if (!path) {
|
|
170
|
+
throw new Error('Setting `' + name + '` requires `path` to be set too');
|
|
171
|
+
}
|
|
172
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var VMessage = require('vfile-message');
|
|
4
|
+
|
|
5
|
+
var VFile = require('./core.js');
|
|
6
|
+
|
|
7
|
+
module.exports = VFile;
|
|
8
|
+
var proto = VFile.prototype;
|
|
9
|
+
proto.message = message;
|
|
10
|
+
proto.info = info;
|
|
11
|
+
proto.fail = fail;
|
|
12
|
+
/* Slight backwards compatibility. Remove in the future. */
|
|
13
|
+
|
|
14
|
+
proto.warn = message;
|
|
15
|
+
/* Create a message with `reason` at `position`.
|
|
16
|
+
* When an error is passed in as `reason`, copies the stack. */
|
|
17
|
+
|
|
18
|
+
function message(reason, position, origin) {
|
|
19
|
+
var filePath = this.path;
|
|
20
|
+
var message = new VMessage(reason, position, origin);
|
|
21
|
+
|
|
22
|
+
if (filePath) {
|
|
23
|
+
message.name = filePath + ':' + message.name;
|
|
24
|
+
message.file = filePath;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
message.fatal = false;
|
|
28
|
+
this.messages.push(message);
|
|
29
|
+
return message;
|
|
30
|
+
}
|
|
31
|
+
/* Fail. Creates a vmessage, associates it with the file,
|
|
32
|
+
* and throws it. */
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
function fail() {
|
|
36
|
+
var message = this.message.apply(this, arguments);
|
|
37
|
+
message.fatal = true;
|
|
38
|
+
throw message;
|
|
39
|
+
}
|
|
40
|
+
/* Info. Creates a vmessage, associates it with the file,
|
|
41
|
+
* and marks the fatality as null. */
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
function info() {
|
|
45
|
+
var message = this.message.apply(this, arguments);
|
|
46
|
+
message.fatal = null;
|
|
47
|
+
return message;
|
|
48
|
+
}
|