Sign in

    case_conv

    A comprehensive MoonBit library for converting between different case styles including camelCase, snake_case, kebab-case, PascalCase, SHOUTY_SNAKE_CASE, Title Case, and more. Features bidirectional conversion, type-safe enums, and zero dependencies.

    case-conversion
    string-manipulation
    camelcase
    snake-case
    kebab-case
    pascalcase
    text-processing
    string-utils
    naming-convention
    utilities
    Download zip
    Version
    0.1.0
    License
    Apache-2.0
    Last updated
    last year
    Downloads
    40

    No dependencies

    #Case Conversion Library for MoonBit

    A comprehensive MoonBit library for converting between different case styles including camelCase, snake_case, kebab-case, PascalCase, SHOUTY_SNAKE_CASE, Title Case, and more.

    #Features

    • Multiple Case Styles: Support for 8 different case styles
    • Bidirectional Conversion: Parse from any case style and convert to any other
    • Type-Safe: Strong typing with enums for case styles
    • Zero Dependencies: Pure MoonBit implementation
    • Performance Optimized: Efficient string building and parsing

    #Supported Case Styles

    StyleExampleDescription
    UpperCamelHelloWorldTestPascalCase - each word capitalized
    LowerCamelhelloWorldTestcamelCase - first word lowercase, others capitalized
    Snakehello_world_testsnake_case - words separated by underscores
    Kebabhello-world-testkebab-case - words separated by hyphens
    ShoutySnakeHELLO_WORLD_TESTSHOUTY_SNAKE_CASE - uppercase with underscores
    SentenceHello world testSentence case - first word capitalized
    TitleHello World TestTitle Case - each word capitalized
    ShoutyKebabHELLO-WORLD-TESTSHOUTY-KEBAB-CASE - uppercase with hyphens

    #Quick Start

    #Basic Usage

    ///|
    test "basic conversion examples" {
    // Parse from camelCase and convert to snake_case
    let words = @case_conv.Words::from_lower_camel("helloWorldTest")
    let snake_result = words.into_snake()
    inspect(snake_result, content="hello_world_test")

    // Parse from kebab-case and convert to PascalCase
    let words2 = @case_conv.Words::from_kebab("hello-world-test")
    let pascal_result = words2.into_upper_camel()
    inspect(pascal_result, content="HelloWorldTest")

    // Parse from snake_case and convert to Title Case
    let words3 = @case_conv.Words::from_snake("my_awesome_function")
    let title_result = words3.into_title()
    inspect(title_result, content="My Awesome Function")
    }

    #Using the Generic into Method

    ///|
    test "generic conversion with CaseStyle enum" {
    let words = @case_conv.Words::from_lower_camel("getUserById")

    // Convert to different styles using the generic method
    let snake = words.into(@case_conv.CaseStyle::Snake)
    inspect(snake, content="get_user_by_id")
    let kebab = words.into(@case_conv.CaseStyle::Kebab)
    inspect(kebab, content="get-user-by-id")
    let shouty = words.into(@case_conv.CaseStyle::ShoutySnake)
    inspect(shouty, content="GET_USER_BY_ID")
    }

    #Parsing Examples

    #From Different Case Styles

    ///|
    test "parsing from various case styles" {
    // From camelCase variations
    let camel_words = @case_conv.Words::from_lower_camel("httpResponseCode")
    inspect(camel_words, content="Words([\"http\", \"response\", \"code\"])")
    let pascal_words = @case_conv.Words::from_upper_camel("HttpResponseCode")
    inspect(pascal_words, content="Words([\"http\", \"response\", \"code\"])")

    // From separator-based styles
    let snake_words = @case_conv.Words::from_snake("http_response_code")
    inspect(snake_words, content="Words([\"http\", \"response\", \"code\"])")
    let kebab_words = @case_conv.Words::from_kebab("http-response-code")
    inspect(kebab_words, content="Words([\"http\", \"response\", \"code\"])")

    // From space-separated styles
    let sentence_words = @case_conv.Words::from_sentence("Http response code")
    inspect(sentence_words, content="Words([\"http\", \"response\", \"code\"])")
    let title_words = @case_conv.Words::from_title("Http Response Code")
    inspect(title_words, content="Words([\"http\", \"response\", \"code\"])")
    }

    #Edge Cases

    ///|
    test "edge cases and special handling" {
    // Empty strings
    let empty_words = @case_conv.Words::from_snake("")
    inspect(empty_words, content="Words([])")
    let empty_result = empty_words.into_upper_camel()
    inspect(empty_result, content="")

    // Single word
    let single_words = @case_conv.Words::from_snake("hello")
    let single_result = single_words.into_upper_camel()
    inspect(single_result, content="Hello")

    // Already lowercase words
    let lower_words = @case_conv.Words::from_sentence("hello world")
    let camel_result = lower_words.into_lower_camel()
    inspect(camel_result, content="helloWorld")
    }

    #Conversion Examples

    #Common Programming Patterns

    ///|
    test "common programming case conversions" {
    // API endpoint naming
    let api_endpoint = @case_conv.Words::from_snake("get_user_profile")
    let url_path = api_endpoint.into_kebab()
    inspect(url_path, content="get-user-profile")

    // Database column to JavaScript property
    let db_column = @case_conv.Words::from_snake("created_at_timestamp")
    let js_property = db_column.into_lower_camel()
    inspect(js_property, content="createdAtTimestamp")

    // Environment variable naming
    let env_var = @case_conv.Words::from_kebab("database-connection-url")
    let env_name = env_var.into_shouty_snake()
    inspect(env_name, content="DATABASE_CONNECTION_URL")

    // Class name generation
    let class_words = @case_conv.Words::from_kebab("user-profile-service")
    let class_name = class_words.into_upper_camel()
    inspect(class_name, content="UserProfileService")
    }

    #Configuration and Documentation

    ///|
    test "configuration and documentation examples" {
    // Configuration key transformations
    let config_key = @case_conv.Words::from_snake("max_retry_attempts")
    let yaml_key = config_key.into_kebab()
    inspect(yaml_key, content="max-retry-attempts")

    // Documentation title generation
    let func_name = @case_conv.Words::from_lower_camel("validateUserInput")
    let doc_title = func_name.into_title()
    inspect(doc_title, content="Validate User Input")

    // Sentence description
    let sentence = func_name.into_sentence()
    inspect(sentence, content="Validate user input")
    }

    #API Reference

    #Types

    • Words(FixedArray[String]) - Internal representation of parsed words
    • CaseStyle - Enum representing different case styles

    #Core Functions

    #Parsing Functions

    • Words::from_upper_camel(String) -> Words - Parse PascalCase
    • Words::from_lower_camel(String) -> Words - Parse camelCase
    • Words::from_snake(String) -> Words - Parse snake_case
    • Words::from_kebab(String) -> Words - Parse kebab-case
    • Words::from_shouty_snake(String) -> Words - Parse SHOUTY_SNAKE_CASE
    • Words::from_sentence(String) -> Words - Parse sentence case
    • Words::from_title(String) -> Words - Parse Title Case
    • Words::from_shouty_kebab(String) -> Words - Parse SHOUTY-KEBAB-CASE

    #Conversion Functions

    • Words::into_upper_camel(Words) -> String - Convert to PascalCase
    • Words::into_lower_camel(Words) -> String - Convert to camelCase
    • Words::into_snake(Words) -> String - Convert to snake_case
    • Words::into_kebab(Words) -> String - Convert to kebab-case
    • Words::into_shouty_snake(Words) -> String - Convert to SHOUTY_SNAKE_CASE
    • Words::into_sentence(Words) -> String - Convert to sentence case
    • Words::into_title(Words) -> String - Convert to Title Case
    • Words::into_shouty_kebab(Words) -> String - Convert to SHOUTY-KEBAB-CASE
    • Words::into(Words, CaseStyle) -> String - Generic conversion function

    #Installation

    Add to your moon.pkg.json:

    { "import": [ "illusory0x0/case_conv" ] }

    #License

    This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

    #Contributing

    Contributions are welcome! Please feel free to submit a Pull Request.

    CaseStyle

    pub(all) enum CaseStyle {
    UpperCamel
    LowerCamel
    Snake
    Kebab
    ShoutySnake
    Sentence
    Title
    ShoutyKebab
    }

    case styles reference:

    https://en.wikipedia.org/wiki/Snake_case https://en.wikipedia.org/wiki/Camel_case https://en.wikipedia.org/wiki/Letter_case#Kebab_case https://en.wikipedia.org/wiki/Letter_case#Sentence_case https://en.wikipedia.org/wiki/Title_case
    impl Eq for CaseStyle
    impl Hash for CaseStyle
    impl Show for CaseStyle
    impl ToJson for CaseStyle

    Words

    pub(all) type Words FixedArray[String]

    immediate representation of a list of words all word should be in lower case e.g. ["hello", "world"]

    impl Compare for Words
    impl Eq for Words
    impl Hash for Words
    impl Show for Words
    impl ToJson for Words

    Words::from_kebab

    fn Words::from_kebab(input : String) -> Words

    Parse kebab-case string into Words Example: "hello-world-test" -> Words(["hello", "world", "test"])

    Words::from_lower_camel

    fn Words::from_lower_camel(input : String) -> Words

    Parse lowerCamelCase string into Words Example: "helloWorldTest" -> Words(["hello", "world", "test"])

    Words::from_sentence

    fn Words::from_sentence(input : String) -> Words

    Parse sentence case string into Words Example: "Hello world test" -> Words(["hello", "world", "test"])

    Words::from_shouty_kebab

    fn Words::from_shouty_kebab(input : String) -> Words

    Parse SHOUTY-KEBAB-CASE string into Words Example: "HELLO-WORLD-TEST" -> Words(["hello", "world", "test"])

    Words::from_shouty_snake

    fn Words::from_shouty_snake(input : String) -> Words

    Parse SHOUTY_SNAKE_CASE string into Words Example: "HELLO_WORLD_TEST" -> Words(["hello", "world", "test"])

    Words::from_snake

    fn Words::from_snake(input : String) -> Words

    Parse snake_case string into Words Example: "hello_world_test" -> Words(["hello", "world", "test"])

    Words::from_title

    fn Words::from_title(input : String) -> Words

    Parse Title Case string into Words Example: "Hello World Test" -> Words(["hello", "world", "test"])

    Words::from_upper_camel

    fn Words::from_upper_camel(input : String) -> Words

    Parse UpperCamelCase (PascalCase) string into Words Example: "HelloWorldTest" -> Words(["hello", "world", "test"])

    Words::inner

    #deprecated("Use `struct T(A)` to declare a newtype and use `.0` access the underlying type instead.")
    fn Words::inner(self : Words) -> FixedArray[String]
    Convert newtype to its underlying type, automatically derived.

    Words::into

    fn Words::into(self : Words, case : CaseStyle) -> String

    Words::into_kebab

    fn Words::into_kebab(self : Words) -> String

    Convert Words to kebab-case string Example: Words(["hello", "world", "test"]) -> "hello-world-test"

    Words::into_lower_camel

    fn Words::into_lower_camel(self : Words) -> String

    Convert Words to lowerCamelCase string Example: Words(["hello", "world", "test"]) -> "helloWorldTest"

    Words::into_sentence

    fn Words::into_sentence(self : Words) -> String

    Convert Words to sentence case string Example: Words(["hello", "world", "test"]) -> "Hello world test"

    Words::into_shouty_kebab

    fn Words::into_shouty_kebab(self : Words) -> String

    Convert Words to SHOUTY-KEBAB-CASE string Example: Words(["hello", "world", "test"]) -> "HELLO-WORLD-TEST"

    Words::into_shouty_snake

    fn Words::into_shouty_snake(self : Words) -> String

    Convert Words to SHOUTY_SNAKE_CASE string Example: Words(["hello", "world", "test"]) -> "HELLO_WORLD_TEST"

    Words::into_snake

    fn Words::into_snake(self : Words) -> String

    Convert Words to snake_case string Example: Words(["hello", "world", "test"]) -> "hello_world_test"

    Words::into_title

    fn Words::into_title(self : Words) -> String

    Convert Words to Title Case string Example: Words(["hello", "world", "test"]) -> "Hello World Test"

    Words::into_upper_camel

    fn Words::into_upper_camel(self : Words) -> String

    Convert Words to UpperCamelCase (PascalCase) string Example: Words(["hello", "world", "test"]) -> "HelloWorldTest"

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io