Skip to content

Latest commit

 

History

History
97 lines (72 loc) · 2.64 KB

README.md

File metadata and controls

97 lines (72 loc) · 2.64 KB

🔄 Casing

Scala Library for Naming Convention Transitions (camelCase, PascalCase, snake_case, kebab-case, etc.)

Build Status Maven Central Scala Version License: MIT

Features

✂️ Split words in any kind of Naming Convention
🪶 Dependency free
🧪 Fully tested

Installation

To include Casing in your Scala project, add the following dependency:

libraryDependencies += "io.github.ranyitz" %% "casing" % "0.2.0"

Usage

import casing._

camelCase("foo_bar") // fooBar
pascalCase("foo bar") // FooBar
snakeCase("fooBar") // foo_bar
kebabCase("foo-bar") // foo-bar
constantCase("foo.bar") // FOO_BAR

caseSplit("fooBarBaz") // foo.bar.baz 
    .map(_.toLowerCase())
    .mkString(".") 

split

splits a string into words based on the casing pattern

can be used to create any custom naming pattern

caseSplit("fooBarBaz") // Seq(foo, Bar, Baz)
caseSplit("foo_bar_baz") // Seq(foo, bar, baz)
caseSplit("foo-bar-baz") // Seq(foo, bar, baz)
caseSplit("FOO_BAR_BAZ") // List(FOO, BAR, BAZ)

camelCase

converts a string to camelCase

camelCase("foo_bar") // fooBar

pascalCase

converts a string to PascalCase

pascalCase("foo_bar") // FooBar

snakeCase

converts a string to snake_case

snakeCase("fooBar") // foo_bar

kebabCase

converts a string to kebab-case

kebabCase("fooBar") // foo-bar

constantCase

converts a string to CONSTANT_CASE or SCREAMING_SNAKE_CASE

constantCase("fooBar") // FOO_BAR

Validation Functions

validates a string against a specific naming convention

isCamelCase("fooBar") // true
isPascalCase("FooBar") // true
isSnakeCase("foo_bar") // true
isKebabCase("foo-bar") // true
isConstantCase("FOO_BAR") // true

Inspiration