joyent-portal/packages/remcalc/src/index.js

12 lines
327 B
JavaScript
Raw Normal View History

2017-06-16 23:46:36 +03:00
const flatten = require('lodash.flatten');
const BASE = 16;
const calc = (base, ...values) =>
flatten(values.map(value => String(value).split(/\s/gim)))
.map(value => `${Number(value.replace('px', '')) / base}rem`)
.join(' ');
module.exports = (...values) => calc(BASE, ...values);
module.exports.withBase = calc;