8889841cindex.js000066600000004062150514436720006226 0ustar00'use strict'; const preserveCamelCase = string => { let isLastCharLower = false; let isLastCharUpper = false; let isLastLastCharUpper = false; for (let i = 0; i < string.length; i++) { const character = string[i]; if (isLastCharLower && /[a-zA-Z]/.test(character) && character.toUpperCase() === character) { string = string.slice(0, i) + '-' + string.slice(i); isLastCharLower = false; isLastLastCharUpper = isLastCharUpper; isLastCharUpper = true; i++; } else if (isLastCharUpper && isLastLastCharUpper && /[a-zA-Z]/.test(character) && character.toLowerCase() === character) { string = string.slice(0, i - 1) + '-' + string.slice(i - 1); isLastLastCharUpper = isLastCharUpper; isLastCharUpper = false; isLastCharLower = true; } else { isLastCharLower = character.toLowerCase() === character && character.toUpperCase() !== character; isLastLastCharUpper = isLastCharUpper; isLastCharUpper = character.toUpperCase() === character && character.toLowerCase() !== character; } } return string; }; const camelCase = (input, options) => { if (!(typeof input === 'string' || Array.isArray(input))) { throw new TypeError('Expected the input to be `string | string[]`'); } options = Object.assign({ pascalCase: false }, options); const postProcess = x => options.pascalCase ? x.charAt(0).toUpperCase() + x.slice(1) : x; if (Array.isArray(input)) { input = input.map(x => x.trim()) .filter(x => x.length) .join('-'); } else { input = input.trim(); } if (input.length === 0) { return ''; } if (input.length === 1) { return options.pascalCase ? input.toUpperCase() : input.toLowerCase(); } const hasUpperCase = input !== input.toLowerCase(); if (hasUpperCase) { input = preserveCamelCase(input); } input = input .replace(/^[_.\- ]+/, '') .toLowerCase() .replace(/[_.\- ]+(\w|$)/g, (_, p1) => p1.toUpperCase()) .replace(/\d+(\w|$)/g, m => m.toUpperCase()); return postProcess(input); }; module.exports = camelCase; // TODO: Remove this for the next major release module.exports.default = camelCase; readme.md000066600000004246150514436720006344 0ustar00# camelcase [![Build Status](https://travis-ci.org/sindresorhus/camelcase.svg?branch=master)](https://travis-ci.org/sindresorhus/camelcase) > Convert a dash/dot/underscore/space separated string to camelCase or PascalCase: `foo-bar` → `fooBar` ---
Get professional support for 'camelcase' with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
--- ## Install ``` $ npm install camelcase ``` ## Usage ```js const camelCase = require('camelcase'); camelCase('foo-bar'); //=> 'fooBar' camelCase('foo_bar'); //=> 'fooBar' camelCase('Foo-Bar'); //=> 'fooBar' camelCase('Foo-Bar', {pascalCase: true}); //=> 'FooBar' camelCase('--foo.bar', {pascalCase: false}); //=> 'fooBar' camelCase('foo bar'); //=> 'fooBar' console.log(process.argv[3]); //=> '--foo-bar' camelCase(process.argv[3]); //=> 'fooBar' camelCase(['foo', 'bar']); //=> 'fooBar' camelCase(['__foo__', '--bar'], {pascalCase: true}); //=> 'FooBar' ``` ## API ### camelCase(input, [options]) #### input Type: `string` `string[]` String to convert to camel case. #### options Type: `Object` ##### pascalCase Type: `boolean`
Default: `false` Uppercase the first character: `foo-bar` → `FooBar` ## Security To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. ## Related - [decamelize](https://github.com/sindresorhus/decamelize) - The inverse of this module - [uppercamelcase](https://github.com/SamVerschueren/uppercamelcase) - Like this module, but to PascalCase instead of camelCase - [titleize](https://github.com/sindresorhus/titleize) - Capitalize every word in string - [humanize-string](https://github.com/sindresorhus/humanize-string) - Convert a camelized/dasherized/underscored string into a humanized one ## License MIT © [Sindre Sorhus](https://sindresorhus.com) license000066600000002125150514436720006124 0ustar00MIT License Copyright (c) Sindre Sorhus (sindresorhus.com) 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. index.d.ts000066600000002400150514436720006454 0ustar00declare namespace camelcase { interface Options { /** Uppercase the first character: `foo-bar` → `FooBar`. @default false */ readonly pascalCase?: boolean; } } declare const camelcase: { /** Convert a dash/dot/underscore/space separated string to camelCase or PascalCase: `foo-bar` → `fooBar`. @param input - String to convert to camel case. @example ``` import camelCase = require('camelcase'); camelCase('foo-bar'); //=> 'fooBar' camelCase('foo_bar'); //=> 'fooBar' camelCase('Foo-Bar'); //=> 'fooBar' camelCase('Foo-Bar', {pascalCase: true}); //=> 'FooBar' camelCase('--foo.bar', {pascalCase: false}); //=> 'fooBar' camelCase('foo bar'); //=> 'fooBar' console.log(process.argv[3]); //=> '--foo-bar' camelCase(process.argv[3]); //=> 'fooBar' camelCase(['foo', 'bar']); //=> 'fooBar' camelCase(['__foo__', '--bar'], {pascalCase: true}); //=> 'FooBar' ``` */ (input: string | ReadonlyArray, options?: camelcase.Options): string; // TODO: Remove this for the next major release, refactor the whole definition to: // declare function camelcase( // input: string | ReadonlyArray, // options?: camelcase.Options // ): string; // export = camelcase; default: typeof camelcase; }; export = camelcase; package.json000066600000001352150514436720007046 0ustar00{ "name": "camelcase", "version": "5.3.1", "description": "Convert a dash/dot/underscore/space separated string to camelCase or PascalCase: `foo-bar` → `fooBar`", "license": "MIT", "repository": "sindresorhus/camelcase", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=6" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "camelcase", "camel-case", "camel", "case", "dash", "hyphen", "dot", "underscore", "separator", "string", "text", "convert", "pascalcase", "pascal-case" ], "devDependencies": { "ava": "^1.4.1", "tsd": "^0.7.1", "xo": "^0.24.0" } }