The value to be converted to snake_cased string
Optionalscream: boolean
Optionally 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_"
strSnakeCase("XMLHttpRequest"); // "xml_http_request"
strSnakeCase("O'Brien & Sons, Ltd."); // "o_brien_sons_ltd_"
// 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_"
strSnakeCase("maxSafeInteger", true); // "MAX_SAFE_INTEGER"
Convert the provided value to
snake_casedstring, you can optionally specify whther the result is all uppercased by passingtrueas the optionalscreamargument, otherwise the entire result will be lowercased.Words are detected using the same rules as strKebabCase, and are joined with a single
_. Leading and trailing whitespace is removed, any other leading or trailing separators are replaced with a single_so the conversion is reversible with strKebabCase (eg."-a-b-"to"_a_b_"and back to"-a-b-"). If the value is not a string it will be converted.