-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
24 lines (21 loc) · 733 Bytes
/
Copy pathindex.js
File metadata and controls
24 lines (21 loc) · 733 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
require('array.prototype.find');
require('array-includes').shim();
var postcss = require('postcss');
var converters = require('./lib/converters');
function translate (value, amount, unit) {
var convert = converters.find(function (converter) {
return converter.unit.includes(unit.toLowerCase());
}, unit);
return convert.css(parseFloat(amount));
}
module.exports = postcss.plugin('postcss-imperial', function (opts) {
opts = opts || {};
return function (css) {
converters.forEach(function (converter) {
converter.unit.forEach(function (unit) {
var pattern = new RegExp('^(\\d+\\.?\\d*)(' + unit + ')$', 'i');
css.replaceValues(pattern, { fast: unit }, translate);
});
});
};
});