You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
1.9 KiB

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