Skip to content

snake

Convert a string to snake case

441 bytes

Usage

Given a string returns it in snake case format.

import * as
import _
_
from 'radashi'
import _
_
.
function snake(str: string, options?: {
splitOnNumber?: boolean;
}): string
export snake

Formats the given string in snake case fashion.

@seehttps://radashi.js.org/reference/string/snake

@example

snake('hello world') // => 'hello_world'
snake('one two-THREE') // => 'one_two_three'
snake('helloWorld') // => 'hello_world'

@version12.1.0

snake
('green fish blue fish') // => green_fish_blue_fish

Warning: In v11.0.0 a change was made to fix this function so that it correctly splits numbers from neighboring letters (hello5 becomes hello_5). You can opt out of this behavior and continue with the legacy style (hello5 becomes hello5) by passing the splitOnNumber options.

import _
_
.
function snake(str: string, options?: {
splitOnNumber?: boolean;
}): string
export snake

Formats the given string in snake case fashion.

@seehttps://radashi.js.org/reference/string/snake

@example

snake('hello world') // => 'hello_world'
snake('one two-THREE') // => 'one_two_three'
snake('helloWorld') // => 'hello_world'

@version12.1.0

snake
('5green fish 2blue fish') // => 5_green_fish_2_blue_fish
import _
_
.
function snake(str: string, options?: {
splitOnNumber?: boolean;
}): string
export snake

Formats the given string in snake case fashion.

@seehttps://radashi.js.org/reference/string/snake

@example

snake('hello world') // => 'hello_world'
snake('one two-THREE') // => 'one_two_three'
snake('helloWorld') // => 'hello_world'

@version12.1.0

snake
('5green fish 2blue fish', {
splitOnNumber?: boolean
splitOnNumber
: false,
}) // => 5green_fish_2blue_fish