case

    String case conversion utility for MoonBit

    case
    string
    camelCase
    snake_case
    kebab-case
    PascalCase
    conversion
    utility
    Download zip
    Author
    Version
    0.2.2
    License
    MIT
    Last updated
    3 months ago
    Downloads
    5K

    #justjavac/case

    CI coverage

    String case conversion helpers for MoonBit.

    #Common conversions

    ///|
    test "common conversions" {
    assert_eq(@case.camel_case("hello world"), "helloWorld")
    assert_eq(@case.pascal_case("hello world"), "HelloWorld")
    assert_eq(@case.snake_case("hello world"), "hello_world")
    assert_eq(@case.kebab_case("hello world"), "hello-world")
    assert_eq(@case.constant_case("hello world"), "HELLO_WORLD")
    assert_eq(@case.flat_case("hello world"), "helloworld")
    assert_eq(@case.upper_flat_case("hello world"), "HELLOWORLD")
    assert_eq(@case.cobol_case("hello world"), "HELLO-WORLD")
    assert_eq(@case.ada_case("hello world"), "Hello_World")
    }

    ada_case

    fn ada_case(text : String) -> String

    Convert a string to Ada_Case.

    Each word is capitalized and joined with underscores, which matches naming styles used in Ada code and some generated identifiers.

    Example

    test "ada_case doc example" {
    assert_eq(ada_case("hello world"), "Hello_World")
    assert_eq(ada_case("test123value"), "Test_123_Value")
    assert_eq(ada_case(""), "")
    }

    alternating_case

    fn alternating_case(text : String) -> String

    Convert a string to alternating case.

    Letters are rewritten one by one as lower, upper, lower, upper, while separators and digits stay unchanged and do not reset the alternation.

    Example

    test "alternating_case doc example" {
    assert_eq(alternating_case("hello world"), "hElLo WoRlD")
    assert_eq(alternating_case("hello123world"), "hElLo123WoRlD")
    assert_eq(alternating_case(""), "")
    }

    camel_case

    fn camel_case(text : String) -> String

    Convert a string to camelCase.

    Word boundaries are detected from separators, case transitions, and letter-digit boundaries before the result is joined without separators.

    Example

    test "camel_case doc example" {
    assert_eq(camel_case("hello world"), "helloWorld")
    assert_eq(camel_case("XMLHttpRequest"), "xmlHttpRequest")
    assert_eq(camel_case("test123value"), "test123Value")
    }

    capital_case

    fn capital_case(text : String) -> String

    Convert a string to Capital Case.

    Each detected word is lowercased first and then capitalized so the output uses spaces between words and a stable presentation style.

    Example

    test "capital_case doc example" {
    assert_eq(capital_case("hello_world"), "Hello World")
    assert_eq(capital_case("XMLHttpRequest"), "Xml Http Request")
    assert_eq(capital_case(""), "")
    }

    cobol_case

    fn cobol_case(text : String) -> String

    Convert a string to COBOL-CASE.

    This is the uppercased form of kebab-case, commonly seen in older tooling, configuration formats, and integration layers.

    Example

    test "cobol_case doc example" {
    assert_eq(cobol_case("hello world"), "HELLO-WORLD")
    assert_eq(cobol_case("XMLHttpRequest"), "XML-HTTP-REQUEST")
    assert_eq(cobol_case(""), "")
    }

    constant_case

    fn constant_case(text : String) -> String

    Convert a string to CONSTANT_CASE.

    This is the uppercased form of snake_case, which is useful for constant names, environment variables, and similar identifier styles.

    Example

    test "constant_case doc example" {
    assert_eq(constant_case("hello world"), "HELLO_WORLD")
    assert_eq(constant_case("iPhone-App"), "I_PHONE_APP")
    assert_eq(constant_case(""), "")
    }

    dot_case

    fn dot_case(text : String) -> String

    Convert a string to dot.case.

    Detected words are lowercased and joined with periods, which is handy for configuration keys, namespaces, and metric names.

    Example

    test "dot_case doc example" {
    assert_eq(dot_case("hello world"), "hello.world")
    assert_eq(dot_case("databaseConnectionString"), "database.connection.string")
    assert_eq(dot_case(""), "")
    }

    flat_case

    fn flat_case(text : String) -> String

    Convert a string to flatcase.

    Lowercased words are joined without separators, which is useful when a compact identifier should discard original boundaries.

    Example

    test "flat_case doc example" {
    assert_eq(flat_case("hello world"), "helloworld")
    assert_eq(flat_case("test123value"), "test123value")
    assert_eq(flat_case(""), "")
    }

    kebab_case

    fn kebab_case(text : String) -> String

    Convert a string to kebab-case.

    The result uses lowercase words separated by hyphens, making it a good fit for URLs, slugs, and CLI-friendly identifiers.

    Example

    test "kebab_case doc example" {
    assert_eq(kebab_case("hello world"), "hello-world")
    assert_eq(kebab_case("XMLHttpRequest"), "xml-http-request")
    assert_eq(kebab_case(""), "")
    }

    no_case

    fn no_case(text : String) -> String

    Convert a string to space-separated lowercase text.

    This is the normalized representation used internally by several case converters when separators and original casing should be discarded.

    Example

    test "no_case doc example" {
    assert_eq(no_case("HelloWorld"), "hello world")
    assert_eq(no_case("test123value"), "test 123 value")
    assert_eq(no_case(""), "")
    }

    pascal_case

    fn pascal_case(text : String) -> String

    Convert a string to PascalCase.

    Every detected word is capitalized and concatenated, which makes the result suitable for type names and other UpperCamelCase identifiers.

    Example

    test "pascal_case doc example" {
    assert_eq(pascal_case("hello world"), "HelloWorld")
    assert_eq(pascal_case("test123value"), "Test123Value")
    assert_eq(pascal_case(""), "")
    }

    path_case

    fn path_case(text : String) -> String

    Convert a string to path/case.

    Lowercase words are joined with /, which is useful when mapping names to route segments or hierarchical resource paths.

    Example

    test "path_case doc example" {
    assert_eq(path_case("hello world"), "hello/world")
    assert_eq(path_case("XMLHttpRequest"), "xml/http/request")
    assert_eq(path_case(""), "")
    }

    reverse_case

    fn reverse_case(text : String) -> String

    Reverse the characters in a string.

    The transformation keeps every character exactly as-is and only changes the order, so casing and separators are preserved in reverse.

    Example

    test "reverse_case doc example" {
    assert_eq(reverse_case("hello"), "olleh")
    assert_eq(reverse_case("Test123"), "321tseT")
    assert_eq(reverse_case(""), "")
    }

    sentence_case

    fn sentence_case(text : String) -> String

    Convert a string to sentence case.

    The first word is capitalized, later words are lowercased, and words are rejoined with spaces for plain-language display.

    Example

    test "sentence_case doc example" {
    assert_eq(sentence_case("hello_world"), "Hello world")
    assert_eq(sentence_case("XMLHttpRequest"), "Xml http request")
    assert_eq(sentence_case(""), "")
    }

    snake_case

    fn snake_case(text : String) -> String

    Convert a string to snake_case.

    Lowercase words are joined with underscores after the input has been split on separators, case transitions, and number boundaries.

    Example

    test "snake_case doc example" {
    assert_eq(snake_case("hello world"), "hello_world")
    assert_eq(snake_case("test123value"), "test_123_value")
    assert_eq(snake_case(""), "")
    }

    sponge_case

    fn sponge_case(text : String) -> String

    Convert a string to spongeCase.

    This uses the familiar alternating lowercase and uppercase pattern often used for mocking text, while keeping non-letters untouched.

    Example

    test "sponge_case doc example" {
    assert_eq(sponge_case("hello world"), "hElLo WoRlD")
    assert_eq(sponge_case("test123value"), "tEsT123vAlUe")
    assert_eq(sponge_case(""), "")
    }

    swap_case

    fn swap_case(text : String) -> String

    Swap the case of each letter in a string.

    Uppercase ASCII letters become lowercase, lowercase ASCII letters become uppercase, and every other character is copied unchanged.

    Example

    test "swap_case doc example" {
    assert_eq(swap_case("Hello World"), "hELLO wORLD")
    assert_eq(swap_case("snake_case"), "SNAKE_CASE")
    assert_eq(swap_case(""), "")
    }

    title_case

    fn title_case(text : String) -> String

    Convert a string to English-style title case.

    Minor words such as and, of, and the stay lowercase when they appear in the middle, while the first and last word are always capitalized.

    Example

    test "title_case doc example" {
    assert_eq(title_case("the lord of the rings"), "The Lord of the Rings")
    assert_eq(title_case("war and peace"), "War and Peace")
    assert_eq(title_case(""), "")
    }

    train_case

    fn train_case(text : String) -> String

    Convert a string to Train-Case.

    Each word is capitalized and the result is joined with hyphens, which matches styles commonly used by HTTP header names and labels.

    Example

    test "train_case doc example" {
    assert_eq(train_case("hello world"), "Hello-World")
    assert_eq(train_case("test123value"), "Test-123-Value")
    assert_eq(train_case(""), "")
    }

    upper_flat_case

    fn upper_flat_case(text : String) -> String

    Convert a string to UPPERFLATCASE.

    Uppercased words are joined without separators, which can be useful for legacy identifiers, short codes, and compact labels.

    Example

    test "upper_flat_case doc example" {
    assert_eq(upper_flat_case("hello world"), "HELLOWORLD")
    assert_eq(upper_flat_case("iPhone-App"), "IPHONEAPP")
    assert_eq(upper_flat_case(""), "")
    }

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io