Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joakimbeng/kebab-case
Convert a string to kebab-case, i.e. its dash separated form
https://github.com/joakimbeng/kebab-case
Last synced: 21 days ago
JSON representation
Convert a string to kebab-case, i.e. its dash separated form
- Host: GitHub
- URL: https://github.com/joakimbeng/kebab-case
- Owner: joakimbeng
- License: mit
- Created: 2015-12-28T16:52:32.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2024-07-01T07:42:43.000Z (7 months ago)
- Last Synced: 2024-12-22T04:11:52.488Z (28 days ago)
- Language: JavaScript
- Size: 36.1 KB
- Stars: 23
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-github-star - kebab-case - case, i.e. its dash separated form | joakimbeng | 23 | (JavaScript)
README
# kebab-case
[![NPM version][npm-image]][npm-url]
> Convert a string to kebab-case, i.e. its dash separated form
The difference between `kebab-case` and e.g. [`dashify`](https://www.npmjs.com/package/dashify) is that this
module doesn't modify the string in any other way than transforming uppercased letters to their lowercased
counterparts prefixed with `-`. Thanks to this there's also a [`reverse`](#kebabcasereversestr) function to
do the opposite, i.e. get back the original value.This is used in [Unistyle](https://github.com/joakimbeng/unistyle) to transform JavaScript CSS properties
to their CSS counterparts without losing a possible browser prefix, e.g: `WebkitTransform -> -webkit-transform`.## Installation
Install `kebab-case` using [npm](https://www.npmjs.com/):
```bash
npm install --save kebab-case
```## Usage
### Module usage
```javascript
import kebabCase from "kebab-case";kebabCase("WebkitTransform");
// "-webkit-transform"
kebabCase.reverse("-webkit-transform");
// "WebkitTransform"
kebabCase("WebkitTransform", false);
// "webkit-transform"
```## API
### `kebabCase(str)`
| Name | Type | Description |
| --------------- | --------- | ----------------------------------------------------------- |
| str | `String` | The string to convert |
| keepLeadingDash | `Boolean` | Whether to keep the leading dash or not. Default is `true`. |Returns: `String`, the kebab cased string.
### `kebabCase.reverse(str)`
| Name | Type | Description |
| ---- | -------- | -------------------------- |
| str | `String` | The string to convert back |Returns: `String`, the "unkebab cased" string.
## License
MIT © [Joakim Carlstein](https://joakim.beng.se/)
[npm-url]: https://npmjs.org/package/kebab-case
[npm-image]: https://badge.fury.io/js/kebab-case.svg