https://github.com/jamen/css-get-unit
Strip the unit off a CSS number.
https://github.com/jamen/css-get-unit
Last synced: 9 months ago
JSON representation
Strip the unit off a CSS number.
- Host: GitHub
- URL: https://github.com/jamen/css-get-unit
- Owner: jamen
- License: mit
- Created: 2016-08-30T22:17:25.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-02-06T07:29:08.000Z (over 9 years ago)
- Last Synced: 2024-04-26T15:21:13.407Z (about 2 years ago)
- Language: JavaScript
- Size: 13.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# css-get-unit [](https://npmjs.org/package/css-get-unit) [](https://travis-ci.org/jamen/css-get-unit)
> Get unit from a CSS value
```js
var unit = require('css-get-unit')
unit('1px')
// => 'px'
unit('30.5kHz')
// => 'kHz'
unit('auto')
// => null
```
This module gets unit from the CSS value without verifying. If there is no unit it will return `null`. To get the number instead, just use `parseFloat`:
```javascript
var value = '100px'
// User css-get-unit to get unit:
var unit = unit(value)
// => 'px'
// Use parseFloat to get number:
var number = parseFloat(value)
// => 100
```
## Installation
```sh
$ npm install --save css-get-unit
```
## Usage
### `unit(value)`
- `value` (`String`): CSS value to get the unit from
```javascript
unit('2px')
// => 'px'
unit('.5ms')
// => 'ms'
unit('100')
// => null
```
## License
MIT © [Jamen Marz](https://github.com/jamen)