Socket
Socket
Sign inDemoInstall

camelcase

Package Overview
Dependencies
0
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 6.2.1 to 6.3.0

4

index.d.ts

@@ -20,2 +20,4 @@ declare namespace camelcase {

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.

@@ -37,3 +39,3 @@

*/
readonly locale?: string | readonly string[];
readonly locale?: false | string | readonly string[];
}

@@ -40,0 +42,0 @@ }

@@ -13,3 +13,3 @@ 'use strict';

const preserveCamelCase = (string, locale) => {
const preserveCamelCase = (string, toLowerCase, toUpperCase) => {
let isLastCharLower = false;

@@ -34,5 +34,5 @@ let isLastCharUpper = false;

} else {
isLastCharLower = character.toLocaleLowerCase(locale) === character && character.toLocaleUpperCase(locale) !== character;
isLastCharLower = toLowerCase(character) === character && toUpperCase(character) !== character;
isLastLastCharUpper = isLastCharUpper;
isLastCharUpper = character.toLocaleUpperCase(locale) === character && character.toLocaleLowerCase(locale) !== character;
isLastCharUpper = toUpperCase(character) === character && toLowerCase(character) !== character;
}

@@ -44,14 +44,14 @@ }

const preserveConsecutiveUppercase = input => {
const preserveConsecutiveUppercase = (input, toLowerCase) => {
LEADING_CAPITAL.lastIndex = 0;
return input.replace(LEADING_CAPITAL, m1 => m1.toLowerCase());
return input.replace(LEADING_CAPITAL, m1 => toLowerCase(m1));
};
const postProcess = (input, options) => {
const postProcess = (input, toUpperCase) => {
SEPARATORS_AND_IDENTIFIER.lastIndex = 0;
NUMBERS_AND_IDENTIFIER.lastIndex = 0;
return input.replace(SEPARATORS_AND_IDENTIFIER, (_, identifier) => identifier.toLocaleUpperCase(options.locale))
.replace(NUMBERS_AND_IDENTIFIER, m => m.toLocaleUpperCase(options.locale));
return input.replace(SEPARATORS_AND_IDENTIFIER, (_, identifier) => toUpperCase(identifier))
.replace(NUMBERS_AND_IDENTIFIER, m => toUpperCase(m));
};

@@ -82,10 +82,17 @@

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 ? input.toLocaleUpperCase(options.locale) : input.toLocaleLowerCase(options.locale);
return options.pascalCase ? toUpperCase(input) : toLowerCase(input);
}
const hasUpperCase = input !== input.toLocaleLowerCase(options.locale);
const hasUpperCase = input !== toLowerCase(input);
if (hasUpperCase) {
input = preserveCamelCase(input, options.locale);
input = preserveCamelCase(input, toLowerCase, toUpperCase);
}

@@ -96,12 +103,12 @@

if (options.preserveConsecutiveUppercase) {
input = preserveConsecutiveUppercase(input);
input = preserveConsecutiveUppercase(input, toLowerCase);
} else {
input = input.toLocaleLowerCase();
input = toLowerCase(input);
}
if (options.pascalCase) {
input = input.charAt(0).toLocaleUpperCase(options.locale) + input.slice(1);
input = toUpperCase(input.charAt(0)) + input.slice(1);
}
return postProcess(input, options);
return postProcess(input, toUpperCase);
};

@@ -108,0 +115,0 @@

{
"name": "camelcase",
"version": "6.2.1",
"version": "6.3.0",
"description": "Convert a dash/dot/underscore/space separated string to camelCase or PascalCase: `foo-bar` → `fooBar`",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -97,3 +97,3 @@ # camelcase

Type: `string | string[]`\
Type: `false | string | string[]`\
Default: The host environment’s current locale.

@@ -119,2 +119,16 @@

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

@@ -121,0 +135,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc