All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.in.shabinder.soundbound.utils.Ext.kt Maven / Gradle / Ivy

There is a newer version: 0.21
Show newest version
package `in`.shabinder.soundbound.utils

import `in`.shabinder.soundbound.models.Artist
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.Json
import kotlin.jvm.JvmName
import kotlin.math.min


@Suppress("NOTHING_TO_INLINE")
internal inline fun List.cleaned(): List {
    return this.filter { it.isNotBlank() && it != "null" }
}

@Suppress("NOTHING_TO_INLINE")
@JvmName("cleanedArtists")
internal inline fun List.cleaned(): List {
    return filter { it.name.isNotBlank() && it.name != "null" }
}

fun  T.limitDecimals(maxDecimals: Int): String {
    val result = toString()
    val lastIndex = result.length - 1
    var pos = lastIndex
    while (pos >= 0 && result[pos] != '.') {
        pos--
    }
    return if (maxDecimals < 1 && pos >= 0) {
        result.substring(0, min(pos, result.length))
    } else if (pos >= 0) {
        result.substring(0, min(pos + 1 + maxDecimals, result.length))
    } else {
        return result
    }
}

val GlobalJson by lazy {
    Json {
        isLenient = true
        ignoreUnknownKeys = true
        coerceInputValues = true
        encodeDefaults = true

        @OptIn(ExperimentalSerializationApi::class)
        explicitNulls = false
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy