pax_global_header00006660000000000000000000000064133207027050014511gustar00rootroot0000000000000052 comment=8c09cba5e530de7d74b087ea66740c0e4a5af02b toidentifier-1.0.0/000077500000000000000000000000001332070270500141745ustar00rootroot00000000000000toidentifier-1.0.0/.editorconfig000066400000000000000000000002631332070270500166520ustar00rootroot00000000000000# http://editorconfig.org root = true [*] charset = utf-8 insert_final_newline = true trim_trailing_whitespace = true [{*.js,*.json,*.yml}] indent_size = 2 indent_style = space toidentifier-1.0.0/.eslintignore000066400000000000000000000000261332070270500166750ustar00rootroot00000000000000coverage node_modules toidentifier-1.0.0/.eslintrc.yml000066400000000000000000000000351332070270500166160ustar00rootroot00000000000000root: true extends: standard toidentifier-1.0.0/.gitattributes000066400000000000000000000000141332070270500170620ustar00rootroot00000000000000* text=auto toidentifier-1.0.0/.gitignore000066400000000000000000000001301332070270500161560ustar00rootroot00000000000000.DS_Store *.log .idea node_modules coverage .nyc_output lib package-lock.json yarn.lock toidentifier-1.0.0/.travis.yml000066400000000000000000000020621332070270500163050ustar00rootroot00000000000000language: node_js node_js: - '0.6' - '0.8' - '0.10' - '0.12' - '1.8' - '2.5' - '3.3' - '4.9' - '5.12' - '6.14' - '7.10' - '8.11' - '9.11' - '10.6' sudo: false dist: precise cache: directories: - node_modules before_install: # Skip updating shrinkwrap / lock - "npm config set shrinkwrap false" # Setup Node.js version-specific dependencies - "test $(echo $TRAVIS_NODE_VERSION | cut -d. -f1) -ge 4 || npm rm --save-dev nyc" - "test $(echo $TRAVIS_NODE_VERSION | cut -d. -f1) -ge 4 || npm rm --save-dev $(grep -E '\"eslint\\S*\"' package.json | cut -d'\"' -f2)" # Update Node.js modules - "test ! -d node_modules || npm prune" - "test ! -d node_modules || npm rebuild" script: # Run test script, depending on nyc install - "test ! -z $(npm -ps ls nyc) || npm test" - "test -z $(npm -ps ls nyc) || npm run-script test-cov" - "test -z $(npm -ps ls eslint) || npm run-script lint" after_success: - "test ! -z $(npm -ps ls nyc) && npm install codecov@2 && nyc report --reporter=text-lcov > coverage.lcov && codecov" toidentifier-1.0.0/LICENSE000066400000000000000000000021241332070270500152000ustar00rootroot00000000000000MIT License Copyright (c) 2016 Douglas Christopher Wilson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. toidentifier-1.0.0/README.md000066400000000000000000000032661332070270500154620ustar00rootroot00000000000000# toidentifier [![NPM Version][npm-image]][npm-url] [![NPM Downloads][downloads-image]][downloads-url] [![Build Status][travis-image]][travis-url] [![Test Coverage][codecov-image]][codecov-url] > Convert a string of words to a JavaScript identifier ## Install This is a [Node.js](https://nodejs.org/en/) module available through the [npm registry](https://www.npmjs.com/). Installation is done using the [`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally): ```bash $ npm install toidentifier ``` ## Example ```js var toIdentifier = require('toidentifier') console.log(toIdentifier('Bad Request')) // => "BadRequest" ``` ## API This CommonJS module exports a single default function: `toIdentifier`. ### toIdentifier(string) Given a string as the argument, it will be transformed according to the following rules and the new string will be returned: 1. Split into words separated by space characters (`0x20`). 2. Upper case the first character of each word. 3. Join the words together with no separator. 4. Remove all non-word (`[0-9a-z_]`) characters. ## License [MIT](LICENSE) [codecov-image]: https://img.shields.io/codecov/c/github/component/toidentifier.svg [codecov-url]: https://codecov.io/gh/component/toidentifier [downloads-image]: https://img.shields.io/npm/dm/toidentifier.svg [downloads-url]: https://npmjs.org/package/toidentifier [npm-image]: https://img.shields.io/npm/v/toidentifier.svg [npm-url]: https://npmjs.org/package/toidentifier [travis-image]: https://img.shields.io/travis/component/toidentifier/master.svg [travis-url]: https://travis-ci.org/component/toidentifier ## [npm]: https://www.npmjs.com/ [yarn]: https://yarnpkg.com/ toidentifier-1.0.0/index.js000066400000000000000000000007521332070270500156450ustar00rootroot00000000000000/*! * toidentifier * Copyright(c) 2016 Douglas Christopher Wilson * MIT Licensed */ /** * Module exports. * @public */ module.exports = toIdentifier /** * Trasform the given string into a JavaScript identifier * * @param {string} str * @returns {string} * @public */ function toIdentifier (str) { return str .split(' ') .map(function (token) { return token.slice(0, 1).toUpperCase() + token.slice(1) }) .join('') .replace(/[^ _0-9a-z]/gi, '') } toidentifier-1.0.0/package.json000066400000000000000000000017631332070270500164710ustar00rootroot00000000000000{ "name": "toidentifier", "description": "Convert a string of words to a JavaScript identifier", "version": "1.0.0", "author": "Douglas Christopher Wilson ", "contributors": [ "Douglas Christopher Wilson ", "Nick Baugh (http://niftylettuce.com/)" ], "repository": "component/toidentifier", "devDependencies": { "eslint": "4.19.1", "eslint-config-standard": "11.0.0", "eslint-plugin-import": "2.11.0", "eslint-plugin-markdown": "1.0.0-beta.6", "eslint-plugin-node": "6.0.1", "eslint-plugin-promise": "3.7.0", "eslint-plugin-standard": "3.1.0", "mocha": "1.21.5", "nyc": "11.8.0" }, "engines": { "node": ">=0.6" }, "license": "MIT", "files": [ "index.js" ], "scripts": { "lint": "eslint --plugin markdown --ext js,md .", "test": "mocha --reporter spec --bail --check-leaks test/", "test-cov": "nyc --reporter=html --reporter=text npm test" } } toidentifier-1.0.0/test/000077500000000000000000000000001332070270500151535ustar00rootroot00000000000000toidentifier-1.0.0/test/.eslintrc.yml000066400000000000000000000000231332070270500175720ustar00rootroot00000000000000env: mocha: true toidentifier-1.0.0/test/index.js000066400000000000000000000010501332070270500166140ustar00rootroot00000000000000 var assert = require('assert') var toIdentifier = require('..') describe('toIdentifier', function () { it('should remove spaces', function () { assert.equal(toIdentifier(' Foo Bar '), 'FooBar') }) it('should upper case first letter', function () { assert.equal(toIdentifier('foo bar'), 'FooBar') }) it('should preserve case for ', function () { assert.equal(toIdentifier('foo bar'), 'FooBar') }) it('should remove non-word characters', function () { assert.equal(toIdentifier('f"o^o $ bar_z'), 'FooBar_z') }) })