-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
46 lines (36 loc) · 1.13 KB
/
index.js
File metadata and controls
46 lines (36 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict';
const Typograf = require('typograf');
const through = require('through2');
const PluginError = require('plugin-error');
const names = [];
function addRules(rules) {
Array.isArray(rules) && rules.forEach(function(rule) {
if (typeof rule === 'object' && typeof rule.name === 'string' && names.indexOf(rule.name) === -1) {
Typograf.addRule(rule);
names.push(rule.name);
}
});
}
module.exports = function(opts) {
opts = opts || {};
addRules(opts.rules);
const typograf = new Typograf(opts);
if (Array.isArray(opts.safeTags)) {
opts.safeTags.forEach(function(tag) {
typograf.addSafeTag.apply(typograf, tag);
});
}
return through.obj(function(file, enc, cb) {
if (file.isNull()) {
this.push(file);
return cb();
}
if (file.isStream()) {
this.emit('error', new PluginError('gulp-typograf', 'Streaming not supported'));
return cb();
}
file.contents = Buffer.from(typograf.execute(file.contents.toString()));
this.push(file);
cb();
});
};