persch.cc:​~/www (master *%)$ mdcat stardust.md

Stardust

Stardust is a software library containing a lot of powerful features that make the programmer’s life much easier. Stardust is my main project that I’ve been working on for many years. I’m developing the library with Kotlin as a multi-platform project with JVM and JavaScript as target platforms.

I'm currently working on version 5.0 of the Stardust library. The release is planned at the beginning of 2023. You can find an early preview in the repository under https://gitlab.com/jmpersch/stardust.

The Stardust library is open source software. It is licensed under the terms of the GNU Affero General Public License, version 3.

Some interesting features of the Stardust library are described in the following sections.

String Building

String formatting was yesterday — with Kotlin’s type-safe builders, we have new capabilities to build things directly with Kotlin code. The Stardust library provides type-safe builders to comfortably create strings especially for the localization of multilingual applications.

lrope {
    val count = items.size

    +"Your shopping cart "

    if(count > 0) {
        +"contains "

        if(count > 1)
            format(count, formats.numbers.fullFixed(0))
        else
            +"one"

        +" item"
        plural(count, "s")
    } else
        +"is empty"

    +"."
}

// If `items` would contain exactly one element, the result would be:
// Your shopping cart contains one item.

Collections

Stardust contains additional collections and provides useful features for manipulation and conversion of mutable and immutable collections.

val immutableList = immutableListOf(1, 2, 3, 4, 5)

val mutableList = immutableList.mutableCopy { add(6) }

mutableList.add(7)

println(mutableList) // [1, 2, 3, 4, 5, 6, 7]

Date and Time

Stardust provides date and time classes with comfortable handling.

val date = Dates.utcCurrent()
println(date) // e.g. 2020-10-19

val dateTime = DateTimes.utcNow()
println(dateTime) // e.g. 2020-10-19 18:42:12.191 UTC

val ts = dateTime.minus(date.toUtcDateTime())
println(ts) // e.g. 0.18:42:12.191

Event Handling

Kotlin doesn’t have a built-in event mechanism, but events are an important design pattern. Because of this, the Stardust library contains a thread-safe event mechanism.

// Subscribe an event
action.subscribe { _, arg -> println(arg.value) }

// Raise an event
actionSource.raise(this, EventArgument("Hello!"))

Helper Classes

The Stardust library contains objects that define all available charsets, locales, and time zones.

val utf_8 = Charsets.utf_8

val en_US = Locales.en_US

val berlin = ZoneIds.europe_berlin

persch.cc:​~/www (master *%)$ mdcat footer.md

Copyright © Jan Martin Persch
All rights reserved.

Powered by the Thunderstruck website engine