-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
27 lines (24 loc) · 1.02 KB
/
index.js
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
var through = require('through2');
var beautify = require('js-beautify');
var hasBufferFrom = typeof Buffer.from !== 'undefined'
function createBeautifyPlugin(beautifier) {
return function gulpBeautify(opts) {
function modifyFile(file, enc, cb) {
if (file.isNull()) return cb(null, file); // pass along
if (file.isStream()) return cb(new Error('gulp-beautify: Streaming not supported'));
var str = file.contents.toString('utf8');
var result = beautifier(str, opts)
// support Node version 0.10/0.12
// while preventing deprecation warning on newer versions
file.contents = hasBufferFrom ? new Buffer.from(result) : new Buffer(result);
cb(null, file);
}
return through.obj(modifyFile);
};
}
// keep the same exports as “js-beautify”
var beautifyExport = createBeautifyPlugin(beautify);
beautifyExport.js = beautifyExport;
beautifyExport.html = createBeautifyPlugin(beautify.html);
beautifyExport.css = createBeautifyPlugin(beautify.css);
module.exports = beautifyExport;