The value to be converted to snake_cased
string
Optional
scream: booleanOptionally return the result as UpperCase (Screaming).
The snake-cased
version of the provided value
strSnakeCase(null); // "null"
strSnakeCase(undefined); // "undefined"
strSnakeCase("hello darkness"); // "hello_darkness"
strSnakeCase("hello_darkness"); // "hello_darkness"
strSnakeCase("_hello_darkness"); // "_hello_darkness"
strSnakeCase("hello-darkness"); // "hello_darkness"
strSnakeCase("-hello-darkness"); // "_hello_darkness"
strSnakeCase("hello darkness, my old friend."); // "hello_darkness_my_old_friend_"
// Use optional Scream flag
strSnakeCase("hello darkness", true); // "HELLO_DARKNESS"
strSnakeCase("hello_darkness", true); // "HELLO_DARKNESS"
strSnakeCase("_hello_darkness", true); // "_HELLO_DARKNESS"
strSnakeCase("hello-darkness", true); // "HELLO_DARKNESS"
strSnakeCase("-hello-darkness", true); // "_HELLO_DARKNESS"
strSnakeCase("hello darkness, my old friend.", true); // "HELLO_DARKNESS_MY_OLD_FRIEND_"
Convert the provided value to
snake_cased
string, you can optionally specify whther the result is all uppercased by passingtrue
as the optionalscream
argument, otherwise the entire result will be lowercased. If the value is not a string it will be converted.