8.0.0 • Published 1 year ago

camelcase v8.0.0

Weekly downloads
54,032,044
License
MIT
Repository
github
Last release
1 year ago

camelcase

Convert a dash/dot/underscore/space separated string to camelCase or PascalCase: foo-barfooBar

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

Usage

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[]

The string to convert to camel case.

options

Type: object

pascalCase

Type: boolean\ Default: false

Uppercase the first character: foo-barFooBar

preserveConsecutiveUppercase

Type: boolean\ Default: false

Preserve consecutive uppercase characters: foo-BARFooBAR.

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.

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 algorithm:

import camelCase from 'camelcase';

// On a platform with 'tr-TR'

camelCase('lorem-ipsum');
//=> 'loremİpsum'

camelCase('lorem-ipsum', {locale: false});
//=> 'loremIpsum'

Related

pascalcase@ngneat/svg-generatorcamelcase-keysjest-validateboxen@istanbuljs/load-nyc-configresolve-url-loader@svgr/coreyargs-unparserreact-scripts@vue/babel-sugar-v-model@vue/babel-sugar-v-onelcia-novaui@bsolution/dev@bsolution/fast@bsolution/scripts@microsoft/bf-qnamaker@megasaur/create@proteria/react-scripts@neuvernetzung/cms-types@zhouhaifei/test@savaleukhin/react-scripts@talesman/react-scripts@hyunggyujang/typechain-polkadot@hyunggyujang/typechain-polkadot-parser@hyunggyujang/typechain-typesarchetype-librarycarrier_anal@directus-asolole/apicbbpa-clientcc-gram-democompat-ui-cli@thingspro-cloud/sdkeasy-select-rntailwind-css-go-generatereact-wind-uichinjowwchinjowsmart-input-demovuedragdropuploadimagesbyteplayerkstick-react-scripts@care-for/yargs-unparserreact-native-bluetooth2killi8n-react-native-fast-imagewatsize-test-react-scriptsopenapi-typescript-node-merged-latest1@psimk/react-scriptsglobal-martcomatch-mvp-debugging@darapti/darapti-react-scriptsswitch_mostqroda-sdkqroda-sdk-v1metaliquid-react-scriptsrockywu-ui@tradeling/gen-sdk@tomas2d/react-scriptsjbojcic-react-scriptsupnext-apps-reader@jvhellemondt/custom-react-scripts@st4rfox/electron-scriptssv-component-librarysv-component-library-1sv-component-library-2@thuanpq/airvert-ui@xinyifly/react-scriptsmasterodin-cloud-sdk-core@lifesum/cms-componentsdvlsc-t1moco-forms-zmio-cli-service@katalabut/react-scriptsandculturecode-react-scriptswebeetle-react-scriptsyadong-react@agney/react-scripts-tailwind@elnk/core-xmlczackmoreplay-react-scriptsgooapps-react-opsthefarm-react-scripts@wywk/headquaters-marketing-eventconcord-ui-plugin-react-scriptssebrae-boilerplatesebrae-react-scripts@cloudhuset/zd-app-react-scriptstyped-image-modulesidelic-react-scriptstest-app-6test-app-7tm-components-test@jvhellemondt/react-scriptsearthling-interactive-react-scripts@borie88/lucidrn-send-smshoogo-niuyapingreact-epic-image-slidersocial-clireece-feature-togglepejann-scripts
8.0.0

1 year ago

7.0.1

2 years ago

7.0.0

2 years ago

6.3.0

3 years ago

6.2.1

3 years ago

6.2.0

4 years ago

6.1.0

4 years ago

6.0.0

5 years ago

5.3.1

6 years ago

5.3.0

6 years ago

5.2.0

6 years ago

5.1.0

6 years ago

5.0.0

7 years ago

4.1.0

8 years ago

4.0.0

8 years ago

3.0.0

8 years ago

2.1.1

9 years ago

2.1.0

9 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.1.0

9 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.0.0

11 years ago