f90b2d5c3c3dc7814e9d52459f01cc71b87b602cbe8f076c6a0a509c9fbf5cdf5098f82c98a2ece32c7cf33549d7a2a09b99223264c158140caea1f76562a3 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # [postcss][postcss]-convert-values [![Build Status](https://travis-ci.org/ben-eb/postcss-convert-values.svg?branch=master)][ci] [![NPM version](https://badge.fury.io/js/postcss-convert-values.svg)][npm] [![Dependency Status](https://gemnasium.com/ben-eb/postcss-convert-values.svg)][deps]
  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. ## Contributors
  53. Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
  54. <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
  55. | [<img src="https://avatars.githubusercontent.com/u/1282980?v=3" width="100px;"/><br /><sub>Ben Briggs</sub>](http://beneb.info)<br />[💻](https://github.com/ben-eb/postcss-convert-values/commits?author=ben-eb) [📖](https://github.com/ben-eb/postcss-convert-values/commits?author=ben-eb) 👀 [⚠️](https://github.com/ben-eb/postcss-convert-values/commits?author=ben-eb) | [<img src="https://avatars.githubusercontent.com/u/5635476?v=3" width="100px;"/><br /><sub>Bogdan Chadkin</sub>](https://github.com/TrySound)<br />[💻](https://github.com/ben-eb/postcss-convert-values/commits?author=TrySound) [📖](https://github.com/ben-eb/postcss-convert-values/commits?author=TrySound) 👀 [⚠️](https://github.com/ben-eb/postcss-convert-values/commits?author=TrySound) | [<img src="https://avatars.githubusercontent.com/u/177485?v=3" width="100px;"/><br /><sub>Roman Komarov</sub>](http://kizu.ru/en/)<br />[🐛](https://github.com/ben-eb/postcss-convert-values/issues?q=author%3Akizu) | [<img src="https://avatars.githubusercontent.com/u/5103477?v=3" width="100px;"/><br /><sub>Dmitry Kiselyov</sub>](http://codepen.io/dmitrykiselyov)<br />[🐛](https://github.com/ben-eb/postcss-convert-values/issues?q=author%3Admitrykiselyov) | [<img src="https://avatars.githubusercontent.com/u/5038030?v=3" width="100px;"/><br /><sub>Charlike Mike Reagent</sub>](http://www.tunnckocore.tk)<br />[💻](https://github.com/ben-eb/postcss-convert-values/commits?author=tunnckoCore) [⚠️](https://github.com/ben-eb/postcss-convert-values/commits?author=tunnckoCore) | [<img src="https://avatars.githubusercontent.com/u/815848?v=3" width="100px;"/><br /><sub>Vyacheslav Shebanov</sub>](https://github.com/Termina1)<br />[📖](https://github.com/ben-eb/postcss-convert-values/commits?author=Termina1) | [<img src="https://avatars.githubusercontent.com/u/192323?v=3" width="100px;"/><br /><sub>Marek ‘saji’ Augustynowicz</sub>](http://twitter.com/saji_)<br />[💻](https://github.com/ben-eb/postcss-convert-values/commits?author=marek-saji) [⚠️](https://github.com/ben-eb/postcss-convert-values/commits?author=marek-saji) |
  56. | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
  57. | [<img src="https://avatars.githubusercontent.com/u/552316?v=3" width="100px;"/><br /><sub>Jonny Gerig Meyer</sub>](www.oddbird.net)<br />[💻](https://github.com/ben-eb/postcss-convert-values/commits?author=jgerigmeyer) [⚠️](https://github.com/ben-eb/postcss-convert-values/commits?author=jgerigmeyer) | [<img src="https://avatars.githubusercontent.com/u/1726061?v=3" width="100px;"/><br /><sub>GU Yiling</sub>](http://lync.in/)<br />[💻](https://github.com/ben-eb/postcss-convert-values/commits?author=Justineo) [⚠️](https://github.com/ben-eb/postcss-convert-values/commits?author=Justineo) |
  58. <!-- ALL-CONTRIBUTORS-LIST:END -->
  59. This project follows the [all-contributors] specification. Contributions of
  60. any kind welcome!
  61. ## License
  62. MIT © [Ben Briggs](http://beneb.info)
  63. [all-contributors]: https://github.com/kentcdodds/all-contributors
  64. [ci]: https://travis-ci.org/ben-eb/postcss-convert-values
  65. [colormin]: https://github.com/ben-eb/postcss-colormin
  66. [deps]: https://gemnasium.com/ben-eb/postcss-convert-values
  67. [npm]: http://badge.fury.io/js/postcss-convert-values
  68. [postcss]: https://github.com/postcss/postcss
  69. [csstricks]: https://css-tricks.com/the-lengths-of-css/