UNPKG

@gannochenko/ui.styled-components

Version:

<!-- PROJECT SHIELDS --> <!-- *** Reference links are enclosed in brackets [ ] instead of parentheses ( ). *** See the bottom of this document for the declaration of the reference variables *** for contributors-url, forks-url, etc. This is an optional, co

30 lines 790 B
export const pInt = (val) => { let iVal = 0; if (typeof val === 'string') { iVal = parseInt(val, 10); if (Number.isNaN(iVal)) { iVal = 0; } } else if (typeof val !== 'undefined' && val !== null) { iVal = val; } return iVal; }; export const op = (val, fn) => { if (typeof val === 'undefined' || val === null) { return val; } const results = val .toString() .trim() .match(/^(\d+)?(.(\d+))?(px|rem|em)?$/i); if (results && results.length) { const full = pInt(results[1]); const frac = pInt(results[3]); const unit = results[4] || ''; return `${fn(full + +`0.${frac}`)}${unit}`; } return val.toString(); }; //# sourceMappingURL=op.js.map