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.3.0 to 7.0.0

73

index.d.ts

@@ -1,42 +0,43 @@

declare namespace camelcase {
interface Options {
/**
Uppercase the first character: `foo-bar` → `FooBar`.
export type Options = {
/**
Uppercase the first character: `foo-bar` → `FooBar`.
@default false
*/
readonly pascalCase?: boolean;
@default false
*/
readonly pascalCase?: boolean;
/**
Preserve the consecutive uppercase characters: `foo-BAR` → `FooBAR`.
/**
Preserve consecutive uppercase characters: `foo-BAR` → `FooBAR`.
@default false
*/
readonly preserveConsecutiveUppercase?: boolean;
@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.
/**
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.
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.
Default: The host environment’s current locale.
@example
```
import camelCase = require('camelcase');
@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[];
}
}
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[];
};
/**

@@ -51,3 +52,3 @@ Convert a dash/dot/underscore/space separated string to camelCase or PascalCase: `foo-bar` → `fooBar`.

```
import camelCase = require('camelcase');
import camelCase from 'camelcase';

@@ -99,7 +100,5 @@ camelCase('foo-bar');

*/
declare function camelcase(
export default function camelcase(
input: string | readonly string[],
options?: camelcase.Options
options?: Options
): string;
export = camelcase;

@@ -1,3 +0,1 @@

'use strict';
const UPPERCASE = /[\p{Lu}]/u;

@@ -18,13 +16,13 @@ const LOWERCASE = /[\p{Ll}]/u;

for (let i = 0; i < string.length; i++) {
const character = string[i];
for (let index = 0; index < string.length; index++) {
const character = string[index];
if (isLastCharLower && UPPERCASE.test(character)) {
string = string.slice(0, i) + '-' + string.slice(i);
string = string.slice(0, index) + '-' + string.slice(index);
isLastCharLower = false;
isLastLastCharUpper = isLastCharUpper;
isLastCharUpper = true;
i++;
index++;
} else if (isLastCharUpper && isLastLastCharUpper && LOWERCASE.test(character)) {
string = string.slice(0, i - 1) + '-' + string.slice(i - 1);
string = string.slice(0, index - 1) + '-' + string.slice(index - 1);
isLastLastCharUpper = isLastCharUpper;

@@ -57,3 +55,3 @@ isLastCharUpper = false;

const camelCase = (input, options) => {
export default function camelCase(input, options) {
if (!(typeof input === 'string' || Array.isArray(input))) {

@@ -66,3 +64,3 @@ throw new TypeError('Expected the input to be `string | string[]`');

preserveConsecutiveUppercase: false,
...options
...options,
};

@@ -82,10 +80,15 @@

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);
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);

@@ -101,9 +104,4 @@ }

input = input.replace(LEADING_SEPARATORS, '');
input = options.preserveConsecutiveUppercase ? preserveConsecutiveUppercase(input, toLowerCase) : toLowerCase(input);
if (options.preserveConsecutiveUppercase) {
input = preserveConsecutiveUppercase(input, toLowerCase);
} else {
input = toLowerCase(input);
}
if (options.pascalCase) {

@@ -114,6 +112,2 @@ 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;
}
{
"name": "camelcase",
"version": "6.3.0",
"version": "7.0.0",
"description": "Convert a dash/dot/underscore/space separated string to camelCase or PascalCase: `foo-bar` → `fooBar`",

@@ -13,4 +13,7 @@ "license": "MIT",

},
"type": "module",
"exports": "./index.js",
"types": "./index.d.ts",
"engines": {
"node": ">=10"
"node": ">=14.16"
},

@@ -41,6 +44,6 @@ "scripts": {

"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.11.0",
"xo": "^0.28.3"
"ava": "^4.3.0",
"tsd": "^0.20.0",
"xo": "^0.49.0"
}
}

@@ -11,12 +11,10 @@ # camelcase

```sh
npm install camelcase
```
$ 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');
import camelCase from 'camelcase';

@@ -94,3 +92,3 @@ camelCase('foo-bar');

Preserve the consecutive uppercase characters: `foo-BAR` → `FooBAR`.
Preserve consecutive uppercase characters: `foo-BAR` → `FooBAR`.

@@ -105,3 +103,3 @@ ##### locale

```js
const camelCase = require('camelcase');
import camelCase from 'camelcase';

@@ -124,3 +122,3 @@ camelCase('lorem-ipsum', {locale: 'en-US'});

```js
const camelCase = require('camelcase');
import camelCase from 'camelcase';

@@ -127,0 +125,0 @@ // On a platform with 'tr-TR'

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