cu

css-units

Value-type representation of CSS units (e.g. px, cm, deg) and a conversion function

Showing:

Popularity

Downloads/wk

3

GitHub Stars

1

Maintenance

Last Commit

7yrs ago

Contributors

0

Package

Dependencies

1

Size (min+gzip)

0.6KB

License

ISC

Type Definitions

Tree-Shakeable

No?

Categories

Readme

css-units

Value-type representation of common CSS units plus a conversion function.

Installation

npm

Get it:

npm install css-units

Require it:

var unit = require('css-units');

API

var v = unit(value, unit)

var v = new unit.Value(value, unit)

Create a new object with the given numeric value and string unit (one of in, cm, pc, mm, pt, px, deg, rad, s, ms, %, em or ex).

v.value

v.unit

value.toString()

Returns a CSS-compatible string representation of the value.

value.convertTo(otherUnit)

Convert value to otherUnit. Returns a new instance of unit.Value on success, throws an error when no conversion is possible.

unit.convert(toUnit, fromUnit, value)

Convert the number value from fromUnit to toUnit. Returns a number on success, throws an error when no conversion is possible. Note the reversed argument order; this is to promote use of partial-application in FP applications.

unit.convertValue(toUnit, value)

Converts Value instance value to toUnit, returning a new instance on success or throwing an error when no conversion is possible. Note the reversed argument order; this is to promote use of partial-application in FP applications.

© 2014 Jason Frame [ @jaz303 / jason@onehackoranother.com ]

Released under the ISC license.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100