| 1 | # stylehacks
|
|---|
| 2 |
|
|---|
| 3 | > Detect/remove browser hacks from CSS files.
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 | ## Install
|
|---|
| 7 |
|
|---|
| 8 | With [npm](https://npmjs.org/package/stylehacks) do:
|
|---|
| 9 |
|
|---|
| 10 | ```
|
|---|
| 11 | npm install stylehacks --save
|
|---|
| 12 | ```
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 | ## Example
|
|---|
| 16 |
|
|---|
| 17 | In its default mode, stylehacks will remove hacks from your CSS file, based on
|
|---|
| 18 | the browsers that you wish to support.
|
|---|
| 19 |
|
|---|
| 20 | ### Input
|
|---|
| 21 |
|
|---|
| 22 | ```css
|
|---|
| 23 | h1 {
|
|---|
| 24 | _color: white;
|
|---|
| 25 | color: rgba(255, 255, 255, 0.5);
|
|---|
| 26 | }
|
|---|
| 27 | ```
|
|---|
| 28 |
|
|---|
| 29 | ### Output
|
|---|
| 30 |
|
|---|
| 31 | ```css
|
|---|
| 32 | h1 {
|
|---|
| 33 | color: rgba(255, 255, 255, 0.5);
|
|---|
| 34 | }
|
|---|
| 35 | ```
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 | ## API
|
|---|
| 39 |
|
|---|
| 40 | ### `stylehacks.detect(node)`
|
|---|
| 41 |
|
|---|
| 42 | Type: `function`
|
|---|
| 43 | Returns: `boolean`
|
|---|
| 44 |
|
|---|
| 45 | This method will take any PostCSS *node*, run applicable plugins depending on
|
|---|
| 46 | its type, then will return a boolean depending on whether it found any of
|
|---|
| 47 | the supported hacks. For example, if the `decl` node found below is passed to
|
|---|
| 48 | the `detect` function, it will return `true`. But if the `rule` node is passed,
|
|---|
| 49 | it will return `false` instead.
|
|---|
| 50 |
|
|---|
| 51 | ```css
|
|---|
| 52 | h1 { _color: red }
|
|---|
| 53 | ```
|
|---|
| 54 |
|
|---|
| 55 | ### `postcss([ stylehacks(opts) ])`
|
|---|
| 56 |
|
|---|
| 57 | stylehacks can also be consumed as a PostCSS plugin. See the
|
|---|
| 58 | [documentation](https://github.com/postcss/postcss#usage) for examples for
|
|---|
| 59 | your environment.
|
|---|
| 60 |
|
|---|
| 61 | #### options
|
|---|
| 62 |
|
|---|
| 63 | ##### lint
|
|---|
| 64 |
|
|---|
| 65 | Type: `boolean`
|
|---|
| 66 | Default: `false`
|
|---|
| 67 |
|
|---|
| 68 | If lint mode is enabled, stylehacks will not remove hacks from the CSS; instead,
|
|---|
| 69 | it will add warnings to `Result#messages`.
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 | ## Related
|
|---|
| 73 |
|
|---|
| 74 | stylehacks works well with your existing PostCSS setup:
|
|---|
| 75 |
|
|---|
| 76 | * [stylelint] - Comprehensive & modern CSS linter, to ensure that your code
|
|---|
| 77 | style rules are respected.
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 | ## Contributing
|
|---|
| 81 |
|
|---|
| 82 | Pull requests are welcome. If you add functionality, then please add unit tests
|
|---|
| 83 | to cover it.
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 | ## License
|
|---|
| 87 |
|
|---|
| 88 | MIT © [Ben Briggs](http://beneb.info)
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 | [stylelint]: https://github.com/stylelint/stylelint
|
|---|