mizmoz.com / css-math
Simple library for performing math operations on css properties.
Installation
NPM
npm install --save css-math
Yarn
yarn add css-math
API
Parser
; // the parser will the value with the provided unit only a single unit type can be // provided right now. Only %, em, rem, px ; // 50px; // 20px // percents, be default we round to 6 decimal places; // 33.333333% // a more complex example; // 81px
Fraction ( > 0.2 )
Return the value of the fraction of the supplied number
; ; // 33.333333%; // 1000px; // 200px
Max ( > 0.3 )
Find the max value from the provided list
; ; // 100%
Min ( > 0.3 )
Find the min value from the provided list
; ; // 600px
Helpers
Get padding box values
Find the top, right, bottom & left padding values from a string
; ; // { top: 10px, bottom: 10px, left: 20px, right: 20px, width: 40px, height: 20px }
Parse value
Parse a string and return it's numeric value and unit type
; ; // { value: 10, unit: px }
Roadmap
Add support for setting a base for a unit
// 150px // 228px