-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
26 lines (21 loc) · 725 Bytes
/
index.js
File metadata and controls
26 lines (21 loc) · 725 Bytes
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
var utils = require('./utils');
module.exports = function (source) {
if (!this.cacheable || !this.query) {
return source;
}
this.cacheable();
var query = Object.assign({},{
viewportWidth: 750,
viewportUnit: 'vw',
minPixelValue:1,
decimal:3
},utils.getQueryString(this.query));
var matchPXExp = /([0-9.]+px)([;,| |}|'|"\)\r|\n])/g;
return source.replace(matchPXExp, function (match, m1, m2) {
var pixels = parseFloat(m1.slice(0, m1.length - 2));
if (pixels <= query.minPixelValue) {
return match;
}
return utils.createPxReplace(pixels, query.viewportWidth, query.decimal, query.viewportUnit) + m2;
});
};