Skip to content

SenpaiOnline/newbase60

Repository files navigation

Maven Central GitHub

This is yet another implementation of NewBase60 algorithm made for Kotlin and Java.

In a nutshell, this library will be useful if you want to implement a URL shortener, like Bitly or TinyURL, that is URL-safe and does not contain confusing character pairs, such as an uppercase letter O and 0, an uppercase letter I and 1.

Check out this article of Tantek Çelik for more information.

Examples

numberToSexagesimal(0) // "0"
numberToSexagesimal(60) // "10"
numberToSexagesimal(1337) // "NH"
numberToSexagesimal(9_223_372_036_854_775_807) // "FFD_YXvLFW7"
sexagesimalToNumber("10") // 60L
sexagesimalToNumber("NH") // 1337L
sexagesimalToNumber("NH🥺") // java.text.ParseException(errorOffset=2, detailMessage="Couldn't parse the character "🥺"")

Installation

The artifact is available on Maven Central, so just add the below dependency to your favorite build automation tool.

Apache Maven

<dependency>
  <groupId>online.senpai</groupId>
  <artifactId>newbase60</artifactId>
  <version>1.0.1</version>
</dependency>

Gradle Groovy DSL

implementation 'online.senpai:newbase60:1.0.1'

Gradle Kotlin DSL

implementation("online.senpai:newbase60:1.0.1")

License

Apache License, Version 2.0