pax_global_header00006660000000000000000000000064142473056260014523gustar00rootroot0000000000000052 comment=6f5439a78b523b157b55546b26bdc5e14cd2b923 camelcase-7.0.0/000077500000000000000000000000001424730562600134445ustar00rootroot00000000000000camelcase-7.0.0/.editorconfig000066400000000000000000000002571424730562600161250ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 camelcase-7.0.0/.gitattributes000066400000000000000000000000231424730562600163320ustar00rootroot00000000000000* text=auto eol=lf camelcase-7.0.0/.github/000077500000000000000000000000001424730562600150045ustar00rootroot00000000000000camelcase-7.0.0/.github/funding.yml000066400000000000000000000001631424730562600171610ustar00rootroot00000000000000github: sindresorhus open_collective: sindresorhus tidelift: npm/camelcase custom: https://sindresorhus.com/donate camelcase-7.0.0/.github/security.md000066400000000000000000000002631424730562600171760ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. camelcase-7.0.0/.github/workflows/000077500000000000000000000000001424730562600170415ustar00rootroot00000000000000camelcase-7.0.0/.github/workflows/main.yml000066400000000000000000000006641424730562600205160ustar00rootroot00000000000000name: CI on: - push - pull_request jobs: test: name: Node.js ${{ matrix.node-version }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: node-version: - 18 - 16 - 14 steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} - run: npm install - run: npm test camelcase-7.0.0/.gitignore000066400000000000000000000000271424730562600154330ustar00rootroot00000000000000node_modules yarn.lock camelcase-7.0.0/.npmrc000066400000000000000000000000231424730562600145570ustar00rootroot00000000000000package-lock=false camelcase-7.0.0/index.d.ts000066400000000000000000000046211424730562600153500ustar00rootroot00000000000000export type Options = { /** Uppercase the first character: `foo-bar` → `FooBar`. @default false */ readonly pascalCase?: boolean; /** Preserve consecutive uppercase characters: `foo-BAR` → `FooBAR`. @default false */ readonly preserveConsecutiveUppercase?: boolean; /** The locale parameter indicates the locale to be used to convert to upper/lower case according to any locale-specific case mappings. If multiple locales are given in an array, the best available locale is used. Setting `locale: false` ignores the platform locale and uses the [Unicode Default Case Conversion](https://unicode-org.github.io/icu/userguide/transforms/casemappings.html#simple-single-character-case-mapping) algorithm. Default: The host environment’s current locale. @example ``` import camelCase from 'camelcase'; camelCase('lorem-ipsum', {locale: 'en-US'}); //=> 'loremIpsum' camelCase('lorem-ipsum', {locale: 'tr-TR'}); //=> 'loremİpsum' camelCase('lorem-ipsum', {locale: ['en-US', 'en-GB']}); //=> 'loremIpsum' camelCase('lorem-ipsum', {locale: ['tr', 'TR', 'tr-TR']}); //=> 'loremİpsum' ``` */ readonly locale?: false | string | readonly string[]; }; /** Convert a dash/dot/underscore/space separated string to camelCase or PascalCase: `foo-bar` → `fooBar`. Correctly handles Unicode strings. @param input - String to convert to camel case. @example ``` import camelCase from 'camelcase'; camelCase('foo-bar'); //=> 'fooBar' camelCase('foo_bar'); //=> 'fooBar' camelCase('Foo-Bar'); //=> 'fooBar' camelCase('розовый_пушистый_единорог'); //=> 'розовыйПушистыйЕдинорог' camelCase('Foo-Bar', {pascalCase: true}); //=> 'FooBar' camelCase('--foo.bar', {pascalCase: false}); //=> 'fooBar' camelCase('Foo-BAR', {preserveConsecutiveUppercase: true}); //=> 'fooBAR' camelCase('fooBAR', {pascalCase: true, preserveConsecutiveUppercase: true})); //=> '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' camelCase(['foo', 'BAR'], {pascalCase: true, preserveConsecutiveUppercase: true}) //=> 'FooBAR' camelCase('lorem-ipsum', {locale: 'en-US'}); //=> 'loremIpsum' ``` */ export default function camelcase( input: string | readonly string[], options?: Options ): string; camelcase-7.0.0/index.js000066400000000000000000000062161424730562600151160ustar00rootroot00000000000000const UPPERCASE = /[\p{Lu}]/u; const LOWERCASE = /[\p{Ll}]/u; const LEADING_CAPITAL = /^[\p{Lu}](?![\p{Lu}])/gu; const IDENTIFIER = /([\p{Alpha}\p{N}_]|$)/u; const SEPARATORS = /[_.\- ]+/; const LEADING_SEPARATORS = new RegExp('^' + SEPARATORS.source); const SEPARATORS_AND_IDENTIFIER = new RegExp(SEPARATORS.source + IDENTIFIER.source, 'gu'); const NUMBERS_AND_IDENTIFIER = new RegExp('\\d+' + IDENTIFIER.source, 'gu'); const preserveCamelCase = (string, toLowerCase, toUpperCase) => { let isLastCharLower = false; let isLastCharUpper = false; let isLastLastCharUpper = false; for (let index = 0; index < string.length; index++) { const character = string[index]; if (isLastCharLower && UPPERCASE.test(character)) { string = string.slice(0, index) + '-' + string.slice(index); isLastCharLower = false; isLastLastCharUpper = isLastCharUpper; isLastCharUpper = true; index++; } else if (isLastCharUpper && isLastLastCharUpper && LOWERCASE.test(character)) { string = string.slice(0, index - 1) + '-' + string.slice(index - 1); isLastLastCharUpper = isLastCharUpper; isLastCharUpper = false; isLastCharLower = true; } else { isLastCharLower = toLowerCase(character) === character && toUpperCase(character) !== character; isLastLastCharUpper = isLastCharUpper; isLastCharUpper = toUpperCase(character) === character && toLowerCase(character) !== character; } } return string; }; const preserveConsecutiveUppercase = (input, toLowerCase) => { LEADING_CAPITAL.lastIndex = 0; return input.replace(LEADING_CAPITAL, m1 => toLowerCase(m1)); }; const postProcess = (input, toUpperCase) => { SEPARATORS_AND_IDENTIFIER.lastIndex = 0; NUMBERS_AND_IDENTIFIER.lastIndex = 0; return input.replace(SEPARATORS_AND_IDENTIFIER, (_, identifier) => toUpperCase(identifier)) .replace(NUMBERS_AND_IDENTIFIER, m => toUpperCase(m)); }; export default function camelCase(input, options) { if (!(typeof input === 'string' || Array.isArray(input))) { throw new TypeError('Expected the input to be `string | string[]`'); } options = { pascalCase: false, preserveConsecutiveUppercase: false, ...options, }; if (Array.isArray(input)) { input = input.map(x => x.trim()) .filter(x => x.length) .join('-'); } else { input = input.trim(); } if (input.length === 0) { return ''; } const toLowerCase = options.locale === false ? string => string.toLowerCase() : string => string.toLocaleLowerCase(options.locale); const toUpperCase = options.locale === false ? string => string.toUpperCase() : string => string.toLocaleUpperCase(options.locale); if (input.length === 1) { if (SEPARATORS.test(input)) { return ''; } return options.pascalCase ? toUpperCase(input) : toLowerCase(input); } const hasUpperCase = input !== toLowerCase(input); if (hasUpperCase) { input = preserveCamelCase(input, toLowerCase, toUpperCase); } input = input.replace(LEADING_SEPARATORS, ''); input = options.preserveConsecutiveUppercase ? preserveConsecutiveUppercase(input, toLowerCase) : toLowerCase(input); if (options.pascalCase) { input = toUpperCase(input.charAt(0)) + input.slice(1); } return postProcess(input, toUpperCase); } camelcase-7.0.0/index.test-d.ts000066400000000000000000000012541424730562600163240ustar00rootroot00000000000000import {expectType} from 'tsd'; import camelCase from './index.js'; expectType(camelCase('foo-bar')); expectType(camelCase('розовый_пушистый_единороги')); expectType(camelCase('Foo-Bar', {locale: ['tr']})); expectType(camelCase('Foo-Bar', {locale: ['tr', 'TR', 'tr-TR']})); expectType(camelCase('Foo-Bar', {pascalCase: true, locale: ['tr']})); expectType(camelCase('Foo-Bar', {pascalCase: true, locale: ['tr', 'TR', 'tr-TR']})); expectType(camelCase('Foo-Bar', {pascalCase: true})); expectType(camelCase(['foo', 'bar'])); expectType(camelCase(['__foo__', '--bar'], {pascalCase: true})); camelcase-7.0.0/license000066400000000000000000000021351424730562600150120ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (https://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. camelcase-7.0.0/package.json000066400000000000000000000015661424730562600157420ustar00rootroot00000000000000{ "name": "camelcase", "version": "7.0.0", "description": "Convert a dash/dot/underscore/space separated string to camelCase or PascalCase: `foo-bar` → `fooBar`", "license": "MIT", "repository": "sindresorhus/camelcase", "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, "type": "module", "exports": "./index.js", "types": "./index.d.ts", "engines": { "node": ">=14.16" }, "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": "^4.3.0", "tsd": "^0.20.0", "xo": "^0.49.0" } } camelcase-7.0.0/readme.md000066400000000000000000000073441424730562600152330ustar00rootroot00000000000000# camelcase > Convert a dash/dot/underscore/space separated string to camelCase or PascalCase: `foo-bar` → `fooBar` Correctly handles Unicode strings. If you use this on untrusted user input, don't forget to limit the length to something reasonable. ## Install ```sh npm install camelcase ``` ## Usage ```js import camelCase from 'camelcase'; camelCase('foo-bar'); //=> 'fooBar' camelCase('foo_bar'); //=> 'fooBar' camelCase('Foo-Bar'); //=> 'fooBar' camelCase('розовый_пушистый_единорог'); //=> 'розовыйПушистыйЕдинорог' camelCase('Foo-Bar', {pascalCase: true}); //=> 'FooBar' camelCase('--foo.bar', {pascalCase: false}); //=> 'fooBar' camelCase('Foo-BAR', {preserveConsecutiveUppercase: true}); //=> 'fooBAR' camelCase('fooBAR', {pascalCase: true, preserveConsecutiveUppercase: true})); //=> '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' camelCase(['foo', 'BAR'], {pascalCase: true, preserveConsecutiveUppercase: true}) //=> 'FooBAR' camelCase('lorem-ipsum', {locale: 'en-US'}); //=> 'loremIpsum' ``` ## 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` ##### preserveConsecutiveUppercase Type: `boolean`\ Default: `false` Preserve consecutive uppercase characters: `foo-BAR` → `FooBAR`. ##### locale Type: `false | string | string[]`\ Default: The host environment’s current locale. The locale parameter indicates the locale to be used to convert to upper/lower case according to any locale-specific case mappings. If multiple locales are given in an array, the best available locale is used. ```js import camelCase from 'camelcase'; camelCase('lorem-ipsum', {locale: 'en-US'}); //=> 'loremIpsum' camelCase('lorem-ipsum', {locale: 'tr-TR'}); //=> 'loremİpsum' camelCase('lorem-ipsum', {locale: ['en-US', 'en-GB']}); //=> 'loremIpsum' camelCase('lorem-ipsum', {locale: ['tr', 'TR', 'tr-TR']}); //=> 'loremİpsum' ``` Setting `locale: false` ignores the platform locale and uses the [Unicode Default Case Conversion](https://unicode-org.github.io/icu/userguide/transforms/casemappings.html#simple-single-character-case-mapping) algorithm: ```js import camelCase from 'camelcase'; // On a platform with 'tr-TR' camelCase('lorem-ipsum'); //=> 'loremİpsum' camelCase('lorem-ipsum', {locale: false}); //=> 'loremIpsum' ``` ## camelcase for enterprise Available as part of the Tidelift Subscription. The maintainers of camelcase and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-camelcase?utm_source=npm-camelcase&utm_medium=referral&utm_campaign=enterprise&utm_term=repo) ## 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 - [camelcase-keys](https://github.com/sindresorhus/camelcase-keys) - Convert object keys to camel case camelcase-7.0.0/test.js000066400000000000000000000353231424730562600147670ustar00rootroot00000000000000import test from 'ava'; import camelCase from './index.js'; test('camelCase', t => { t.is(camelCase('foo'), 'foo'); /// https://github.com/sindresorhus/camelcase/issues/95 /// t.is(camelCase('IDs'), 'ids'); /// t.is(camelCase('FooIDs'), 'fooIds'); t.is(camelCase('foo-bar'), 'fooBar'); t.is(camelCase('foo-bar-baz'), 'fooBarBaz'); t.is(camelCase('foo--bar'), 'fooBar'); t.is(camelCase('--foo-bar'), 'fooBar'); t.is(camelCase('--foo--bar'), 'fooBar'); t.is(camelCase('FOO-BAR'), 'fooBar'); t.is(camelCase('FOÈ-BAR'), 'foèBar'); t.is(camelCase('-foo-bar-'), 'fooBar'); t.is(camelCase('--foo--bar--'), 'fooBar'); t.is(camelCase('foo-1'), 'foo1'); t.is(camelCase('foo.bar'), 'fooBar'); t.is(camelCase('foo..bar'), 'fooBar'); t.is(camelCase('..foo..bar..'), 'fooBar'); t.is(camelCase('foo_bar'), 'fooBar'); t.is(camelCase('__foo__bar__'), 'fooBar'); t.is(camelCase('foo bar'), 'fooBar'); t.is(camelCase(' foo bar '), 'fooBar'); t.is(camelCase('-'), ''); t.is(camelCase(' - '), ''); t.is(camelCase('fooBar'), 'fooBar'); t.is(camelCase('fooBar-baz'), 'fooBarBaz'); t.is(camelCase('foìBar-baz'), 'foìBarBaz'); t.is(camelCase('fooBarBaz-bazzy'), 'fooBarBazBazzy'); t.is(camelCase('FBBazzy'), 'fbBazzy'); t.is(camelCase('F'), 'f'); t.is(camelCase('FooBar'), 'fooBar'); t.is(camelCase('Foo'), 'foo'); t.is(camelCase('FOO'), 'foo'); t.is(camelCase(['foo', 'bar']), 'fooBar'); t.is(camelCase(['foo', '-bar']), 'fooBar'); t.is(camelCase(['foo', '-bar', 'baz']), 'fooBarBaz'); t.is(camelCase(['', '']), ''); t.is(camelCase('--'), ''); t.is(camelCase(''), ''); t.is(camelCase('_'), ''); t.is(camelCase(' '), ''); t.is(camelCase('.'), ''); t.is(camelCase('..'), ''); t.is(camelCase('--'), ''); t.is(camelCase(' '), ''); t.is(camelCase('__'), ''); t.is(camelCase('--__--_--_'), ''); t.is(camelCase(['---_', '--', '', '-_- ']), ''); t.is(camelCase('foo bar?'), 'fooBar?'); t.is(camelCase('foo bar!'), 'fooBar!'); t.is(camelCase('foo bar$'), 'fooBar$'); t.is(camelCase('foo-bar#'), 'fooBar#'); t.is(camelCase('XMLHttpRequest'), 'xmlHttpRequest'); t.is(camelCase('AjaxXMLHttpRequest'), 'ajaxXmlHttpRequest'); t.is(camelCase('Ajax-XMLHttpRequest'), 'ajaxXmlHttpRequest'); t.is(camelCase([]), ''); t.is(camelCase('mGridCol6@md'), 'mGridCol6@md'); t.is(camelCase('A::a'), 'a::a'); t.is(camelCase('Hello1World'), 'hello1World'); t.is(camelCase('Hello11World'), 'hello11World'); t.is(camelCase('hello1world'), 'hello1World'); t.is(camelCase('Hello1World11foo'), 'hello1World11Foo'); t.is(camelCase('Hello1'), 'hello1'); t.is(camelCase('hello1'), 'hello1'); t.is(camelCase('1Hello'), '1Hello'); t.is(camelCase('1hello'), '1Hello'); t.is(camelCase('h2w'), 'h2W'); t.is(camelCase('розовый_пушистый-единороги'), 'розовыйПушистыйЕдинороги'); t.is(camelCase('розовый_пушистый-единороги'), 'розовыйПушистыйЕдинороги'); t.is(camelCase('РОЗОВЫЙ_ПУШИСТЫЙ-ЕДИНОРОГИ'), 'розовыйПушистыйЕдинороги'); t.is(camelCase('桑德在这里。'), '桑德在这里。'); t.is(camelCase('桑德在这里。'), '桑德在这里。'); t.is(camelCase('桑德_在这里。'), '桑德在这里。'); }); test('camelCase with pascalCase option', t => { t.is(camelCase('foo', {pascalCase: true}), 'Foo'); t.is(camelCase('foo-bar', {pascalCase: true}), 'FooBar'); t.is(camelCase('foo-bar-baz', {pascalCase: true}), 'FooBarBaz'); t.is(camelCase('foo--bar', {pascalCase: true}), 'FooBar'); t.is(camelCase('--foo-bar', {pascalCase: true}), 'FooBar'); t.is(camelCase('--foo--bar', {pascalCase: true}), 'FooBar'); t.is(camelCase('FOO-BAR', {pascalCase: true}), 'FooBar'); t.is(camelCase('FOÈ-BAR', {pascalCase: true}), 'FoèBar'); t.is(camelCase('-foo-bar-', {pascalCase: true}), 'FooBar'); t.is(camelCase('--foo--bar--', {pascalCase: true}), 'FooBar'); t.is(camelCase('foo-1', {pascalCase: true}), 'Foo1'); t.is(camelCase('foo.bar', {pascalCase: true}), 'FooBar'); t.is(camelCase('foo..bar', {pascalCase: true}), 'FooBar'); t.is(camelCase('..foo..bar..', {pascalCase: true}), 'FooBar'); t.is(camelCase('foo_bar', {pascalCase: true}), 'FooBar'); t.is(camelCase('__foo__bar__', {pascalCase: true}), 'FooBar'); t.is(camelCase('__foo__bar__', {pascalCase: true}), 'FooBar'); t.is(camelCase('foo bar', {pascalCase: true}), 'FooBar'); t.is(camelCase(' foo bar ', {pascalCase: true}), 'FooBar'); t.is(camelCase('-', {pascalCase: true}), ''); t.is(camelCase(' - ', {pascalCase: true}), ''); t.is(camelCase('fooBar', {pascalCase: true}), 'FooBar'); t.is(camelCase('fooBar-baz', {pascalCase: true}), 'FooBarBaz'); t.is(camelCase('foìBar-baz', {pascalCase: true}), 'FoìBarBaz'); t.is(camelCase('fooBarBaz-bazzy', {pascalCase: true}), 'FooBarBazBazzy'); t.is(camelCase('FBBazzy', {pascalCase: true}), 'FbBazzy'); t.is(camelCase('F', {pascalCase: true}), 'F'); t.is(camelCase('FooBar', {pascalCase: true}), 'FooBar'); t.is(camelCase('Foo', {pascalCase: true}), 'Foo'); t.is(camelCase('FOO', {pascalCase: true}), 'Foo'); t.is(camelCase(['foo', 'bar'], {pascalCase: true}), 'FooBar'); t.is(camelCase(['foo', '-bar'], {pascalCase: true}), 'FooBar'); t.is(camelCase(['foo', '-bar', 'baz'], {pascalCase: true}), 'FooBarBaz'); t.is(camelCase(['', ''], {pascalCase: true}), ''); t.is(camelCase('--', {pascalCase: true}), ''); t.is(camelCase('', {pascalCase: true}), ''); t.is(camelCase('--__--_--_', {pascalCase: true}), ''); t.is(camelCase(['---_', '--', '', '-_- '], {pascalCase: true}), ''); t.is(camelCase('foo bar?', {pascalCase: true}), 'FooBar?'); t.is(camelCase('foo bar!', {pascalCase: true}), 'FooBar!'); t.is(camelCase('foo bar$', {pascalCase: true}), 'FooBar$'); t.is(camelCase('foo-bar#', {pascalCase: true}), 'FooBar#'); t.is(camelCase('XMLHttpRequest', {pascalCase: true}), 'XmlHttpRequest'); t.is(camelCase('AjaxXMLHttpRequest', {pascalCase: true}), 'AjaxXmlHttpRequest'); t.is(camelCase('Ajax-XMLHttpRequest', {pascalCase: true}), 'AjaxXmlHttpRequest'); t.is(camelCase([], {pascalCase: true}), ''); t.is(camelCase('mGridCol6@md', {pascalCase: true}), 'MGridCol6@md'); t.is(camelCase('A::a', {pascalCase: true}), 'A::a'); t.is(camelCase('Hello1World', {pascalCase: true}), 'Hello1World'); t.is(camelCase('Hello11World', {pascalCase: true}), 'Hello11World'); t.is(camelCase('hello1world', {pascalCase: true}), 'Hello1World'); t.is(camelCase('hello1World', {pascalCase: true}), 'Hello1World'); t.is(camelCase('hello1', {pascalCase: true}), 'Hello1'); t.is(camelCase('Hello1', {pascalCase: true}), 'Hello1'); t.is(camelCase('1hello', {pascalCase: true}), '1Hello'); t.is(camelCase('1Hello', {pascalCase: true}), '1Hello'); t.is(camelCase('h1W', {pascalCase: true}), 'H1W'); t.is(camelCase('РозовыйПушистыйЕдинороги', {pascalCase: true}), 'РозовыйПушистыйЕдинороги'); t.is(camelCase('розовый_пушистый-единороги', {pascalCase: true}), 'РозовыйПушистыйЕдинороги'); t.is(camelCase('РОЗОВЫЙ_ПУШИСТЫЙ-ЕДИНОРОГИ', {pascalCase: true}), 'РозовыйПушистыйЕдинороги'); t.is(camelCase('桑德在这里。', {pascalCase: true}), '桑德在这里。'); t.is(camelCase('桑德_在这里。', {pascalCase: true}), '桑德在这里。'); }); test('camelCase with preserveConsecutiveUppercase option', t => { t.is(camelCase('foo-BAR', {preserveConsecutiveUppercase: true}), 'fooBAR'); t.is(camelCase('Foo-BAR', {preserveConsecutiveUppercase: true}), 'fooBAR'); t.is(camelCase('fooBAR', {preserveConsecutiveUppercase: true}), 'fooBAR'); t.is(camelCase('fooBaR', {preserveConsecutiveUppercase: true}), 'fooBaR'); t.is(camelCase('FOÈ-BAR', {preserveConsecutiveUppercase: true}), 'FOÈBAR'); t.is(camelCase(['foo', 'BAR'], {preserveConsecutiveUppercase: true}), 'fooBAR'); t.is(camelCase(['foo', '-BAR'], {preserveConsecutiveUppercase: true}), 'fooBAR'); t.is(camelCase(['foo', '-BAR', 'baz'], {preserveConsecutiveUppercase: true}), 'fooBARBaz'); t.is(camelCase(['', ''], {preserveConsecutiveUppercase: true}), ''); t.is(camelCase('--', {preserveConsecutiveUppercase: true}), ''); t.is(camelCase('', {preserveConsecutiveUppercase: true}), ''); t.is(camelCase('--__--_--_', {preserveConsecutiveUppercase: true}), ''); t.is(camelCase(['---_', '--', '', '-_- '], {preserveConsecutiveUppercase: true}), ''); t.is(camelCase('foo BAR?', {preserveConsecutiveUppercase: true}), 'fooBAR?'); t.is(camelCase('foo BAR!', {preserveConsecutiveUppercase: true}), 'fooBAR!'); t.is(camelCase('foo BAR$', {preserveConsecutiveUppercase: true}), 'fooBAR$'); t.is(camelCase('foo-BAR#', {preserveConsecutiveUppercase: true}), 'fooBAR#'); t.is(camelCase('XMLHttpRequest', {preserveConsecutiveUppercase: true}), 'XMLHttpRequest'); t.is(camelCase('AjaxXMLHttpRequest', {preserveConsecutiveUppercase: true}), 'ajaxXMLHttpRequest'); t.is(camelCase('Ajax-XMLHttpRequest', {preserveConsecutiveUppercase: true}), 'ajaxXMLHttpRequest'); t.is(camelCase([], {preserveConsecutiveUppercase: true}), ''); t.is(camelCase('mGridCOl6@md', {preserveConsecutiveUppercase: true}), 'mGridCOl6@md'); t.is(camelCase('A::a', {preserveConsecutiveUppercase: true}), 'a::a'); t.is(camelCase('Hello1WORLD', {preserveConsecutiveUppercase: true}), 'hello1WORLD'); t.is(camelCase('Hello11WORLD', {preserveConsecutiveUppercase: true}), 'hello11WORLD'); t.is(camelCase('РозовыйПушистыйFOOдинорогиf', {preserveConsecutiveUppercase: true}), 'розовыйПушистыйFOOдинорогиf'); t.is(camelCase('桑德在这里。', {preserveConsecutiveUppercase: true}), '桑德在这里。'); t.is(camelCase('桑德_在这里。', {preserveConsecutiveUppercase: true}), '桑德在这里。'); /// https://github.com/sindresorhus/camelcase/issues/95 /// t.is(camelCase('IDs', {preserveConsecutiveUppercase: true}), 'ids'); t.is(camelCase('FooIDs', {preserveConsecutiveUppercase: true}), 'fooIDs'); }); test('camelCase with both pascalCase and preserveConsecutiveUppercase option', t => { t.is(camelCase('foo-BAR', {pascalCase: true, preserveConsecutiveUppercase: true}), 'FooBAR'); t.is(camelCase('fooBAR', {pascalCase: true, preserveConsecutiveUppercase: true}), 'FooBAR'); t.is(camelCase('fooBaR', {pascalCase: true, preserveConsecutiveUppercase: true}), 'FooBaR'); t.is(camelCase('fOÈ-BAR', {pascalCase: true, preserveConsecutiveUppercase: true}), 'FOÈBAR'); t.is(camelCase('--foo.BAR', {pascalCase: true, preserveConsecutiveUppercase: true}), 'FooBAR'); t.is(camelCase(['Foo', 'BAR'], {pascalCase: true, preserveConsecutiveUppercase: true}), 'FooBAR'); t.is(camelCase(['foo', '-BAR'], {pascalCase: true, preserveConsecutiveUppercase: true}), 'FooBAR'); t.is(camelCase(['foo', '-BAR', 'baz'], {pascalCase: true, preserveConsecutiveUppercase: true}), 'FooBARBaz'); t.is(camelCase(['', ''], {pascalCase: true, preserveConsecutiveUppercase: true}), ''); t.is(camelCase('--', {pascalCase: true, preserveConsecutiveUppercase: true}), ''); t.is(camelCase('', {pascalCase: true, preserveConsecutiveUppercase: true}), ''); t.is(camelCase('--__--_--_', {pascalCase: true, preserveConsecutiveUppercase: true}), ''); t.is(camelCase(['---_', '--', '', '-_- '], {pascalCase: true, preserveConsecutiveUppercase: true}), ''); t.is(camelCase('foo BAR?', {pascalCase: true, preserveConsecutiveUppercase: true}), 'FooBAR?'); t.is(camelCase('foo BAR!', {pascalCase: true, preserveConsecutiveUppercase: true}), 'FooBAR!'); t.is(camelCase('Foo BAR$', {pascalCase: true, preserveConsecutiveUppercase: true}), 'FooBAR$'); t.is(camelCase('foo-BAR#', {pascalCase: true, preserveConsecutiveUppercase: true}), 'FooBAR#'); t.is(camelCase('xMLHttpRequest', {pascalCase: true, preserveConsecutiveUppercase: true}), 'XMLHttpRequest'); t.is(camelCase('ajaxXMLHttpRequest', {pascalCase: true, preserveConsecutiveUppercase: true}), 'AjaxXMLHttpRequest'); t.is(camelCase('Ajax-XMLHttpRequest', {pascalCase: true, preserveConsecutiveUppercase: true}), 'AjaxXMLHttpRequest'); t.is(camelCase([], {pascalCase: true, preserveConsecutiveUppercase: true}), ''); t.is(camelCase('mGridCOl6@md', {pascalCase: true, preserveConsecutiveUppercase: true}), 'MGridCOl6@md'); t.is(camelCase('A::a', {pascalCase: true, preserveConsecutiveUppercase: true}), 'A::a'); t.is(camelCase('Hello1WORLD', {pascalCase: true, preserveConsecutiveUppercase: true}), 'Hello1WORLD'); t.is(camelCase('Hello11WORLD', {pascalCase: true, preserveConsecutiveUppercase: true}), 'Hello11WORLD'); t.is(camelCase('pозовыйПушистыйFOOдинорогиf', {pascalCase: true, preserveConsecutiveUppercase: true}), 'PозовыйПушистыйFOOдинорогиf'); t.is(camelCase('桑德在这里。', {pascalCase: true, preserveConsecutiveUppercase: true}), '桑德在这里。'); t.is(camelCase('桑德_在这里。', {pascalCase: true, preserveConsecutiveUppercase: true}), '桑德在这里。'); }); test('camelCase with locale option', t => { t.is(camelCase('lorem-ipsum', {locale: 'tr-TR'}), 'loremİpsum'); t.is(camelCase('lorem-ipsum', {locale: 'en-EN'}), 'loremIpsum'); t.is(camelCase('lorem-ipsum', {locale: ['tr', 'TR', 'tr-TR']}), 'loremİpsum'); t.is(camelCase('lorem-ipsum', {locale: ['en-EN', 'en-GB']}), 'loremIpsum'); t.is(camelCase('ipsum-dolor', {pascalCase: true, locale: 'tr-TR'}), 'İpsumDolor'); t.is(camelCase('ipsum-dolor', {pascalCase: true, locale: 'en-EN'}), 'IpsumDolor'); t.is(camelCase('ipsum-dolor', {pascalCase: true, locale: ['tr', 'TR', 'tr-TR']}), 'İpsumDolor'); t.is(camelCase('ipsum-dolor', {pascalCase: true, locale: ['en-EN', 'en-GB']}), 'IpsumDolor'); }); test('camelCase with disabled locale', t => { withLocaleCaseFunctionsMocked(() => { t.is(camelCase('lorem-ipsum', {locale: false}), 'loremIpsum'); t.is(camelCase('ipsum-dolor', {pascalCase: true, locale: false}), 'IpsumDolor'); t.is(camelCase('ipsum-DOLOR', {pascalCase: true, locale: false, preserveConsecutiveUppercase: true}), 'IpsumDOLOR'); }); }); test('invalid input', t => { t.throws(() => { camelCase(1); }, { message: /Expected the input to be/, }); }); /* eslint-disable no-extend-native */ const withLocaleCaseFunctionsMocked = fn => { const throwWhenBeingCalled = () => { throw new Error('Should not be called'); }; const toLocaleUpperCase = Object.getOwnPropertyDescriptor(String.prototype, 'toLocaleUpperCase'); const toLocaleLowerCase = Object.getOwnPropertyDescriptor(String.prototype, 'toLocaleLowerCase'); Object.defineProperty(String.prototype, 'toLocaleUpperCase', { ...toLocaleUpperCase, value: throwWhenBeingCalled, }); Object.defineProperty(String.prototype, 'toLocaleLowerCase', { ...toLocaleLowerCase, value: throwWhenBeingCalled, }); try { fn(); } finally { Object.defineProperty(String.prototype, 'toLocaleUpperCase', toLocaleUpperCase); Object.defineProperty(String.prototype, 'toLocaleLowerCase', toLocaleLowerCase); } }; /* eslint-enable no-extend-native */