Multiplatform kotlin string case conversion and detection library.

Overview

KaseFormat

Download CircleCI Awesome Kotlin Badge

Multiplatform kotlin string case conversion and detection library.

examples

(Inspired by Guava's CaseFormat)

Setup

Declare repository

Include the following in your respositories block within the build.gradle.kts:

repositories {
    maven("https://dl.bintray.com/dotcipher/maven")
}

Or in groovy syntax for a build.gradle:

repositories {
    maven {
        url 'https://dl.bintray.com/dotcipher/maven'
    }   
}

Include dependency

Include the following in your dependencies block (replacing <version> with the latest release above:

dependencies {
        // JVM implementation
        implementation("io.dotcipher.kase:kase-format-jvm:<version>")

        // Native / JS implementations coming soon
}

Usage

KaseFormat is the main entrypoint for library usage, and it's defined as an enum of the following formats:

  • LOWER_HYPHEN (ie. hello-world)
  • CAPITAL_HYPHEN (ie. Hello-World)
  • UPPER_HYPHEN (ie. HELLO-WORLD)
  • LOWER_UNDERSCORE (ie. hello_world)
  • CAPITAL_UNDERSCORE (ie. Hello_World)
  • UPPER_UNDERSCORE (ie. HELLO_WORLD)
  • LOWER_CAMEL (ie. helloWorld)
  • CAPITAL_CAMEL (ie. HelloWorld)

Conversion

The most efficient way to convert is if the source format is known before conversion. For example, if the intent is to convert from LOWER_UNDERSCORE (ie. hello_world) to CAPITAL_CAMEL (ie. HelloWorld) then you could use the following syntax:

val str = "hello_world"
val output = KaseFormat.LOWER_UNDERSCORE.convert(KaseFormat.CAPITAL_CAMEL, str)
// output == "HelloWorld"

If the source format isn't known before conversion, then a KaseConverter needs to be created targeting the destination format. The KaseConverter can be reused and is thread-safe. For example if the intent is to convert into the LOWER_HYPHEN format from any unknown format then you can use the following syntax:

val strings = listOf("string_one", "STRING-TWO", "stringThree", "StringFour")
val converter = KaseFormat.LOWER_HYPHEN.converter()

val firstOutput = converter.convert(strings[0])
// firstOutput == "string-one"

val listOutput = converter.convert(strings.sublist(1, strings.size))
// listOutput == listOf("string-two", "string-three", "string-four")

Detection

Detection of what format a string might be (by best guess), can be accomplished using the following syntax:

val str = "someString"
val format = KaseFormat.determine(str)
// format == LOWER_CAMEL
You might also like...
Dependency Injection library for Kotlin Multiplatform, support iOS and Android

Multiplatform-DI library for Kotlin Multiplatform Lightweight dependency injection framework for Kotlin Multiplatform application Dependency injection

Server Sent Events (SSE) client multiplatform library made with Kotlin and backed by coroutines

OkSSE OkSSE is an client for Server Sent events protocol written in Kotlin Multiplatform. The implementation is written according to W3C Recommendatio

A local storage management library for Kotlin Multiplatform Mobile iOS and android
A local storage management library for Kotlin Multiplatform Mobile iOS and android

A local storage management library for Kotlin Multiplatform Mobile iOS and android Features iOS and Android local storage in one interface Provides ge

Opinionated Redux-like implementation backed by Kotlin Coroutines and Kotlin Multiplatform Mobile

CoRed CoRed is Redux-like implementation that maintains the benefits of Redux's core idea without the boilerplate. No more action types, action creato

Kotlin multiplatform library template.

template-kmp-library Kotlin multiplatform library template. Has a baseline setup for a multiplatform library supporting all kotlin targets except andr

Generic AST parsing library for kotlin multiplatform

kotlinx.ast kotlinx.ast is a generic AST (Abstract Syntax Tree) parsing library, Kotlin is currently the only supported language. The library is desig

Kotlin multiplatform library template

template-kmp-library Kotlin multiplatform library template. Has a baseline setup for a multiplatform library supporting all kotlin targets except depr

Kotlin Multiplatform (KMP) library for reading resources in tests

kotlinx-resources Kotlin Multiplatform (KMP) plugin and library that add support for reading resources in tests. The plugin and a library work in tand

Kotlinx-murmurhash - Kotlin Multiplatform (KMP) library for hashing using MurmurHash

kotlinx-murmurhash Kotlin Multiplatform (KMP) library for MurmurHash, a non-cryp

Comments
  • Switch to MP lib pattern

    Switch to MP lib pattern

    Since this repo is MP by default, it's probably best to use the new MP publishing mechanisms introduced recently: https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#publishing-a-multiplatform-library

    enhancement good first issue 
    opened by dotCipher 0
  • Include option to treat digits as boundaries

    Include option to treat digits as boundaries

    The consumer of the lib might want to treat digits as boundaries when converting between cases. The library should provide a flag or mechanism for handling that

    enhancement good first issue 
    opened by dotCipher 0
Releases(0.1.0)
Owner
Cody Moore
Lead Developer @bloomcredit / Ex-@palantir / EDM enthusiast / Scotch aficionado / Father
Cody Moore
🚀 Sample Android HB Case

HB Case Android and Compose Version Android Clean Architecture in HB Case Sample is a sample project that presents modern, approach to Android applica

Mr.Sanchez 8 Aug 27, 2022
With Viola android face detection library, you can detect faces in a bitmap, crop faces using predefined algorithm and get additional information from the detected faces.

Viola Viola android face detection library detects faces automatically from a bitmap, crop faces using the predefined algorithms, and provides supplem

Darwin Francis 58 Nov 1, 2022
On-device wake word detection powered by deep learning.

Porcupine Made in Vancouver, Canada by Picovoice Porcupine is a highly-accurate and lightweight wake word engine. It enables building always-listening

Picovoice 2.8k Dec 30, 2022
KMP library for string unicode normalization

doistx-normalize Kotlin Multiplatform (KMP) library that adds support for normalization as described by Unicode Standard Annex #15 - Unicode Normaliza

Doist 31 Nov 22, 2022
Detekt rule no string parameter with kotlin

Detekt custom rule template This repository is a template. You can use it to generate your own repository to write and share your custom rules. How to

Christian Wüstner 0 Nov 26, 2021
This program will read from your android application string.xml file and generate translated strings.xml files in your preferred languages using google sheet.

Localize your application content This program will read from your application string.xml file and generate translated strings.xml files in your prefe

DhiWise 4 Jul 29, 2022
String obfuscator for Android applications

Paranoid String obfuscator for Android applications. Usage In order to make Para

Joom 7 Sep 10, 2022
A tiny Kotlin multiplatform library that assists in saving and restoring objects to and from disk using kotlinx.coroutines, kotlinx.serialisation and okio

Store A tiny Kotlin multiplatform library that assists in saving and restoring objects to and from disk using kotlinx.coroutines, kotlinx.serialisatio

Isuru Rajapakse 98 Jan 3, 2023
Real life Kotlin Multiplatform project with an iOS application developed in Swift with SwiftUI, an Android application developed in Kotlin with Jetpack Compose and a backed in Kotlin hosted on AppEngine.

Conferences4Hall Real life Kotlin Multiplatform project with an iOS application developed in Swift with SwiftUI, an Android application developed in K

Gérard Paligot 98 Dec 15, 2022
A Bluetooth kotlin multiplatform "Cross-Platform" library for iOS and Android

Blue-Falcon A Bluetooth "Cross Platform" Kotlin Multiplatform library for iOS, Android, MacOS, Raspberry Pi and Javascript. Bluetooth in general has t

Andrew Reed 220 Dec 28, 2022