-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
50 lines (42 loc) · 1.04 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
/**
* Requires
*/
var util = require('gulp-util');
var PluginError = util.PluginError;
var through = require('through2');
var rework = require('rework');
var replaceRem = require('./lib');
/**
* PLUGIN_NAME
* @type {String}
*/
var PLUGIN_NAME = 'ydcss-px2rem';
/**
* Gulp rem 2 px
* @param {Number} size
* @return {Object}
*/
function rem2px(size) {
if (typeof size == 'undefined') {
size = 100
}
return through.obj(function (file, enc, callback) {
if (file.isNull()) {
this.push(file);
return callback();
}
if (file.isStream()) {
this.emit('error', new PluginError(PLUGIN_NAME, 'Streaming not supported'));
return callback();
}
try {
file.contents = new Buffer(rework(file.contents.toString()).use(replaceRem(size)).toString());
} catch (err) {
this.emit('error', new PluginError(PLUGIN_NAME, err));
}
this.push(file);
callback();
});
}
module.exports = rem2px;