Start sharing components as a team!Share components as a team!Join Bit to build your applications faster.Get Started Free

strip-unit

v3.2.0arrow_drop_down
v3.2.0
STATUS
Passing
DOWNLOADS
0
VISIBILITY
Public
PUBLISHED
8 months ago
SIZE
565 B
Returns a given CSS value minus its unit (or the original value if an invalid string is passed).
1 contributor
Use strip-unit in your project ?
Copied
npm i @bit/styled-components.polished.helpers.strip-unit
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.dev
Component Example
React
React
Vue
Angular
Add dependency... help_outline
Just
import
any of the 1 million components
and packages in Bit or NPM to the example.
import Button from '@bit/grommet.grommet.button';
import Lodash from 'lodash';
toggle layout
modifieddraft
chevron_left
chevron_right
helpers/stripUnit ()

Returns a given CSS value minus its unit (or the original value if an invalid string is passed). Optionally returns an array containing the stripped value and the original unit of measure.

Example
// Styles as object usage
const styles = {
  '--dimension': stripUnit('100px'),
  '--unit': stripUnit('100px')[1],
}

// styled-components usage
const div = styled.div`
  --dimension: ___CSS_0___;
  --unit: ___CSS_1___;
`

// CSS in JS Output

element {
  '--dimension': 100,
  '--unit': 'px',
}
Test Summary

should strip px from whole values

Pass

should strip px from values

Pass

should strip pt from whole values

Pass

should strip pt from values

Pass

should strip pc from whole values

Pass

should strip pc from values

Pass

should strip mm from whole values

Pass

should strip mm from values

Pass

should strip q from whole values

Pass

should strip q from values

Pass

should strip cm from whole values

Pass

should strip cm from values

Pass

should strip in from whole values

Pass

should strip in from values

Pass

should strip em from whole value

Pass

should strip em from decimal values

Pass

should strip rem from whole values

Pass

should strip rem from decimal values

Pass

should strip ex from whole values

Pass

should strip ex from decimal values

Pass

should strip ch from whole values

Pass

should strip ch from decimal values

Pass

should strip vh from whole values

Pass

should strip vh from decimal values

Pass

should strip vw from whole values

Pass

should strip vw from decimal values

Pass

should strip vmin from whole values

Pass

should strip vmin from decimal values

Pass

should strip vmax from whole values

Pass

should strip vmax from decimal values

Pass

should strip % from whole values

Pass

should strip % from decimal values

Pass

should return a unitless value when passed

Pass