Function strSnakeCase

  • Convert the provided value to snake_cased string, you can optionally specify whther the result is all uppercased by passing true as the optional scream argument, otherwise the entire result will be lowercased. If the value is not a string it will be converted.

    Type Parameters

    • T

    Parameters

    • value: T

      The value to be converted to snake_cased string

    • Optionalscream: boolean

      Optionally return the result as UpperCase (Screaming).

    Returns string

    The snake-cased version of the provided value

    0.9.0

    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_"