Skip to content

Commit

Permalink
Improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Sep 29, 2023
1 parent 01954f0 commit 2f1e273
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 46 deletions.
65 changes: 41 additions & 24 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,43 @@
export type Options = {
/**
Uppercase the first character: `foo-bar` → `FooBar`.
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`.
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;

/**
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
Expand All @@ -36,6 +56,21 @@ export type Options = {
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[];
};
Expand Down Expand Up @@ -63,18 +98,6 @@ camelCase('Foo-Bar');
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'
Expand All @@ -86,14 +109,8 @@ camelCase(process.argv[3]);
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'
camelCase(['__foo__', '--bar']);
//=> 'fooBar'
```
*/
export default function camelcase(
Expand Down
46 changes: 24 additions & 22 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,6 @@ camelCase('Foo-Bar');
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'

Expand All @@ -52,14 +40,8 @@ camelCase(process.argv[3]);
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'
camelCase(['__foo__', '--bar']);
//=> 'fooBar'
```

## API
Expand All @@ -83,12 +65,32 @@ 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`.
Preserve consecutive uppercase characters: `foo-BAR``FooBAR`

```js
import camelCase from 'camelcase';

camelCase('foo-BAR', {preserveConsecutiveUppercase: true});
//=> 'fooBAR'

camelCase('foo-BAR', {preserveConsecutiveUppercase: false});
//=> 'fooBar'
````

##### locale

Expand Down Expand Up @@ -118,7 +120,7 @@ Setting `locale: false` ignores the platform locale and uses the [Unicode Defaul
```js
import camelCase from 'camelcase';
// On a platform with 'tr-TR'
// On a platform with `tr-TR`.
camelCase('lorem-ipsum');
//=> 'loremİpsum'
Expand Down

0 comments on commit 2f1e273

Please sign in to comment.