You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.7 KiB

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