[6a3a178] | 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 | ### `stylehacks.process(css, [options]).then(function(result) {})`
|
---|
| 56 |
|
---|
| 57 | #### options
|
---|
| 58 |
|
---|
| 59 | ##### lint
|
---|
| 60 |
|
---|
| 61 | Type: `boolean`
|
---|
| 62 | Default: `false`
|
---|
| 63 |
|
---|
| 64 | If lint mode is enabled, stylehacks will not remove hacks from the CSS; instead,
|
---|
| 65 | it will add warnings to `Result#messages`.
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 | ### `postcss([ stylehacks(opts) ])`
|
---|
| 69 |
|
---|
| 70 | stylehacks can also be consumed as a PostCSS plugin. See the
|
---|
| 71 | [documentation](https://github.com/postcss/postcss#usage) for examples for
|
---|
| 72 | your environment.
|
---|
| 73 |
|
---|
| 74 |
|
---|
| 75 | ## Related
|
---|
| 76 |
|
---|
| 77 | stylehacks works well with your existing PostCSS setup:
|
---|
| 78 |
|
---|
| 79 | * [stylelint] - Comprehensive & modern CSS linter, to ensure that your code
|
---|
| 80 | style rules are respected.
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 | ## Contributing
|
---|
| 84 |
|
---|
| 85 | Pull requests are welcome. If you add functionality, then please add unit tests
|
---|
| 86 | to cover it.
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 | ## License
|
---|
| 90 |
|
---|
| 91 | MIT © [Ben Briggs](http://beneb.info)
|
---|
| 92 |
|
---|
| 93 |
|
---|
| 94 | [stylelint]: https://github.com/stylelint/stylelint
|
---|