hypertino / inflector   1.0.14

BSD 3-clause "New" or "Revised" License GitHub

English pluralization/singularization + naming convention transformation

Scala versions: 2.13 2.12
Scala.js versions: 1.x

Maven Central

About

Inflector is a Scala/Scala.js library which implements English pluralization and singularization along with popular identifier's naming convention transformation.

Pluralization is based on based on Damian Conway's paper "An Algorithmic Approach to English Pluralization" and borrows some code from it's java implementation by Atteo

I've additionally implemented English singularization, it works for me, however didn't checked it very intensively.

Usage

Installation

The artifacts for Inflector live on Maven Central and can be tied into your SBT-based Scala project like this:

libraryDependencies += "com.hypertino" %% "inflector" % "1.0.14"

It is available for Scala 2.12 - 2.13

Pluralization

import com.hypertino.inflector.English

println(English.plural("cat")) // -> cats
println(English.plural("cat", 1)) // -> cat
println(English.plural("cat", 2)) // -> cats
println(English.singular("cats")) // -> cat

Identifier conventions

import com.hypertino.inflector.naming._

println(SnakeCaseToCamelCaseConverter.convert("string_like_this")) // -> stringLikeThis
println(CamelCaseToDashCaseConverter.convert("stringLikeThis")) // -> string-like-this
println(CamelCaseToHyphenCaseConverter.convert("stringLikeThis")) // -> String-Like-This

You may also convert back to camel-case and construct other converters.

License

Inflector library is available under the BSD 3-Clause License