[6a3a178] | 1 | # [postcss][postcss]-convert-values
|
---|
| 2 |
|
---|
| 3 | > Convert values with PostCSS (e.g. ms -> s)
|
---|
| 4 |
|
---|
| 5 | ## Install
|
---|
| 6 |
|
---|
| 7 | With [npm](https://npmjs.org/package/postcss-convert-values) do:
|
---|
| 8 |
|
---|
| 9 | ```
|
---|
| 10 | npm install postcss-convert-values --save
|
---|
| 11 | ```
|
---|
| 12 |
|
---|
| 13 | ## Example
|
---|
| 14 |
|
---|
| 15 | This plugin reduces CSS size by converting values to use different units
|
---|
| 16 | where possible; for example, `500ms` can be represented as `.5s`. You can
|
---|
| 17 | read more about these units in [this article][csstricks].
|
---|
| 18 |
|
---|
| 19 | ### Input
|
---|
| 20 |
|
---|
| 21 | ```css
|
---|
| 22 | h1 {
|
---|
| 23 | font-size: 16px;
|
---|
| 24 | width: 0em
|
---|
| 25 | }
|
---|
| 26 | ```
|
---|
| 27 |
|
---|
| 28 | ### Output
|
---|
| 29 |
|
---|
| 30 | ```css
|
---|
| 31 | h1 {
|
---|
| 32 | font-size: 1pc;
|
---|
| 33 | width: 0
|
---|
| 34 | }
|
---|
| 35 | ```
|
---|
| 36 |
|
---|
| 37 | Note that this plugin only covers conversions for duration and absolute length
|
---|
| 38 | values. For color conversions, use [postcss-colormin][colormin].
|
---|
| 39 |
|
---|
| 40 | ## API
|
---|
| 41 |
|
---|
| 42 | ### convertValues([options])
|
---|
| 43 |
|
---|
| 44 | #### options
|
---|
| 45 |
|
---|
| 46 | ##### length
|
---|
| 47 |
|
---|
| 48 | Type: `boolean`
|
---|
| 49 | Default: `true`
|
---|
| 50 |
|
---|
| 51 | Pass `false` to disable conversion from `px` to other absolute length units,
|
---|
| 52 | such as `pc` & `pt` & vice versa.
|
---|
| 53 |
|
---|
| 54 | ##### time
|
---|
| 55 |
|
---|
| 56 | Type: `boolean`
|
---|
| 57 | Default: `true`
|
---|
| 58 |
|
---|
| 59 | Pass `false` to disable conversion from `ms` to `s` & vice versa.
|
---|
| 60 |
|
---|
| 61 | ##### angle
|
---|
| 62 |
|
---|
| 63 | Type: `boolean`
|
---|
| 64 | Default: `true`
|
---|
| 65 |
|
---|
| 66 | Pass `false` to disable conversion from `deg` to `turn` & vice versa.
|
---|
| 67 |
|
---|
| 68 | ##### precision
|
---|
| 69 |
|
---|
| 70 | Type: `boolean|number`
|
---|
| 71 | Default: `false`
|
---|
| 72 |
|
---|
| 73 | Specify any numeric value here to round `px` values to that many decimal places;
|
---|
| 74 | for example, using `{precision: 2}` will round `6.66667px` to `6.67px`, and
|
---|
| 75 | `{precision: 0}` will round it to `7px`. Passing `false` (the default) will
|
---|
| 76 | leave these values as is.
|
---|
| 77 |
|
---|
| 78 | It is recommended for most use cases to set this option to `2`.
|
---|
| 79 |
|
---|
| 80 |
|
---|
| 81 | ## Usage
|
---|
| 82 |
|
---|
| 83 | See the [PostCSS documentation](https://github.com/postcss/postcss#usage) for
|
---|
| 84 | examples for your environment.
|
---|
| 85 |
|
---|
| 86 |
|
---|
| 87 | ## Contributors
|
---|
| 88 |
|
---|
| 89 | See [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).
|
---|
| 90 |
|
---|
| 91 |
|
---|
| 92 | ## License
|
---|
| 93 |
|
---|
| 94 | MIT © [Ben Briggs](http://beneb.info)
|
---|
| 95 |
|
---|
| 96 |
|
---|
| 97 | [postcss]: https://github.com/postcss/postcss
|
---|
| 98 | [csstricks]: https://css-tricks.com/the-lengths-of-css/
|
---|