Skip to content

English pluralization/singularization + naming convention transformation

License

Notifications You must be signed in to change notification settings

hypertino/inflector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

English pluralization/singularization + naming convention transformation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages