Functions to change string casing
Methods
(static) camelCase(subject, localeopt) → {string}
Converts subject
to camelCase.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
subject |
string | The string to camelCase |
||
locale |
string | Array.<string> |
<optional> |
en-US | The locale or locales to use for capitalization |
- Since:
- 0.0.1
Throws:
-
-
if locale is not a valid language tag
- Type
- RangeError
-
-
-
if an array element is not a string
- Type
- TypeError
-
Returns:
the camelCased string with non-word characters stripped out
- Type
- string
Example
camelCase("bird flight")
// => "birdFlight"
camelCase("this_is_a_string")
// => "thisIsAString"
camelCase(" _-It is istanbul not constantinople-_ ", "TR")
// => "itİsİstanbulNotConstantinople"
(static) capitalize(subject, optionsopt) → {string}
Capitalizes the first letter of a string. If lower is true, downcases the rest of the string. If all is true, all words in the string will be capitalized. Use the locale parameter to set the locale for casing the string.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
subject |
string | String to capitalize |
|||||||||||||||||||||
options |
Object |
<optional> |
Optional parameters Properties
|
- Since:
- 0.0.1
Throws:
-
-
if locale is not a valid language tag
- Type
- RangeError
-
-
-
if an array element in the locale param is not a string
- Type
- TypeError
-
Returns:
- Type
- string
Example
capitalize("thIs Is a String to CAPITALIZE")
// => "ThIs Is a String to CAPITALIZE"
capitalize("thIs Is a String to CAPITALIZE", { lower: true })
// => "This is a string to capitalize"
capitalize("thIs Is a String to CAPITALIZE", { lower: true, all: true })
// => "This Is A String To Capitalize"
capitalize("istanbul", { locale: "TR" })
// => İstanbul
(static) decapitalize(subject, optionsopt) → {string}
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
subject |
string | String to decapitalize |
|||||||||||||||||||||
options |
Object |
<optional> |
Optional parameters Properties
|
- Since:
- 0.0.1
Throws:
-
-
if locale is not a valid language tag
- Type
- RangeError
-
-
-
if an array element in the local param is not a string
- Type
- TypeError
-
Returns:
- Type
- string
Example
decapitalize("THis IS A String To DeCapitalize")
// => "tHis IS A String To DeCapitalize"
decapitalize("THis IS A String To DeCapitalize", { lower: true })
// => "this is a string To decapitalize"
decapitalize("THIS IS A STRING TO DECAPITALIZE", { all: true })
// => "tHIS iS a sTRING tO dECAPITALIZE"
decapitalize("İstanbul", { locale: "TR" })
// => "istanbul"
(static) downcase(subject, locale)
Convert a string to lowercase based on locale information
Parameters:
Name | Type | Description |
---|---|---|
subject |
string | String to downcase |
locale |
string | Array.<string> | Locale information or an array of locales |
- Since:
- 0.0.1
Throws:
-
-
if locale is not a valid language tag
- Type
- RangeError
-
-
-
if an array element in the locale param is not a string
- Type
- TypeError
-
Example
downcase("This IS A StRiNg")
// => "this is a string"
downcase("İSTANBUL")
// => "i̇stanbul"
(static) pascalCase(subject) → {string}
Convert a string to PascalCase
Parameters:
Name | Type | Description |
---|---|---|
subject |
string | The string to convert to PascalCase |
- Since:
- 0.0.1
Returns:
- Type
- string
Example
pascalCase("this IS some TEXT")
// => "ThisIsSomeText"
(static) snakeCase(subject, param1, A) → {string}
Convert a string to upper or lower snake_case
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
subject |
string | The string to convert |
||||||
param1 |
Object | Options Properties
|
||||||
A |
string | Array.<string> | locale string or array of locales |
- Since:
- 0.0.1
Throws:
-
-
if locale is not a valid language tag
- Type
- RangeError
-
-
-
if an array element in the locale param is not a string
- Type
- TypeError
-
Returns:
- Type
- string
Example
snakeCase("This is a string")
// => "this_is_a_string"
snakeCase("thisIsAString", { upper: true })
// => "THIS_IS_A_STRING"