Methods
(static) capitalize(chunk) → {string}
Capitalizes the first character of a string.
Parameters:
| Name | Type | Description |
|---|---|---|
chunk |
string | The string to capitalize |
Returns:
The capitalized string
- Type
- string
Example
capitalize('hello') // => 'Hello'
(static) fromCamelCase(str, glueopt) → {string}
Converts a camelCase string to a delimited format.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
str |
string | The camelCase string to convert |
||
glue |
string |
<optional> |
'_' | The delimiter to use |
Returns:
The delimited string in lowercase
- Type
- string
Example
fromCamelCase('helloWorld') // => 'hello_world'
fromCamelCase('helloWorld', '-') // => 'hello-world'
(static) pluralToSingular(str) → {string}
Converts a plural word to its singular form (basic English rules).
Parameters:
| Name | Type | Description |
|---|---|---|
str |
string | The plural word |
Returns:
The singular form
- Type
- string
Example
pluralToSingular('categories') // => 'category'
pluralToSingular('users') // => 'user'
(static) singularToPlural(str) → {string}
Converts a singular word to its plural form (basic English rules).
Parameters:
| Name | Type | Description |
|---|---|---|
str |
string | The singular word |
Returns:
The plural form
- Type
- string
Example
singularToPlural('category') // => 'categories'
singularToPlural('user') // => 'users'
(static) toCamelCase(str, glueopt) → {string}
Converts a string to camelCase from a delimited format.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
str |
string | The string to convert |
||
glue |
string |
<optional> |
'_' | The delimiter to split on |
Returns:
The camelCase string
- Type
- string
Example
toCamelCase('hello_world') // => 'helloWorld'
toCamelCase('hello-world', '-') // => 'helloWorld'
(static) toDocumentId(str, glueopt, suffixopt, prefixopt) → {string}
Converts a string to a document ID format (typically used for database foreign keys).
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
str |
string | The string to convert |
||
glue |
string |
<optional> |
'_' | The delimiter in the input string |
suffix |
string |
<optional> |
'Id' | The suffix to append |
prefix |
string |
<optional> |
'' | The prefix to prepend |
Returns:
The document ID string
- Type
- string
Example
toDocumentId('user_roles') // => 'userRoleId'
toDocumentId('categories', '_', 'ID', 'ref') // => 'refCategoryID'