pax_global_header00006660000000000000000000000064141641346420014517gustar00rootroot0000000000000052 comment=497d7fc3ae98b2232af1e56aa24f82878d7f53f0 camelcase-6.3.0/000077500000000000000000000000001416413464200134425ustar00rootroot00000000000000camelcase-6.3.0/.editorconfig000066400000000000000000000002571416413464200161230ustar00rootroot00000000000000root = 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-6.3.0/.gitattributes000066400000000000000000000000231416413464200163300ustar00rootroot00000000000000* text=auto eol=lf camelcase-6.3.0/.github/000077500000000000000000000000001416413464200150025ustar00rootroot00000000000000camelcase-6.3.0/.github/funding.yml000066400000000000000000000001631416413464200171570ustar00rootroot00000000000000github: sindresorhus open_collective: sindresorhus tidelift: npm/camelcase custom: https://sindresorhus.com/donate camelcase-6.3.0/.github/security.md000066400000000000000000000002631416413464200171740ustar00rootroot00000000000000# 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-6.3.0/.github/workflows/000077500000000000000000000000001416413464200170375ustar00rootroot00000000000000camelcase-6.3.0/.github/workflows/main.yml000066400000000000000000000006641416413464200205140ustar00rootroot00000000000000name: CI on: - push - pull_request jobs: test: name: Node.js ${{ matrix.node-version }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: node-version: - 14 - 12 - 10 steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - run: npm install - run: npm test camelcase-6.3.0/.gitignore000066400000000000000000000000271416413464200154310ustar00rootroot00000000000000node_modules yarn.lock camelcase-6.3.0/.npmrc000066400000000000000000000000231416413464200145550ustar00rootroot00000000000000package-lock=false camelcase-6.3.0/index.d.ts000066400000000000000000000047571416413464200153600ustar00rootroot00000000000000declare namespace camelcase { interface Options { /** Uppercase the first character: `foo-bar` → `FooBar`. @default false */ readonly pascalCase?: boolean; /** Preserve the 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 = require('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 = require('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' ``` */ declare function camelcase( input: string | readonly string[], options?: camelcase.Options ): string; export = camelcase; camelcase-6.3.0/index.js000066400000000000000000000063101416413464200151070ustar00rootroot00000000000000'use strict'; const 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 i = 0; i < string.length; i++) { const character = string[i]; if (isLastCharLower && UPPERCASE.test(character)) { string = string.slice(0, i) + '-' + string.slice(i); isLastCharLower = false; isLastLastCharUpper = isLastCharUpper; isLastCharUpper = true; i++; } else if (isLastCharUpper && isLastLastCharUpper && LOWERCASE.test(character)) { string = string.slice(0, i - 1) + '-' + string.slice(i - 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)); }; const 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) { return options.pascalCase ? toUpperCase(input) : toLowerCase(input); } const hasUpperCase = input !== toLowerCase(input); if (hasUpperCase) { input = preserveCamelCase(input, toLowerCase, toUpperCase); } input = input.replace(LEADING_SEPARATORS, ''); if (options.preserveConsecutiveUppercase) { input = preserveConsecutiveUppercase(input, toLowerCase); } else { input = toLowerCase(input); } if (options.pascalCase) { input = toUpperCase(input.charAt(0)) + input.slice(1); } return postProcess(input, toUpperCase); }; module.exports = camelCase; // TODO: Remove this for the next major release module.exports.default = camelCase; camelcase-6.3.0/index.test-d.ts000066400000000000000000000012511416413464200163170ustar00rootroot00000000000000import {expectType} from 'tsd'; import camelCase = require('.'); 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-6.3.0/license000066400000000000000000000021351416413464200150100ustar00rootroot00000000000000MIT 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-6.3.0/package.json000066400000000000000000000014541416413464200157340ustar00rootroot00000000000000{ "name": "camelcase", "version": "6.3.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" }, "engines": { "node": ">=10" }, "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.11.0", "xo": "^0.28.3" } } camelcase-6.3.0/readme.md000066400000000000000000000075611416413464200152320ustar00rootroot00000000000000# 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 ``` $ npm install camelcase ``` *If you need to support Firefox < 78, stay on version 5 as version 6 uses regex features not available in Firefox < 78.* ## Usage ```js const camelCase = require('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 the 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 const camelCase = require('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 const camelCase = require('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-6.3.0/test.js000066400000000000000000000342441416413464200147660ustar00rootroot00000000000000import test from 'ava'; import camelCase from '.'; test('camelCase', t => { t.is(camelCase('foo'), 'foo'); 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('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}), '桑德在这里。'); }); 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); }, /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 */