Converts a string to snake_case.
This function converts a string to kebab-case, which is a naming convention where multiple words are joined together with underscores (_) and all characters are lowercase.
Converting a string with spaces to snake_case:
toSnakeCase('hello world')// => { ok: true, value: 'hello_world' } Copy
toSnakeCase('hello world')// => { ok: true, value: 'hello_world' }
Converting a string with hyphens to snake_case:
toSnakeCase('fooBarBaz')// => { ok: true, value: 'foo_bar_baz' } Copy
toSnakeCase('fooBarBaz')// => { ok: true, value: 'foo_bar_baz' }
Handling non-string input:
toSnakeCase(42)// => { ok: false, error: Error('[strings.toSnakeCase] Expected string value as input') } Copy
toSnakeCase(42)// => { ok: false, error: Error('[strings.toSnakeCase] Expected string value as input') }
The input string to convert.
A Result containing the converted string on success, or an Error object if the provided input is not a string.
Result
Error
Generated using TypeDoc v0.24.7
Converts a string to snake_case.
Remarks
This function converts a string to kebab-case, which is a naming convention where multiple words are joined together with underscores (_) and all characters are lowercase.
Example
Converting a string with spaces to snake_case:
Example
Converting a string with hyphens to snake_case:
Example
Handling non-string input: