JSPM

css-strip-units

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 373
  • Score
    100M100P100Q88964F
  • License MIT

Strip everything but the unit from a CSS value.

Package Exports

  • css-strip-units

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (css-strip-units) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

css-strip-units NPM version Build Status

Strip everything but the unit from a CSS value.

strip('1px')
// => 'px'

strip('30.5kHz')
// => 'kHz'

strip(['100%', '99rem', '.25s'])
// => ['%', 'rem', 's']

This module stays future-proof by stripping numbers off the front, so non-existent units are still passed with this module. Use another module to check the validity of units.

To get the number of a CSS value simply use parseFloat or parseInt (it actually works!):

var value = '100px'

// User css-strip-units to get unit:
var unit = strip(value)
// => 'px'

// Use parseFloat to get number:
var number = parseFloat(value)
// => 100

Installation

$ npm install --save css-strip-units

API

strip(value)

Strip any number's unit (including those non-existent).

  • value (String|Array): String or array of values to strip the unit(s) from.
strip('2px')
// => '2'

strip(['.01px', '9px'])
// => ['.01', '9']

Returns string or array depending the type of value you input.

License

MIT © Jamen Marz