UNPKG

2.31 kBTypeScriptView Raw
1declare namespace camelcase {
2 interface Options {
3 /**
4 Uppercase the first character: `foo-bar` → `FooBar`.
5
6 @default false
7 */
8 readonly pascalCase?: boolean;
9
10 /**
11 Preserve the consecutive uppercase characters: `foo-BAR` → `FooBAR`.
12
13 @default false
14 */
15 readonly preserveConsecutiveUppercase?: boolean;
16
17 /**
18 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.
19
20 Default: The host environment’s current locale.
21
22 @example
23 ```
24 import camelCase = require('camelcase');
25
26 camelCase('lorem-ipsum', {locale: 'en-US'});
27 //=> 'loremIpsum'
28 camelCase('lorem-ipsum', {locale: 'tr-TR'});
29 //=> 'loremİpsum'
30 camelCase('lorem-ipsum', {locale: ['en-US', 'en-GB']});
31 //=> 'loremIpsum'
32 camelCase('lorem-ipsum', {locale: ['tr', 'TR', 'tr-TR']});
33 //=> 'loremİpsum'
34 ```
35 */
36 readonly locale?: string | readonly string[];
37 }
38}
39
40/**
41Convert a dash/dot/underscore/space separated string to camelCase or PascalCase: `foo-bar` → `fooBar`.
42
43Correctly handles Unicode strings.
44
45@param input - String to convert to camel case.
46
47@example
48```
49import camelCase = require('camelcase');
50
51camelCase('foo-bar');
52//=> 'fooBar'
53
54camelCase('foo_bar');
55//=> 'fooBar'
56
57camelCase('Foo-Bar');
58//=> 'fooBar'
59
60camelCase('розовый_пушистый_единороги');
61//=> 'розовыйПушистыйЕдинороги'
62
63camelCase('Foo-Bar', {pascalCase: true});
64//=> 'FooBar'
65
66camelCase('--foo.bar', {pascalCase: false});
67//=> 'fooBar'
68
69camelCase('Foo-BAR', {preserveConsecutiveUppercase: true});
70//=> 'fooBAR'
71
72camelCase('fooBAR', {pascalCase: true, preserveConsecutiveUppercase: true}));
73//=> 'FooBAR'
74
75camelCase('foo bar');
76//=> 'fooBar'
77
78console.log(process.argv[3]);
79//=> '--foo-bar'
80camelCase(process.argv[3]);
81//=> 'fooBar'
82
83camelCase(['foo', 'bar']);
84//=> 'fooBar'
85
86camelCase(['__foo__', '--bar'], {pascalCase: true});
87//=> 'FooBar'
88
89camelCase(['foo', 'BAR'], {pascalCase: true, preserveConsecutiveUppercase: true})
90//=> 'FooBAR'
91
92camelCase('lorem-ipsum', {locale: 'en-US'});
93//=> 'loremIpsum'
94```
95*/
96declare function camelcase(
97 input: string | readonly string[],
98 options?: camelcase.Options
99): string;
100
101export = camelcase;