Snake
Overview
Snake converts to snake_case.
If you are coming from Node.js, the closest pattern is snake_case(s).
Signature
go
func Snake(s string) stringCompare: Node.js · Standard Go · gox
js
_.snakeCase('FooBar');go
s = strings.ToLower(strings.ReplaceAll(name, " ", "_"))go
import "github.com/sahilkhaire/gox/str"
s := str.Snake("FooBar")Example
go
import "github.com/sahilkhaire/gox/str"
s := str.Snake("FooBar")Tips
Import github.com/sahilkhaire/gox/str and call Snake directly. See the comparison below for the standard library equivalent.
Standard library alternative
Use the standard library directly:
go
s = strings.ToLower(strings.ReplaceAll(name, " ", "_"))