1 | # toidentifier
|
---|
2 |
|
---|
3 | [![NPM Version][npm-image]][npm-url]
|
---|
4 | [![NPM Downloads][downloads-image]][downloads-url]
|
---|
5 | [![Build Status][travis-image]][travis-url]
|
---|
6 | [![Test Coverage][codecov-image]][codecov-url]
|
---|
7 |
|
---|
8 | > Convert a string of words to a JavaScript identifier
|
---|
9 |
|
---|
10 | ## Install
|
---|
11 |
|
---|
12 | This is a [Node.js](https://nodejs.org/en/) module available through the
|
---|
13 | [npm registry](https://www.npmjs.com/). Installation is done using the
|
---|
14 | [`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
|
---|
15 |
|
---|
16 | ```bash
|
---|
17 | $ npm install toidentifier
|
---|
18 | ```
|
---|
19 |
|
---|
20 | ## Example
|
---|
21 |
|
---|
22 | ```js
|
---|
23 | var toIdentifier = require('toidentifier')
|
---|
24 |
|
---|
25 | console.log(toIdentifier('Bad Request'))
|
---|
26 | // => "BadRequest"
|
---|
27 | ```
|
---|
28 |
|
---|
29 | ## API
|
---|
30 |
|
---|
31 | This CommonJS module exports a single default function: `toIdentifier`.
|
---|
32 |
|
---|
33 | ### toIdentifier(string)
|
---|
34 |
|
---|
35 | Given a string as the argument, it will be transformed according to
|
---|
36 | the following rules and the new string will be returned:
|
---|
37 |
|
---|
38 | 1. Split into words separated by space characters (`0x20`).
|
---|
39 | 2. Upper case the first character of each word.
|
---|
40 | 3. Join the words together with no separator.
|
---|
41 | 4. Remove all non-word (`[0-9a-z_]`) characters.
|
---|
42 |
|
---|
43 | ## License
|
---|
44 |
|
---|
45 | [MIT](LICENSE)
|
---|
46 |
|
---|
47 | [codecov-image]: https://img.shields.io/codecov/c/github/component/toidentifier.svg
|
---|
48 | [codecov-url]: https://codecov.io/gh/component/toidentifier
|
---|
49 | [downloads-image]: https://img.shields.io/npm/dm/toidentifier.svg
|
---|
50 | [downloads-url]: https://npmjs.org/package/toidentifier
|
---|
51 | [npm-image]: https://img.shields.io/npm/v/toidentifier.svg
|
---|
52 | [npm-url]: https://npmjs.org/package/toidentifier
|
---|
53 | [travis-image]: https://img.shields.io/travis/component/toidentifier/master.svg
|
---|
54 | [travis-url]: https://travis-ci.org/component/toidentifier
|
---|
55 |
|
---|
56 |
|
---|
57 | ##
|
---|
58 |
|
---|
59 | [npm]: https://www.npmjs.com/
|
---|
60 |
|
---|
61 | [yarn]: https://yarnpkg.com/
|
---|