pax_global_header00006660000000000000000000000064141443054520014514gustar00rootroot0000000000000052 comment=a885785de8dc9eb3f5dba0c38de034ffdb68223f toidentifier-1.0.1/000077500000000000000000000000001414430545200142005ustar00rootroot00000000000000toidentifier-1.0.1/.editorconfig000066400000000000000000000002631414430545200166560ustar00rootroot00000000000000# 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.1/.eslintignore000066400000000000000000000000261414430545200167010ustar00rootroot00000000000000coverage node_modules toidentifier-1.0.1/.eslintrc.yml000066400000000000000000000002321414430545200166210ustar00rootroot00000000000000root: true extends: - standard - plugin:markdown/recommended plugins: - markdown overrides: - files: '**/*.md' processor: 'markdown/markdown' toidentifier-1.0.1/.gitattributes000066400000000000000000000000141414430545200170660ustar00rootroot00000000000000* text=auto toidentifier-1.0.1/.github/000077500000000000000000000000001414430545200155405ustar00rootroot00000000000000toidentifier-1.0.1/.github/workflows/000077500000000000000000000000001414430545200175755ustar00rootroot00000000000000toidentifier-1.0.1/.github/workflows/ci.yml000066400000000000000000000125361414430545200207220ustar00rootroot00000000000000name: ci on: - pull_request - push jobs: test: runs-on: ubuntu-18.04 strategy: matrix: name: - Node.js 0.6 - Node.js 0.8 - Node.js 0.10 - Node.js 0.12 - io.js 1.x - io.js 2.x - io.js 3.x - Node.js 4.x - Node.js 5.x - Node.js 6.x - Node.js 7.x - Node.js 8.x - Node.js 9.x - Node.js 10.x - Node.js 11.x - Node.js 12.x - Node.js 13.x - Node.js 14.x - Node.js 15.x - Node.js 16.x - Node.js 17.x include: - name: Node.js 0.6 node-version: "0.6" npm-i: mocha@1.21.5 npm-rm: nyc - name: Node.js 0.8 node-version: "0.8" npm-i: mocha@2.5.3 npm-rm: nyc - name: Node.js 0.10 node-version: "0.10" npm-i: mocha@3.5.3 npm-rm: nyc - name: Node.js 0.12 node-version: "0.12" npm-i: mocha@3.5.3 npm-rm: nyc - name: io.js 1.x node-version: "1.8" npm-i: mocha@3.5.3 npm-rm: nyc - name: io.js 2.x node-version: "2.5" npm-i: mocha@3.5.3 npm-rm: nyc - name: io.js 3.x node-version: "3.3" npm-i: mocha@3.5.3 npm-rm: nyc - name: Node.js 4.x node-version: "4.9" npm-i: mocha@5.2.0 npm-rm: nyc - name: Node.js 5.x node-version: "5.12" npm-i: mocha@5.2.0 npm-rm: nyc - name: Node.js 6.x node-version: "6.17" npm-i: mocha@6.2.3 npm-rm: nyc - name: Node.js 7.x node-version: "7.10" npm-i: mocha@6.2.3 npm-rm: nyc - name: Node.js 8.x node-version: "8.17" npm-i: mocha@7.2.0 - name: Node.js 9.x node-version: "9.11" npm-i: mocha@7.2.0 - name: Node.js 10.x node-version: "10.24" npm-i: mocha@8.4.0 - name: Node.js 11.x node-version: "11.15" npm-i: mocha@8.4.0 - name: Node.js 12.x node-version: "12.22" - name: Node.js 13.x node-version: "13.14" - name: Node.js 14.x node-version: "14.18" - name: Node.js 15.x node-version: "15.14" - name: Node.js 16.x node-version: "16.13" - name: Node.js 17.x node-version: "17.1" steps: - uses: actions/checkout@v2 - name: Install Node.js ${{ matrix.node-version }} shell: bash -eo pipefail -l {0} run: | if [[ "${{ matrix.node-version }}" == 0.6* ]]; then sudo apt-get install g++-4.8 gcc-4.8 libssl1.0-dev export CC=/usr/bin/gcc-4.8 export CXX=/usr/bin/g++-4.8 fi nvm install --default ${{ matrix.node-version }} if [[ "${{ matrix.node-version }}" == 0.* && "$(cut -d. -f2 <<< "${{ matrix.node-version }}")" -lt 10 ]]; then nvm install --alias=npm 0.10 nvm use ${{ matrix.node-version }} if [[ "$(npm -v)" == 1.1.* ]]; then nvm exec npm npm install -g npm@1.1 ln -fs "$(which npm)" "$(dirname "$(nvm which npm)")/npm" else sed -i '1s;^.*$;'"$(printf '#!%q' "$(nvm which npm)")"';' "$(readlink -f "$(which npm)")" fi npm config set strict-ssl false fi dirname "$(nvm which ${{ matrix.node-version }})" >> "$GITHUB_PATH" - name: Configure npm run: npm config set shrinkwrap false - name: Remove npm module(s) ${{ matrix.npm-rm }} run: npm rm --silent --save-dev ${{ matrix.npm-rm }} if: matrix.npm-rm != '' - name: Install npm module(s) ${{ matrix.npm-i }} run: npm install --save-dev ${{ matrix.npm-i }} if: matrix.npm-i != '' - name: Setup Node.js version-specific dependencies shell: bash run: | # eslint for linting # - remove on Node.js < 10 if [[ "$(cut -d. -f1 <<< "${{ matrix.node-version }}")" -lt 10 ]]; then node -pe 'Object.keys(require("./package").devDependencies).join("\n")' | \ grep -E '^eslint(-|$)' | \ sort -r | \ xargs -n1 npm rm --silent --save-dev fi - name: Install Node.js dependencies run: npm install - name: List environment id: list_env shell: bash run: | echo "node@$(node -v)" echo "npm@$(npm -v)" npm -s ls ||: (npm -s ls --depth=0 ||:) | awk -F'[ @]' 'NR>1 && $2 { print "::set-output name=" $2 "::" $3 }' - name: Run tests shell: bash run: | if npm -ps ls nyc | grep -q nyc; then npm run test-ci else npm test fi - name: Lint code if: steps.list_env.outputs.eslint != '' run: npm run lint - name: Collect code coverage uses: coverallsapp/github-action@master if: steps.list_env.outputs.nyc != '' with: github-token: ${{ secrets.GITHUB_TOKEN }} flag-name: run-${{ matrix.test_number }} parallel: true coverage: needs: test runs-on: ubuntu-latest steps: - name: Upload code coverage uses: coverallsapp/github-action@master with: github-token: ${{ secrets.github_token }} parallel-finished: true toidentifier-1.0.1/.gitignore000066400000000000000000000001301414430545200161620ustar00rootroot00000000000000.DS_Store *.log .idea node_modules coverage .nyc_output lib package-lock.json yarn.lock toidentifier-1.0.1/HISTORY.md000066400000000000000000000002001414430545200156530ustar00rootroot000000000000001.0.1 / 2021-11-14 ================== * pref: enable strict mode 1.0.0 / 2018-07-09 ================== * Initial release toidentifier-1.0.1/LICENSE000066400000000000000000000021241414430545200152040ustar00rootroot00000000000000MIT 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.1/README.md000066400000000000000000000034131414430545200154600ustar00rootroot00000000000000# toidentifier [![NPM Version][npm-image]][npm-url] [![NPM Downloads][downloads-image]][downloads-url] [![Build Status][github-actions-ci-image]][github-actions-ci-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 [github-actions-ci-image]: https://img.shields.io/github/workflow/status/component/toidentifier/ci/master?label=ci [github-actions-ci-url]: https://github.com/component/toidentifier?query=workflow%3Aci [npm-image]: https://img.shields.io/npm/v/toidentifier.svg [npm-url]: https://npmjs.org/package/toidentifier ## [npm]: https://www.npmjs.com/ [yarn]: https://yarnpkg.com/ toidentifier-1.0.1/index.js000066400000000000000000000007701414430545200156510ustar00rootroot00000000000000/*! * toidentifier * Copyright(c) 2016 Douglas Christopher Wilson * MIT Licensed */ 'use strict' /** * 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.1/package.json000066400000000000000000000021661414430545200164730ustar00rootroot00000000000000{ "name": "toidentifier", "description": "Convert a string of words to a JavaScript identifier", "version": "1.0.1", "author": "Douglas Christopher Wilson ", "contributors": [ "Douglas Christopher Wilson ", "Nick Baugh (http://niftylettuce.com/)" ], "repository": "component/toidentifier", "devDependencies": { "eslint": "7.32.0", "eslint-config-standard": "14.1.1", "eslint-plugin-import": "2.25.3", "eslint-plugin-markdown": "2.2.1", "eslint-plugin-node": "11.1.0", "eslint-plugin-promise": "4.3.1", "eslint-plugin-standard": "4.1.0", "mocha": "9.1.3", "nyc": "15.1.0" }, "engines": { "node": ">=0.6" }, "license": "MIT", "files": [ "HISTORY.md", "LICENSE", "index.js" ], "scripts": { "lint": "eslint .", "test": "mocha --reporter spec --bail --check-leaks test/", "test-ci": "nyc --reporter=lcov --reporter=text npm test", "test-cov": "nyc --reporter=html --reporter=text npm test", "version": "node scripts/version-history.js && git add HISTORY.md" } } toidentifier-1.0.1/scripts/000077500000000000000000000000001414430545200156675ustar00rootroot00000000000000toidentifier-1.0.1/scripts/version-history.js000066400000000000000000000027771414430545200214260ustar00rootroot00000000000000'use strict' var fs = require('fs') var path = require('path') var HISTORY_FILE_PATH = path.join(__dirname, '..', 'HISTORY.md') var MD_HEADER_REGEXP = /^====*$/ var VERSION = process.env.npm_package_version var VERSION_PLACEHOLDER_REGEXP = /^(?:unreleased|(\d+\.)+x)$/ var historyFileLines = fs.readFileSync(HISTORY_FILE_PATH, 'utf-8').split('\n') if (!MD_HEADER_REGEXP.test(historyFileLines[1])) { console.error('Missing header in HISTORY.md') process.exit(1) } if (!VERSION_PLACEHOLDER_REGEXP.test(historyFileLines[0])) { console.error('Missing placeholder version in HISTORY.md') process.exit(1) } if (historyFileLines[0].indexOf('x') !== -1) { var versionCheckRegExp = new RegExp('^' + historyFileLines[0].replace('x', '.+') + '$') if (!versionCheckRegExp.test(VERSION)) { console.error('Version %s does not match placeholder %s', VERSION, historyFileLines[0]) process.exit(1) } } historyFileLines[0] = VERSION + ' / ' + getLocaleDate() historyFileLines[1] = repeat('=', historyFileLines[0].length) fs.writeFileSync(HISTORY_FILE_PATH, historyFileLines.join('\n')) function getLocaleDate () { var now = new Date() return zeroPad(now.getFullYear(), 4) + '-' + zeroPad(now.getMonth() + 1, 2) + '-' + zeroPad(now.getDate(), 2) } function repeat (str, length) { var out = '' for (var i = 0; i < length; i++) { out += str } return out } function zeroPad (number, length) { var num = number.toString() while (num.length < length) { num = '0' + num } return num } toidentifier-1.0.1/test/000077500000000000000000000000001414430545200151575ustar00rootroot00000000000000toidentifier-1.0.1/test/.eslintrc.yml000066400000000000000000000000231414430545200175760ustar00rootroot00000000000000env: mocha: true toidentifier-1.0.1/test/index.js000066400000000000000000000011001414430545200166140ustar00rootroot00000000000000 var assert = require('assert') var toIdentifier = require('..') describe('toIdentifier', function () { it('should remove spaces', function () { assert.strictEqual(toIdentifier(' Foo Bar '), 'FooBar') }) it('should upper case first letter', function () { assert.strictEqual(toIdentifier('foo bar'), 'FooBar') }) it('should preserve case for ', function () { assert.strictEqual(toIdentifier('foo bar'), 'FooBar') }) it('should remove non-word characters', function () { assert.strictEqual(toIdentifier('f"o^o $ bar_z'), 'FooBar_z') }) })