pax_global_header00006660000000000000000000000064151044464200014512gustar00rootroot0000000000000052 comment=8596a65fcbfedd474cdedf16f48b7d9381eb7953 sindresorhus-camelcase-1a745cc/000077500000000000000000000000001510444642000165665ustar00rootroot00000000000000sindresorhus-camelcase-1a745cc/.editorconfig000066400000000000000000000002571510444642000212470ustar00rootroot00000000000000root = 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 sindresorhus-camelcase-1a745cc/.gitattributes000066400000000000000000000000231510444642000214540ustar00rootroot00000000000000* text=auto eol=lf sindresorhus-camelcase-1a745cc/.github/000077500000000000000000000000001510444642000201265ustar00rootroot00000000000000sindresorhus-camelcase-1a745cc/.github/security.md000066400000000000000000000002631510444642000223200ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. sindresorhus-camelcase-1a745cc/.github/workflows/000077500000000000000000000000001510444642000221635ustar00rootroot00000000000000sindresorhus-camelcase-1a745cc/.github/workflows/main.yml000066400000000000000000000006451510444642000236370ustar00rootroot00000000000000name: CI on: - push - pull_request jobs: test: name: Node.js ${{ matrix.node-version }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: node-version: - 24 - 20 steps: - uses: actions/checkout@v5 - uses: actions/setup-node@v6 with: node-version: ${{ matrix.node-version }} - run: npm install - run: npm test sindresorhus-camelcase-1a745cc/.gitignore000066400000000000000000000000271510444642000205550ustar00rootroot00000000000000node_modules yarn.lock sindresorhus-camelcase-1a745cc/.npmrc000066400000000000000000000000231510444642000177010ustar00rootroot00000000000000package-lock=false sindresorhus-camelcase-1a745cc/index.d.ts000066400000000000000000000074111510444642000204720ustar00rootroot00000000000000export type Options = { /** Uppercase the first character: `foo-bar` → `FooBar` @default false @example ``` import camelCase from 'camelcase'; camelCase('foo-bar', {pascalCase: true}); //=> 'FooBar' camelCase('foo-bar', {pascalCase: false}); //=> 'fooBar' ``` */ readonly pascalCase?: boolean; /** Preserve consecutive uppercase characters: `foo-BAR` → `FooBAR` @default false @example ``` import camelCase from 'camelcase'; camelCase('foo-BAR', {preserveConsecutiveUppercase: true}); //=> 'fooBAR' camelCase('foo-BAR', {preserveConsecutiveUppercase: false}); //=> 'fooBar' ```` */ readonly preserveConsecutiveUppercase?: boolean; /** Controls whether letters immediately following digits are treated as word boundaries. **When `true` (default):** Capitalize the first letter immediately following a numeric sequence, unless a separator intervenes. This aligns with most utilities, such as Lodash. **When `false`:** Do not treat digits as word boundaries. Preserve the original case of letters immediately following digits. Separators still create word boundaries. This follows the Google Java Style Guide which treats numbers as non-boundary characters. @default true @example ``` import camelCase from 'camelcase'; camelCase('foo2bar', {capitalizeAfterNumber: true}); //=> 'foo2Bar' (capitalizes 'b' after digit) camelCase('foo2bar', {capitalizeAfterNumber: false}); //=> 'foo2bar' (preserves lowercase 'b') // Preserves original case after numbers when false camelCase('Textures_3d', {capitalizeAfterNumber: false}); //=> 'textures3d' (preserves lowercase 'd') camelCase('Textures_3D', {capitalizeAfterNumber: false}); //=> 'textures3D' (preserves uppercase 'D') // Separators still create boundaries camelCase('foo_2_bar', {capitalizeAfterNumber: false}); //=> 'foo2Bar' ('bar' follows separator, not digit) ``` */ readonly capitalizeAfterNumber?: 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. 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' ``` 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: @example ``` import camelCase from 'camelcase'; // On a platform with `tr-TR`.` camelCase('lorem-ipsum'); //=> 'loremİpsum' camelCase('lorem-ipsum', {locale: false}); //=> 'loremIpsum' ``` */ 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 - The 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'); //=> 'fooBar' console.log(process.argv[3]); //=> '--foo-bar' camelCase(process.argv[3]); //=> 'fooBar' camelCase(['foo', 'bar']); //=> 'fooBar' camelCase(['__foo__', '--bar']); //=> '__fooBar' ``` */ export default function camelcase( input: string | readonly string[], options?: Options ): string; sindresorhus-camelcase-1a745cc/index.js000066400000000000000000000165471510444642000202500ustar00rootroot00000000000000const UPPERCASE = /[\p{Lu}]/u; const LOWERCASE = /[\p{Ll}]/u; const LEADING_CAPITAL = /^[\p{Lu}](?![\p{Lu}])/u; const SEPARATORS = /[_.\- ]+/; // The |$ alternative allows matching at end-of-string, capturing empty string // This enables NUMBERS_AND_IDENTIFIER to match digits at string end (e.g., "test123") const IDENTIFIER = /([\p{Alpha}\p{N}_]|$)/u; const LEADING_SEPARATORS = new RegExp('^' + SEPARATORS.source); const SEPARATORS_AND_IDENTIFIER = new RegExp(SEPARATORS.source + IDENTIFIER.source, 'gu'); const NUMBERS_AND_IDENTIFIER = new RegExp(String.raw`\d+` + IDENTIFIER.source, 'gu'); const preserveCamelCase = (string, toLowerCase, toUpperCase, preserveConsecutiveUppercase) => { let isLastCharLower = false; let isLastCharUpper = false; let isLastLastCharUpper = false; let isLastLastCharPreserved = false; for (let index = 0; index < string.length; index++) { const character = string[index]; // Was the character 3 positions back inserted as a separator? // Prevents excessive separators by checking if we recently inserted one // index - 3 accounts for: current character, inserted separator, previous character // Default true for early positions activates the preserveConsecutiveUppercase guard isLastLastCharPreserved = index > 2 ? string[index - 3] === '-' : true; if (isLastCharLower && UPPERCASE.test(character)) { // FooBar → Foo-Bar (insert separator before uppercase) string = string.slice(0, index) + '-' + string.slice(index); isLastCharLower = false; isLastLastCharUpper = isLastCharUpper; isLastCharUpper = true; index++; } else if ( isLastCharUpper && isLastLastCharUpper && LOWERCASE.test(character) && (!isLastLastCharPreserved || preserveConsecutiveUppercase) ) { // FOOBar → FOO-Bar 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) => input.replace(LEADING_CAPITAL, match => toLowerCase(match)); const processWithCasePreservation = (input, toLowerCase, preserveConsecutiveUppercase) => { let result = ''; let previousWasNumber = false; let previousWasUppercase = false; // Convert input to array for lookahead capability const characters = [...input]; for (let index = 0; index < characters.length; index++) { const character = characters[index]; const isUpperCase = UPPERCASE.test(character); const nextCharIsUpperCase = index + 1 < characters.length && UPPERCASE.test(characters[index + 1]); if (previousWasNumber && /[\p{Alpha}]/u.test(character)) { // Letter after number - preserve original case result += character; previousWasNumber = false; previousWasUppercase = isUpperCase; } else if (preserveConsecutiveUppercase && isUpperCase && (previousWasUppercase || nextCharIsUpperCase)) { // Part of consecutive uppercase sequence when preserveConsecutiveUppercase is true - keep it result += character; previousWasUppercase = true; } else if (/\d/.test(character)) { // Number - keep as-is and track it result += character; previousWasNumber = true; previousWasUppercase = false; } else if (SEPARATORS.test(character)) { // Separator - keep as-is and maintain previousWasNumber state result += character; previousWasUppercase = false; } else { // Regular character - lowercase it result += toLowerCase(character); previousWasNumber = false; previousWasUppercase = false; } } return result; }; /** Core post-processing: - Collapses separators and uppercases the following identifier character. - Optionally uppercases the identifier following a numeric sequence. Two-pass strategy prevents conflicts: 1. NUMBERS_AND_IDENTIFIER: handles digit-to-letter transitions 2. SEPARATORS_AND_IDENTIFIER: handles separator-to-identifier transitions Example: "b2b_registration" with capitalizeAfterNumber: true - Pass 1: "2b" matches, next char is "_" (separator), so don't capitalize → "b2b_registration" - Pass 2: "_r" matches, replace with "R" → "b2bRegistration" */ const postProcess = (input, toUpperCase, {capitalizeAfterNumber}) => { const transformNumericIdentifier = capitalizeAfterNumber ? (match, identifier, offset, string) => { const nextCharacter = string.charAt(offset + match.length); // If the numeric+identifier run is immediately followed by a separator, // treat it as a continued token and do not force a new word. if (SEPARATORS.test(nextCharacter)) { return match; } // Only uppercase the identifier part (not the digits) for efficiency return identifier ? match.slice(0, -identifier.length) + toUpperCase(identifier) : match; } // When false: numbers do not create a word boundary. : match => match; return input .replaceAll(NUMBERS_AND_IDENTIFIER, transformNumericIdentifier) .replaceAll( SEPARATORS_AND_IDENTIFIER, (_, identifier) => toUpperCase(identifier), ); }; 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, capitalizeAfterNumber: true, ...options, }; if (Array.isArray(input)) { input = input .map(element => element.trim()) .filter(element => element.length > 0) .join('-'); } else { input = input.trim(); } if (input.length === 0) { return ''; } // Preserve leading _ and $ as they have semantic meaning const leadingPrefix = input.match(/^[_$]*/)[0]; input = input.slice(leadingPrefix.length); if (input.length === 0) { return leadingPrefix; } 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 leadingPrefix; } return leadingPrefix + (options.pascalCase ? toUpperCase(input) : toLowerCase(input)); } const hasUpperCase = input !== toLowerCase(input); if (hasUpperCase) { input = preserveCamelCase( input, toLowerCase, toUpperCase, options.preserveConsecutiveUppercase, ); } // Strip leading separators eagerly so they do not affect word detection input = input.replace(LEADING_SEPARATORS, ''); // Normalize base casing while preserving intended consecutive uppers if (options.capitalizeAfterNumber) { // Standard behavior - lowercase everything (or preserve consecutive uppercase) input = options.preserveConsecutiveUppercase ? preserveConsecutiveUppercase(input, toLowerCase) : toLowerCase(input); } else { // Preserve case after numbers (processWithCasePreservation handles preserveConsecutiveUppercase internally) input = processWithCasePreservation(input, toLowerCase, options.preserveConsecutiveUppercase); } if (options.pascalCase && input.length > 0) { input = toUpperCase(input[0]) + input.slice(1); } return leadingPrefix + postProcess(input, toUpperCase, options); } sindresorhus-camelcase-1a745cc/index.test-d.ts000066400000000000000000000017661510444642000214560ustar00rootroot00000000000000import {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('foo2bar', {capitalizeAfterNumber: true})); expectType(camelCase('foo2bar', {capitalizeAfterNumber: false})); expectType(camelCase('foo2bar', {pascalCase: true, capitalizeAfterNumber: true})); expectType(camelCase('foo2bar', {pascalCase: true, capitalizeAfterNumber: false})); expectType(camelCase(['foo', 'bar'])); expectType(camelCase(['__foo__', '--bar'], {pascalCase: true})); sindresorhus-camelcase-1a745cc/license000066400000000000000000000021351510444642000201340ustar00rootroot00000000000000MIT 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. sindresorhus-camelcase-1a745cc/package.json000066400000000000000000000016341510444642000210600ustar00rootroot00000000000000{ "name": "camelcase", "version": "9.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": { "types": "./index.d.ts", "default": "./index.js" }, "sideEffects": false, "engines": { "node": ">=20" }, "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": "^6.4.1", "tsd": "^0.33.0", "xo": "^1.2.3" } } sindresorhus-camelcase-1a745cc/readme.md000066400000000000000000000104711510444642000203500ustar00rootroot00000000000000# 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'); //=> 'fooBar' console.log(process.argv[3]); //=> '--foo-bar' camelCase(process.argv[3]); //=> 'fooBar' camelCase(['foo', 'bar']); //=> 'fooBar' camelCase(['__foo__', '--bar']); //=> '__fooBar' ``` > [!NOTE] > Not idempotent when special characters are present. `camelCase('{ A')` → `'{A}'`, but `camelCase('{A}')` → `'{a}'`. ## API ### camelCase(input, options?) #### input Type: `string | string[]` The string to convert to camel case. #### options Type: `object` ##### pascalCase Type: `boolean`\ Default: `false` Uppercase the first character: `foo-bar` → `FooBar` ```js import camelCase from 'camelcase'; camelCase('foo-bar', {pascalCase: true}); //=> 'FooBar' camelCase('foo-bar', {pascalCase: false}); //=> 'fooBar' ``` ##### preserveConsecutiveUppercase Type: `boolean`\ Default: `false` Preserve consecutive uppercase characters: `foo-BAR` → `FooBAR` ```js import camelCase from 'camelcase'; camelCase('foo-BAR', {preserveConsecutiveUppercase: true}); //=> 'fooBAR' camelCase('foo-BAR', {preserveConsecutiveUppercase: false}); //=> 'fooBar' ```` ##### capitalizeAfterNumber Type: `boolean`\ Default: `true` Controls whether letters immediately following digits are treated as word boundaries. **When `true` (default):** Capitalize the first letter immediately following a numeric sequence, unless a separator intervenes. This aligns with most utilities, such as Lodash. **When `false`:** Do not treat digits as word boundaries. Preserve the original case of letters immediately following digits. Separators still create word boundaries. This follows the Google Java Style Guide which treats numbers as non-boundary characters. ```js import camelCase from 'camelcase'; camelCase('foo2bar', {capitalizeAfterNumber: true}); //=> 'foo2Bar' (capitalizes 'b' after digit) camelCase('foo2bar', {capitalizeAfterNumber: false}); //=> 'foo2bar' (preserves lowercase 'b') // Preserves original case after numbers when false camelCase('Textures_3d', {capitalizeAfterNumber: false}); //=> 'textures3d' (preserves lowercase 'd') camelCase('Textures_3D', {capitalizeAfterNumber: false}); //=> 'textures3D' (preserves uppercase 'D') // Separators still create boundaries camelCase('foo_2_bar', {capitalizeAfterNumber: false}); //=> 'foo2Bar' ('bar' follows separator, not digit) ``` ##### 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' ``` ## Related - [decamelize](https://github.com/sindresorhus/decamelize) - The inverse of this module - [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 sindresorhus-camelcase-1a745cc/test.js000066400000000000000000000550241510444642000201110ustar00rootroot00000000000000import test from 'ava'; import camelCase from './index.js'; test('camelCase', t => { t.is(camelCase('b2b_registration_request'), 'b2bRegistrationRequest'); t.is(camelCase('b2b-registration-request'), 'b2bRegistrationRequest'); t.is(camelCase('b2b_registration_b2b_request'), 'b2bRegistrationB2bRequest'); t.is(camelCase('foo'), 'foo'); 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('b2b_registration_request', {pascalCase: true}), 'B2bRegistrationRequest'); 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('-', {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}), '桑德在这里。'); t.is(camelCase('a1b', {pascalCase: true}), 'A1B'); }); 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}), '桑德在这里。'); 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('number handling follows Google Style Guide', t => { // Numbers don't create word boundaries (Google Java Style Guide) // https://google.github.io/styleguide/javaguide.html#s5.3-camel-case t.is(camelCase('turn_on_2sv', {capitalizeAfterNumber: false}), 'turnOn2sv'); // NOT turnOn2Sv t.is(camelCase('a1b_text', {capitalizeAfterNumber: false}), 'a1bText'); // NOT a1BText t.is(camelCase('foo2bar', {capitalizeAfterNumber: false}), 'foo2bar'); // NOT foo2Bar t.is(camelCase('version2', {capitalizeAfterNumber: false}), 'version2'); // With pascalCase t.is(camelCase('turn_on_2sv', {pascalCase: true, capitalizeAfterNumber: false}), 'TurnOn2sv'); t.is(camelCase('a1b_text', {pascalCase: true, capitalizeAfterNumber: false}), 'A1bText'); }); test('camelCase with capitalizeAfterNumber option', t => { t.is(camelCase('Hello1World'), 'hello1World'); t.is(camelCase('Hello1World', {capitalizeAfterNumber: false}), 'hello1World'); // Preserves uppercase W t.is(camelCase('foo2bar'), 'foo2Bar'); t.is(camelCase('foo2bar', {capitalizeAfterNumber: false}), 'foo2bar'); t.is(camelCase('hello1world'), 'hello1World'); t.is(camelCase('hello1world', {capitalizeAfterNumber: false}), 'hello1world'); // Preserves lowercase w t.is(camelCase('turn_on_2sv'), 'turnOn2Sv'); t.is(camelCase('turn_on_2sv', {capitalizeAfterNumber: false}), 'turnOn2sv'); t.is(camelCase('Hello1World', {pascalCase: true}), 'Hello1World'); t.is(camelCase('Hello1World', {pascalCase: true, capitalizeAfterNumber: false}), 'Hello1World'); // Preserves uppercase W t.is(camelCase('turn_on_2sv', {pascalCase: true}), 'TurnOn2Sv'); t.is(camelCase('turn_on_2sv', {pascalCase: true, capitalizeAfterNumber: false}), 'TurnOn2sv'); }); test('capitalizeAfterNumber edge cases', t => { t.is(camelCase('foo-2bar'), 'foo2Bar'); t.is(camelCase('foo-2bar', {capitalizeAfterNumber: false}), 'foo2bar'); t.is(camelCase('foo-2bar', {pascalCase: true}), 'Foo2Bar'); t.is(camelCase('foo-2bar', {pascalCase: true, capitalizeAfterNumber: false}), 'Foo2bar'); t.is(camelCase('2foo-bar'), '2FooBar'); t.is(camelCase('2foo-bar', {capitalizeAfterNumber: false}), '2fooBar'); t.is(camelCase('2foo-bar', {pascalCase: true}), '2FooBar'); t.is(camelCase('2foo-bar', {pascalCase: true, capitalizeAfterNumber: false}), '2fooBar'); t.is(camelCase('XML2HTTP'), 'xml2Http'); t.is(camelCase('XML2HTTP', {capitalizeAfterNumber: false}), 'xml2Http'); // Preserves uppercase H t.is(camelCase('XML2HTTP', {pascalCase: true}), 'Xml2Http'); t.is(camelCase('XML2HTTP', {pascalCase: true, capitalizeAfterNumber: false}), 'Xml2Http'); // Preserves uppercase H t.is(camelCase('2a'), '2A'); t.is(camelCase('2a', {capitalizeAfterNumber: false}), '2a'); t.is(camelCase('2a', {pascalCase: true}), '2A'); t.is(camelCase('2a', {pascalCase: true, capitalizeAfterNumber: false}), '2a'); t.is(camelCase('foo2BAR', {preserveConsecutiveUppercase: true}), 'foo2BAR'); t.is(camelCase('foo2BAR', {preserveConsecutiveUppercase: true, capitalizeAfterNumber: false}), 'foo2BAR'); }); test('case preservation after numbers (capitalizeAfterNumber: false)', t => { // When capitalizeAfterNumber is false, original case is preserved t.is(camelCase('Textures_3d', {capitalizeAfterNumber: false}), 'textures3d'); // Preserves lowercase d t.is(camelCase('Textures_3D', {capitalizeAfterNumber: false}), 'textures3D'); // Preserves uppercase D t.is(camelCase('version_1a', {capitalizeAfterNumber: false}), 'version1a'); t.is(camelCase('version_1A', {capitalizeAfterNumber: false}), 'version1A'); t.is(camelCase('foo_2_bar', {capitalizeAfterNumber: false}), 'foo2Bar'); // 'bar' is after separator, not directly after number // With pascalCase t.is(camelCase('Textures_3d', {pascalCase: true, capitalizeAfterNumber: false}), 'Textures3d'); t.is(camelCase('Textures_3D', {pascalCase: true, capitalizeAfterNumber: false}), 'Textures3D'); }); test('preserve leading underscores and dollar signs', t => { // Leading _ and $ have semantic meaning (private/internal, jQuery/observables) 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'); // Edge cases: only prefix characters t.is(camelCase('_'), '_'); t.is(camelCase('__'), '__'); t.is(camelCase('$'), '$'); t.is(camelCase('$$$'), '$$$'); t.is(camelCase('_$'), '_$'); // With pascalCase t.is(camelCase('_foo_bar', {pascalCase: true}), '_FooBar'); t.is(camelCase('$foo_bar', {pascalCase: true}), '$FooBar'); t.is(camelCase('__foo_bar', {pascalCase: true}), '__FooBar'); // With preserveConsecutiveUppercase t.is(camelCase('_foo_BAR', {preserveConsecutiveUppercase: true}), '_fooBAR'); t.is(camelCase('$foo_BAR', {preserveConsecutiveUppercase: true}), '$fooBAR'); // Combined with other transformations t.is(camelCase('_foo-bar_baz'), '_fooBarBaz'); t.is(camelCase('$http_service'), '$httpService'); }); test('edge cases: emoji and unicode', t => { // Emoji treated as non-separator special character t.is(camelCase('foo-🦄-bar'), 'foo-🦄Bar'); t.is(camelCase('foo🦄bar'), 'foo🦄bar'); // Zero-width characters preserved t.is(camelCase('foo\u200Dbar'), 'foo\u200Dbar'); // RTL languages t.is(camelCase('foo_مرحبا_bar'), 'fooمرحباBar'); t.is(camelCase('foo_שלום_bar'), 'fooשלוםBar'); }); test('edge cases: combined options', t => { // All options together t.is(camelCase('foo_2BAR_baz', {pascalCase: true, preserveConsecutiveUppercase: true, capitalizeAfterNumber: false}), 'Foo2BARBaz'); // Leading prefix with all options t.is(camelCase('__foo_2BAR', {pascalCase: true, preserveConsecutiveUppercase: true, capitalizeAfterNumber: false}), '__Foo2BAR'); t.is(camelCase('$_foo_BAR', {pascalCase: true, preserveConsecutiveUppercase: true}), '$_FooBAR'); }); test('edge cases: numbers', t => { // Decimal numbers (dots are separators) t.is(camelCase('version_3.14.15'), 'version31415'); // Negative sign is special character t.is(camelCase('temp_-5_degrees'), 'temp5Degrees'); // Only numbers t.is(camelCase('123'), '123'); t.is(camelCase('123_456_789'), '123456789'); }); test('edge cases: locale with capitalizeAfterNumber', t => { // Turkish i/İ with numbers and capitalizeAfterNumber t.is(camelCase('test_1i', {locale: 'tr-TR'}), 'test1İ'); t.is(camelCase('test_1i', {locale: 'tr-TR', capitalizeAfterNumber: false}), 'test1i'); // Empty locale array falls back to default t.is(camelCase('foo-bar', {locale: []}), 'fooBar'); }); test('edge cases: special characters', t => { // Multiple consecutive special chars t.is(camelCase('foo##bar'), 'foo##bar'); t.is(camelCase('foo@#$bar'), 'foo@#$bar'); // Mixed separators and special chars t.is(camelCase('foo_@#_bar'), 'foo_@#Bar'); }); test('edge cases: array input', t => { // Array with leading prefixes t.is(camelCase(['_foo', '$bar']), '_foo-$bar'); // Array with only whitespace elements t.is(camelCase([' ', ' foo ', ' ']), 'foo'); t.is(camelCase(['', ' ', '']), ''); }); test('edge cases: uppercase transitions', t => { // Multiple rapid transitions t.is(camelCase('aAbBcC'), 'aAbBcC'); t.is(camelCase('a1A2B3C'), 'a1A2B3C'); // Single uppercase with preserveConsecutiveUppercase t.is(camelCase('fooAbar', {preserveConsecutiveUppercase: true}), 'fooAbar'); t.is(camelCase('A', {preserveConsecutiveUppercase: true}), 'a'); }); test('edge cases: extreme inputs', t => { // Very long separator sequences const longPrefix = '_'.repeat(50); t.is(camelCase(longPrefix + 'foo' + longPrefix + 'bar'), longPrefix + 'fooBar'); // Mixed repeated separators t.is(camelCase('_-. _-. _-.foo'), '_foo'); // Only separators t.is(camelCase('-_. -_. -_.'), ''); }); 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 */