|
1 | | -# css-in-js-utils |
2 | | -Useful utility functions for CSS in JS solutions |
| 1 | +# CSS-in-JS Utilities |
| 2 | +A library that provides useful utilities functions for CSS-in-JS solutions.<br> |
| 3 | +They are intended to be used by CSS-in-JS library authors rather used directly. |
| 4 | +<br> |
| 5 | +<img alt="TravisCI" src="https://travis-ci.org/rofrischmann/css-in-js-utils.svg?branch=master"> |
| 6 | +<a href="https://codeclimate.com/github/rofrischmann/css-in-js-utils/coverage"><img alt="Test Coverage" src="https://codeclimate.com/github/rofrischmann/css-in-js-utils/badges/coverage.svg"></a> |
| 7 | +<img alt="npm downloads" src="https://img.shields.io/npm/dm/css-in-js-utils.svg"> |
| 8 | +<img alt="npm version" src="https://badge.fury.io/js/css-in-js-utils.svg"> |
| 9 | + |
| 10 | +## Installation |
| 11 | +```sh |
| 12 | +yarn add css-in-js-utils |
| 13 | +``` |
| 14 | + |
| 15 | +## Utilities |
| 16 | +* [`camelCaseProperty(property)`](#camelcasepropertyproperty) |
| 17 | +* [`hyphenateProperty(property)`](#hyphenatepropertyproperty) |
| 18 | +* [`isPrefixedProperty(property)`](#isprefixedpropertyproperty) |
| 19 | +* [`isPrefixedValue(value)`](#isprefixedvaluevalue) |
| 20 | +* [`isUnitlessProperty(property)`](#isunitlessproperty) |
| 21 | +* [`normalizeProperty(property)`](#normalizepropertyproperty) |
| 22 | +* [`unprefixProperty(property)`](#unprefixpropertyproperty) |
| 23 | +* [`unprefixValue(value)`](#unprefixvaluevalue) |
| 24 | + |
| 25 | +------ |
| 26 | + |
| 27 | +### `camelCaseProperty(property)` |
| 28 | +Converts the `property` to camelCase. |
| 29 | + |
| 30 | +```javascript |
| 31 | +import { camelCaseProperty } from 'css-in-js-utils' |
| 32 | + |
| 33 | +console.log(camelCaseProperty('padding-top')) |
| 34 | +// => 'paddingTop' |
| 35 | + |
| 36 | +console.log(camelCaseProperty('-webkit-transition')) |
| 37 | +// => 'WebkitTransition' |
| 38 | +``` |
| 39 | + |
| 40 | +------ |
| 41 | + |
| 42 | +### `hyphenateProperty(property)` |
| 43 | +Converts the `property` to hyphen-case. |
| 44 | +> Directly mirrors [hyphenate-style-name](https://github.com/rexxars/hyphenate-style-name). |
| 45 | +
|
| 46 | +```javascript |
| 47 | +import { hyphenateProperty } from 'css-in-js-utils' |
| 48 | + |
| 49 | +console.log(hyphenateProperty('paddingTop')) |
| 50 | +// => 'padding-top' |
| 51 | + |
| 52 | +console.log(hyphenateProperty('WebkitTransition')) |
| 53 | +// => '-webkit-transition' |
| 54 | +``` |
| 55 | + |
| 56 | +------ |
| 57 | + |
| 58 | +### `isPrefixedProperty(property)` |
| 59 | +Checks if a `property` includes a vendor prefix. |
| 60 | + |
| 61 | +```javascript |
| 62 | +import { isPrefixedProperty } from 'css-in-js-utils' |
| 63 | + |
| 64 | +console.log(isPrefixedProperty('paddingTop')) |
| 65 | +// => false |
| 66 | + |
| 67 | +console.log(isPrefixedProperty('WebkitTransition')) |
| 68 | +// => true |
| 69 | +``` |
| 70 | + |
| 71 | +------ |
| 72 | +### `isPrefixedValue(value)` |
| 73 | +Checks if a `value` includes vendor prefixes. |
| 74 | + |
| 75 | +```javascript |
| 76 | +import { isPrefixedValue } from 'css-in-js-utils' |
| 77 | + |
| 78 | +console.log(isPrefixedValue('200px')) |
| 79 | +console.log(isPrefixedValue(200)) |
| 80 | +// => false |
| 81 | + |
| 82 | +console.log(isPrefixedValue('-webkit-calc(100% - 50px)')) |
| 83 | +// => true |
| 84 | +``` |
| 85 | + |
| 86 | +------ |
| 87 | + |
| 88 | +### `isUnitlessProperty(property)` |
| 89 | +Checks if a `property` accepts unitless values. |
| 90 | +> Directly mirrors [unitless-css-property](https://github.com/rofrischmann/unitless-css-property). |
| 91 | +
|
| 92 | +```javascript |
| 93 | +import { isUnitlessProperty } from 'css-in-js-utils' |
| 94 | + |
| 95 | +console.log(isUnitlessProperty('width')) |
| 96 | +// => false |
| 97 | + |
| 98 | +console.log(isUnitlessProperty('flexGrow')) |
| 99 | +console.log(isUnitlessProperty('lineHeight')) |
| 100 | +// => true |
| 101 | +``` |
| 102 | + |
| 103 | +### `normalizeProperty(property)` |
| 104 | +Normalizes the `property` by unprefixing **and** camelCasing it. |
| 105 | +> Uses the [`camelCaseProperty`](#camelcasepropertyproperty) and [`unprefixProperty`](#unprefixpropertyproperty)-methods. |
| 106 | +
|
| 107 | +```javascript |
| 108 | +import { normalizeProperty } from 'css-in-js-utils' |
| 109 | + |
| 110 | +console.log(normalizeProperty('-webkit-transition-delay')) |
| 111 | +// => 'transitionDelay' |
| 112 | +``` |
| 113 | + |
| 114 | +### `unprefixProperty(property)` |
| 115 | +Removes the vendor prefix (if set) from the `property`. |
| 116 | + |
| 117 | +```javascript |
| 118 | +import { unprefixProperty } from 'css-in-js-utils' |
| 119 | + |
| 120 | +console.log(unprefixProperty('WebkitTransition')) |
| 121 | +// => 'transition' |
| 122 | + |
| 123 | +console.log(unprefixProperty('transitionDelay')) |
| 124 | +// => 'transitionDelay' |
| 125 | +``` |
| 126 | + |
| 127 | +### `unprefixValue(value)` |
| 128 | +Removes all vendor prefixes (if any) from the `value`. |
| 129 | + |
| 130 | +```javascript |
| 131 | +import { unprefixValue } from 'css-in-js-utils' |
| 132 | + |
| 133 | +console.log(unprefixValue('-webkit-calc(-moz-calc(100% - 50px)/2)')) |
| 134 | +// => 'calc(calc(100% - 50px)/2)' |
| 135 | + |
| 136 | +console.log(unprefixValue('100px')) |
| 137 | +// => '100px' |
| 138 | +``` |
| 139 | + |
| 140 | +## Direct Import |
| 141 | +Every utility function may be imported directly to save bundle size. |
| 142 | + |
| 143 | +```javascript |
| 144 | +import camelCaseProperty from 'css-in-js-utils/lib/camelCaseProperty' |
| 145 | +``` |
| 146 | + |
| 147 | +## License |
| 148 | +css-in-js-utils is licensed under the [MIT License](http://opensource.org/licenses/MIT).<br> |
| 149 | +Documentation is licensed under [Creative Common License](http://creativecommons.org/licenses/by/4.0/).<br> |
| 150 | +Created with ♥ by [@rofrischmann](http://rofrischmann.de). |
0 commit comments