From dfc248885fd2e3af99e130e54dc34f176b009915 Mon Sep 17 00:00:00 2001 From: Volkan Sen Date: Sun, 19 Jul 2020 00:17:54 +0300 Subject: [PATCH 01/16] - Add locale as new option property and pass locale parameter to related methods. - Added tests. - Updated type file and documentation. --- index.d.ts | 19 +++++++++++++++++++ index.js | 20 ++++++++++---------- index.test-d.ts | 4 ++++ test.js | 8 ++++++++ 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/index.d.ts b/index.d.ts index 51d2ba2..39e7302 100644 --- a/index.d.ts +++ b/index.d.ts @@ -6,6 +6,12 @@ declare namespace camelcase { @default false */ readonly pascalCase?: boolean; + + /** + Convert characters with given locale(s). See String.prototype.toLocaleLowerCase(). + @default undefined. Uses host's current locale when not provided. + */ + readonly locale?: string | string[]; } } @@ -51,6 +57,19 @@ camelCase(['foo', 'bar']); camelCase(['__foo__', '--bar'], {pascalCase: true}); //=> 'FooBar' + +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' + ``` */ declare function camelcase( diff --git a/index.js b/index.js index dd2c490..872615b 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ 'use strict'; -const preserveCamelCase = string => { +const preserveCamelCase = (string, locales) => { let isLastCharLower = false; let isLastCharUpper = false; let isLastLastCharUpper = false; @@ -20,9 +20,9 @@ const preserveCamelCase = string => { isLastCharUpper = false; isLastCharLower = true; } else { - isLastCharLower = character.toLocaleLowerCase() === character && character.toLocaleUpperCase() !== character; + isLastCharLower = character.toLocaleLowerCase(locales) === character && character.toLocaleUpperCase(locales) !== character; isLastLastCharUpper = isLastCharUpper; - isLastCharUpper = character.toLocaleUpperCase() === character && character.toLocaleLowerCase() !== character; + isLastCharUpper = character.toLocaleUpperCase(locales) === character && character.toLocaleLowerCase(locales) !== character; } } @@ -39,7 +39,7 @@ const camelCase = (input, options) => { ...options }; - const postProcess = x => options.pascalCase ? x.charAt(0).toLocaleUpperCase() + x.slice(1) : x; + const postProcess = x => options.pascalCase ? x.charAt(0).toLocaleUpperCase(options.locales) + x.slice(1) : x; if (Array.isArray(input)) { input = input.map(x => x.trim()) @@ -54,20 +54,20 @@ const camelCase = (input, options) => { } if (input.length === 1) { - return options.pascalCase ? input.toLocaleUpperCase() : input.toLocaleLowerCase(); + return options.pascalCase ? input.toLocaleUpperCase(options.locales) : input.toLocaleLowerCase(options.locales); } - const hasUpperCase = input !== input.toLocaleLowerCase(); + const hasUpperCase = input !== input.toLocaleLowerCase(options.locales); if (hasUpperCase) { - input = preserveCamelCase(input); + input = preserveCamelCase(input, options.locales); } input = input .replace(/^[_.\- ]+/, '') - .toLocaleLowerCase() - .replace(/[_.\- ]+([\p{Alpha}\p{N}_]|$)/gu, (_, p1) => p1.toLocaleUpperCase()) - .replace(/\d+([\p{Alpha}\p{N}_]|$)/gu, m => m.toLocaleUpperCase()); + .toLocaleLowerCase(options.locales) + .replace(/[_.\- ]+([\p{Alpha}\p{N}_]|$)/gu, (_, p1) => p1.toLocaleUpperCase(options.locales)) + .replace(/\d+([\p{Alpha}\p{N}_]|$)/gu, m => m.toLocaleUpperCase(options.locales)); return postProcess(input); }; diff --git a/index.test-d.ts b/index.test-d.ts index cc565d9..e39b067 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -3,6 +3,10 @@ import camelCase = require('.'); expectType(camelCase('foo-bar')); expectType(camelCase('розовый_пушистый_единороги')); +expectType(camelCase('Foo-Bar', {locale: ['tr']})); +expectType(camelCase('Foo-Bar', {locale: ['tr', 'TR', 'tr-TR']})); +expectType(camelCase('Foo-Bar', {pascalCase: true, locale: ['tr']})); +expectType(camelCase('Foo-Bar', {pascalCase: true, locale: ['tr', 'TR', 'tr-TR']})); expectType(camelCase('Foo-Bar', {pascalCase: true})); expectType(camelCase(['foo', 'bar'])); expectType(camelCase(['__foo__', '--bar'], {pascalCase: true})); diff --git a/test.js b/test.js index 4dea4be..5b51f0b 100644 --- a/test.js +++ b/test.js @@ -64,6 +64,10 @@ test('camelCase', t => { t.is(camelCase('桑德在这里。'), '桑德在这里。'); t.is(camelCase('桑德在这里。'), '桑德在这里。'); t.is(camelCase('桑德_在这里。'), '桑德在这里。'); + t.is(camelCase('lorem-ipsum', {locales: 'tr-TR'}), 'loremİpsum'); + t.is(camelCase('lorem-ipsum', {locales: 'en-EN'}), 'loremIpsum'); + t.is(camelCase('lorem-ipsum', {locales: ['tr', 'TR', 'tr-TR']}), 'loremİpsum'); + t.is(camelCase('lorem-ipsum', {locales: ['en-EN', 'en-GB']}), 'loremIpsum'); }); test('camelCase with pascalCase option', t => { @@ -128,6 +132,10 @@ test('camelCase with pascalCase option', t => { t.is(camelCase('РОЗОВЫЙ_ПУШИСТЫЙ-ЕДИНОРОГИ', {pascalCase: true}), 'РозовыйПушистыйЕдинороги'); t.is(camelCase('桑德在这里。', {pascalCase: true}), '桑德在这里。'); t.is(camelCase('桑德_在这里。', {pascalCase: true}), '桑德在这里。'); + t.is(camelCase('lorem-ipsum', {pascalCase: true, locales: 'tr-TR'}), 'Loremİpsum'); + t.is(camelCase('lorem-ipsum', {pascalCase: true, locales: 'en-EN'}), 'LoremIpsum'); + t.is(camelCase('lorem-ipsum', {pascalCase: true, locales: ['tr', 'TR', 'tr-TR']}), 'Loremİpsum'); + t.is(camelCase('lorem-ipsum', {pascalCase: true, locales: ['en-EN', 'en-GB']}), 'LoremIpsum'); }); test('invalid input', t => { From 358126ec01b17d15e4762d22ed886a373a1fc761 Mon Sep 17 00:00:00 2001 From: Volkan Sen Date: Sun, 19 Jul 2020 00:24:52 +0300 Subject: [PATCH 02/16] Updated readme.md with locale option. --- readme.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/readme.md b/readme.md index da76012..1fa7e6d 100644 --- a/readme.md +++ b/readme.md @@ -48,6 +48,12 @@ camelCase(['foo', 'bar']); camelCase(['__foo__', '--bar'], {pascalCase: true}); //=> 'FooBar' + +camelCase('lorem-ipsum', {locale: 'en-US'}); +//=> 'loremIpsum' + +camelCase('lorem-ipsum', {locale: 'tr-TR'}); +//=> 'loremİpsum' ``` ## API @@ -71,6 +77,13 @@ Default: `false` Uppercase the first character: `foo-bar` → `FooBar` +##### locale + +Type: `string | string[]`\ +Default: `undefined` + +Locale to be used with lowercase or uppercase conversions. + ## camelcase for enterprise Available as part of the Tidelift Subscription. From c4f6459d9aad12f2e319920a93b2c24ef4a62838 Mon Sep 17 00:00:00 2001 From: Volkan Sen Date: Sun, 19 Jul 2020 00:35:42 +0300 Subject: [PATCH 03/16] Change option locales to locale --- index.js | 20 ++++++++++---------- test.js | 16 ++++++++-------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index 872615b..3c7ae42 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ 'use strict'; -const preserveCamelCase = (string, locales) => { +const preserveCamelCase = (string, locale) => { let isLastCharLower = false; let isLastCharUpper = false; let isLastLastCharUpper = false; @@ -20,9 +20,9 @@ const preserveCamelCase = (string, locales) => { isLastCharUpper = false; isLastCharLower = true; } else { - isLastCharLower = character.toLocaleLowerCase(locales) === character && character.toLocaleUpperCase(locales) !== character; + isLastCharLower = character.toLocaleLowerCase(locale) === character && character.toLocaleUpperCase(locale) !== character; isLastLastCharUpper = isLastCharUpper; - isLastCharUpper = character.toLocaleUpperCase(locales) === character && character.toLocaleLowerCase(locales) !== character; + isLastCharUpper = character.toLocaleUpperCase(locale) === character && character.toLocaleLowerCase(locale) !== character; } } @@ -39,7 +39,7 @@ const camelCase = (input, options) => { ...options }; - const postProcess = x => options.pascalCase ? x.charAt(0).toLocaleUpperCase(options.locales) + x.slice(1) : x; + const postProcess = x => options.pascalCase ? x.charAt(0).toLocaleUpperCase(options.locale) + x.slice(1) : x; if (Array.isArray(input)) { input = input.map(x => x.trim()) @@ -54,20 +54,20 @@ const camelCase = (input, options) => { } if (input.length === 1) { - return options.pascalCase ? input.toLocaleUpperCase(options.locales) : input.toLocaleLowerCase(options.locales); + return options.pascalCase ? input.toLocaleUpperCase(options.locale) : input.toLocaleLowerCase(options.locale); } - const hasUpperCase = input !== input.toLocaleLowerCase(options.locales); + const hasUpperCase = input !== input.toLocaleLowerCase(options.locale); if (hasUpperCase) { - input = preserveCamelCase(input, options.locales); + input = preserveCamelCase(input, options.locale); } input = input .replace(/^[_.\- ]+/, '') - .toLocaleLowerCase(options.locales) - .replace(/[_.\- ]+([\p{Alpha}\p{N}_]|$)/gu, (_, p1) => p1.toLocaleUpperCase(options.locales)) - .replace(/\d+([\p{Alpha}\p{N}_]|$)/gu, m => m.toLocaleUpperCase(options.locales)); + .toLocaleLowerCase(options.locale) + .replace(/[_.\- ]+([\p{Alpha}\p{N}_]|$)/gu, (_, p1) => p1.toLocaleUpperCase(options.locale)) + .replace(/\d+([\p{Alpha}\p{N}_]|$)/gu, m => m.toLocaleUpperCase(options.locale)); return postProcess(input); }; diff --git a/test.js b/test.js index 5b51f0b..737f2b0 100644 --- a/test.js +++ b/test.js @@ -64,10 +64,10 @@ test('camelCase', t => { t.is(camelCase('桑德在这里。'), '桑德在这里。'); t.is(camelCase('桑德在这里。'), '桑德在这里。'); t.is(camelCase('桑德_在这里。'), '桑德在这里。'); - t.is(camelCase('lorem-ipsum', {locales: 'tr-TR'}), 'loremİpsum'); - t.is(camelCase('lorem-ipsum', {locales: 'en-EN'}), 'loremIpsum'); - t.is(camelCase('lorem-ipsum', {locales: ['tr', 'TR', 'tr-TR']}), 'loremİpsum'); - t.is(camelCase('lorem-ipsum', {locales: ['en-EN', 'en-GB']}), 'loremIpsum'); + t.is(camelCase('lorem-ipsum', {locale: 'tr-TR'}), 'loremİpsum'); + t.is(camelCase('lorem-ipsum', {locale: 'en-EN'}), 'loremIpsum'); + t.is(camelCase('lorem-ipsum', {locale: ['tr', 'TR', 'tr-TR']}), 'loremİpsum'); + t.is(camelCase('lorem-ipsum', {locale: ['en-EN', 'en-GB']}), 'loremIpsum'); }); test('camelCase with pascalCase option', t => { @@ -132,10 +132,10 @@ test('camelCase with pascalCase option', t => { t.is(camelCase('РОЗОВЫЙ_ПУШИСТЫЙ-ЕДИНОРОГИ', {pascalCase: true}), 'РозовыйПушистыйЕдинороги'); t.is(camelCase('桑德在这里。', {pascalCase: true}), '桑德在这里。'); t.is(camelCase('桑德_在这里。', {pascalCase: true}), '桑德在这里。'); - t.is(camelCase('lorem-ipsum', {pascalCase: true, locales: 'tr-TR'}), 'Loremİpsum'); - t.is(camelCase('lorem-ipsum', {pascalCase: true, locales: 'en-EN'}), 'LoremIpsum'); - t.is(camelCase('lorem-ipsum', {pascalCase: true, locales: ['tr', 'TR', 'tr-TR']}), 'Loremİpsum'); - t.is(camelCase('lorem-ipsum', {pascalCase: true, locales: ['en-EN', 'en-GB']}), 'LoremIpsum'); + t.is(camelCase('lorem-ipsum', {pascalCase: true, locale: 'tr-TR'}), 'Loremİpsum'); + t.is(camelCase('lorem-ipsum', {pascalCase: true, locale: 'en-EN'}), 'LoremIpsum'); + t.is(camelCase('lorem-ipsum', {pascalCase: true, locale: ['tr', 'TR', 'tr-TR']}), 'Loremİpsum'); + t.is(camelCase('lorem-ipsum', {pascalCase: true, locale: ['en-EN', 'en-GB']}), 'LoremIpsum'); }); test('invalid input', t => { From 676fa8b7e314be83b699b11a25389b917afe9432 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 20 Jul 2020 06:44:06 +0800 Subject: [PATCH 04/16] Update index.d.ts --- index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index 39e7302..2bfe035 100644 --- a/index.d.ts +++ b/index.d.ts @@ -9,9 +9,10 @@ declare namespace camelcase { /** Convert characters with given locale(s). See String.prototype.toLocaleLowerCase(). + @default undefined. Uses host's current locale when not provided. - */ - readonly locale?: string | string[]; + */ + readonly locale?: string | readonly string[]; } } @@ -69,7 +70,6 @@ camelCase('lorem-ipsum', {locale: ['en-US', 'en-GB]}); camelCase('lorem-ipsum', {locale: ['tr', 'TR', 'tr-TR']}); //=> 'loremİpsum' - ``` */ declare function camelcase( From 9820e20929a4b2240e58cff30c2c941859426652 Mon Sep 17 00:00:00 2001 From: Volkan Sen Date: Mon, 20 Jul 2020 20:43:56 +0300 Subject: [PATCH 05/16] New test for 'locale' option' --- test.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/test.js b/test.js index 737f2b0..6de410c 100644 --- a/test.js +++ b/test.js @@ -64,10 +64,6 @@ test('camelCase', t => { t.is(camelCase('桑德在这里。'), '桑德在这里。'); t.is(camelCase('桑德在这里。'), '桑德在这里。'); t.is(camelCase('桑德_在这里。'), '桑德在这里。'); - t.is(camelCase('lorem-ipsum', {locale: 'tr-TR'}), 'loremİpsum'); - t.is(camelCase('lorem-ipsum', {locale: 'en-EN'}), 'loremIpsum'); - t.is(camelCase('lorem-ipsum', {locale: ['tr', 'TR', 'tr-TR']}), 'loremİpsum'); - t.is(camelCase('lorem-ipsum', {locale: ['en-EN', 'en-GB']}), 'loremIpsum'); }); test('camelCase with pascalCase option', t => { @@ -132,10 +128,17 @@ test('camelCase with pascalCase option', t => { t.is(camelCase('РОЗОВЫЙ_ПУШИСТЫЙ-ЕДИНОРОГИ', {pascalCase: true}), 'РозовыйПушистыйЕдинороги'); t.is(camelCase('桑德在这里。', {pascalCase: true}), '桑德在这里。'); t.is(camelCase('桑德_在这里。', {pascalCase: true}), '桑德在这里。'); - t.is(camelCase('lorem-ipsum', {pascalCase: true, locale: 'tr-TR'}), 'Loremİpsum'); - t.is(camelCase('lorem-ipsum', {pascalCase: true, locale: 'en-EN'}), 'LoremIpsum'); - t.is(camelCase('lorem-ipsum', {pascalCase: true, locale: ['tr', 'TR', 'tr-TR']}), 'Loremİpsum'); - t.is(camelCase('lorem-ipsum', {pascalCase: true, locale: ['en-EN', 'en-GB']}), 'LoremIpsum'); +}); + +test('camelCase with locale option', t => { + t.is(camelCase('lorem-ipsum', {locale: 'tr-TR'}), 'loremİpsum'); + t.is(camelCase('lorem-ipsum', {locale: 'en-EN'}), 'loremIpsum'); + t.is(camelCase('lorem-ipsum', {locale: ['tr', 'TR', 'tr-TR']}), 'loremİpsum'); + t.is(camelCase('lorem-ipsum', {locale: ['en-EN', 'en-GB']}), 'loremIpsum'); + t.is(camelCase('ipsum-dolor', {pascalCase: true, locale: 'tr-TR'}), 'İpsumDolor'); + t.is(camelCase('ipsum-dolor', {pascalCase: true, locale: 'en-EN'}), 'IpsumDolor'); + t.is(camelCase('ipsum-dolor', {pascalCase: true, locale: ['tr', 'TR', 'tr-TR']}), 'İpsumDolor'); + t.is(camelCase('ipsum-dolor', {pascalCase: true, locale: ['en-EN', 'en-GB']}), 'IpsumDolor'); }); test('invalid input', t => { From 68491de16d938a74c9a3f6de0b39939fc0bc79f2 Mon Sep 17 00:00:00 2001 From: Volkan Sen Date: Mon, 20 Jul 2020 23:15:51 +0300 Subject: [PATCH 06/16] Enchanced 'locale' option documentation in readme.md --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 1fa7e6d..1a32e5a 100644 --- a/readme.md +++ b/readme.md @@ -80,9 +80,9 @@ Uppercase the first character: `foo-bar` → `FooBar` ##### locale Type: `string | string[]`\ -Default: `undefined` +Default: The host environment’s current locale -Locale to be used with lowercase or uppercase conversions. +*From `String.prototype.toLocaleUpperCase()`*: 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 default locale is the host environment’s current locale. ## camelcase for enterprise From ab02cd3eeaaa67648e6d1a3ea38b76e4b09c0658 Mon Sep 17 00:00:00 2001 From: Volkan Sen Date: Mon, 20 Jul 2020 23:16:30 +0300 Subject: [PATCH 07/16] Removed excessive examples. --- index.d.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/index.d.ts b/index.d.ts index 2bfe035..30644af 100644 --- a/index.d.ts +++ b/index.d.ts @@ -61,15 +61,6 @@ camelCase(['__foo__', '--bar'], {pascalCase: true}); 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' ``` */ declare function camelcase( From 54d27cebf6495d1a6f5d8ac4eb09e75a29c7a474 Mon Sep 17 00:00:00 2001 From: Volkan Sen Date: Tue, 21 Jul 2020 11:27:11 +0300 Subject: [PATCH 08/16] Added examples about 'locale' usage. --- readme.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index 1a32e5a..5b7033a 100644 --- a/readme.md +++ b/readme.md @@ -51,9 +51,6 @@ camelCase(['__foo__', '--bar'], {pascalCase: true}); camelCase('lorem-ipsum', {locale: 'en-US'}); //=> 'loremIpsum' - -camelCase('lorem-ipsum', {locale: 'tr-TR'}); -//=> 'loremİpsum' ``` ## API @@ -84,6 +81,20 @@ Default: The host environment’s current locale *From `String.prototype.toLocaleUpperCase()`*: 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 default locale is the host environment’s current locale. +```js +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' +``` + ## camelcase for enterprise Available as part of the Tidelift Subscription. From dcef5caf800f20ff42436c4ddd47428c30430ebf Mon Sep 17 00:00:00 2001 From: Volkan Sen Date: Sat, 8 Aug 2020 13:27:26 +0300 Subject: [PATCH 09/16] Synced locale description in index.d.ts with readme.md --- index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index 30644af..f5dfef3 100644 --- a/index.d.ts +++ b/index.d.ts @@ -7,10 +7,10 @@ declare namespace camelcase { */ readonly pascalCase?: boolean; - /** - Convert characters with given locale(s). See String.prototype.toLocaleLowerCase(). + /** + From `String.prototype.toLocaleUpperCase()`: 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 default locale is the host environment’s current locale. - @default undefined. Uses host's current locale when not provided. + @default The host environment’s current locale */ readonly locale?: string | readonly string[]; } From 1f729e2301305b5d40fbbda023d9bd0949f4cf5c Mon Sep 17 00:00:00 2001 From: Volkan Sen Date: Sat, 8 Aug 2020 13:32:05 +0300 Subject: [PATCH 10/16] Removed trailing space. --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index f5dfef3..0e34179 100644 --- a/index.d.ts +++ b/index.d.ts @@ -7,7 +7,7 @@ declare namespace camelcase { */ readonly pascalCase?: boolean; - /** + /** From `String.prototype.toLocaleUpperCase()`: 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 default locale is the host environment’s current locale. @default The host environment’s current locale From 1eef68648fae794b6fdbaa65894fe94110412b32 Mon Sep 17 00:00:00 2001 From: Volkan Sen Date: Tue, 11 Aug 2020 08:07:55 +0300 Subject: [PATCH 11/16] - Removed reference to 'String.prototype.toLocaleUpperCase()' - Removed duplicate specification for default. --- index.d.ts | 2 +- readme.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 0e34179..2b1240e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -8,7 +8,7 @@ declare namespace camelcase { readonly pascalCase?: boolean; /** - From `String.prototype.toLocaleUpperCase()`: 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 default locale is 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. @default The host environment’s current locale */ diff --git a/readme.md b/readme.md index 5b7033a..ad3e2cb 100644 --- a/readme.md +++ b/readme.md @@ -79,7 +79,7 @@ Uppercase the first character: `foo-bar` → `FooBar` Type: `string | string[]`\ Default: The host environment’s current locale -*From `String.prototype.toLocaleUpperCase()`*: 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 default locale is 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. ```js camelCase('lorem-ipsum', {locale: 'en-US'}); From 928b8c46cfea7930b315be35e8917a4f4c09eed1 Mon Sep 17 00:00:00 2001 From: Volkan Sen Date: Tue, 29 Sep 2020 16:09:11 +0300 Subject: [PATCH 12/16] - Added 4 samples to `locale` parameter docs. - Fixed incorrect @default usage. --- index.d.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 2b1240e..4678ff2 100644 --- a/index.d.ts +++ b/index.d.ts @@ -9,8 +9,23 @@ declare namespace camelcase { /** 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. + + Default: The host environment’s current locale - @default The host environment’s current locale + @example + ```js + 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?: string | readonly string[]; } From 20a0f6b07cfb1b9c4df2e436fda8753ad8375e5a Mon Sep 17 00:00:00 2001 From: Volkan Sen Date: Tue, 29 Sep 2020 16:17:50 +0300 Subject: [PATCH 13/16] Fixed trailing space problem. --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 4678ff2..711ad64 100644 --- a/index.d.ts +++ b/index.d.ts @@ -9,7 +9,7 @@ declare namespace camelcase { /** 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. - + Default: The host environment’s current locale @example From d2514638692930a72f87b24a79032d0666849eba Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 10 Oct 2020 18:57:59 +0200 Subject: [PATCH 14/16] Update index.d.ts --- index.d.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 711ad64..21baed2 100644 --- a/index.d.ts +++ b/index.d.ts @@ -8,12 +8,14 @@ declare namespace camelcase { readonly pascalCase?: 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. Default: The host environment’s current locale @example - ```js + ``` + import camelCase = require('camelcase'); + camelCase('lorem-ipsum', {locale: 'en-US'}); //=> 'loremIpsum' From 92c518a204f4faebb9d556c8d7a59b8405a89bf4 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 10 Oct 2020 18:59:28 +0200 Subject: [PATCH 15/16] Update readme.md --- readme.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index ad3e2cb..c9b4e08 100644 --- a/readme.md +++ b/readme.md @@ -77,11 +77,13 @@ Uppercase the first character: `foo-bar` → `FooBar` ##### locale Type: `string | string[]`\ -Default: The host environment’s current locale +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. +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. ```js +const camelCase = require('camelcase'); + camelCase('lorem-ipsum', {locale: 'en-US'}); //=> 'loremIpsum' From 962383ea349ec3811b1f83ea78e8cd54495fb368 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 10 Oct 2020 18:59:47 +0200 Subject: [PATCH 16/16] Update index.d.ts --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 21baed2..90a208a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -10,7 +10,7 @@ declare namespace camelcase { /** 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. - Default: The host environment’s current locale + Default: The host environment’s current locale. @example ```