Codeblock
Expressive Code
References
- Firebase Docs — Placeholder · Theme switcher
- NextJS Docs — Language switcher
- Kotlin Docs — Run · See more
File Icons
println("Kotlin")console.log('Typescript')Focus
class Sketch: PApplet {
override fun setup() { fullscreen() }
override fun draw() { background(0) rect( x = 100, y = 100, width = 100, height = 100 ) }
companion object { fun main(args: Array<String>) = PApplet.main(Sketch::class.name) }}Callout
rootProject.name = "ProjectName" Usually same as root folder name
include("subproject")Sticky Scroll
import kotlin.math.lnimport kotlin.math.max
fun main() {fun main() { for(i in 1..3) { println("Hello world x$i") }}
/** * Pluralize a word depending on its count * * [Source](https://taingmeng.medium.com/pluralize-string-with-kotlin-extension-554fb8c63469) */fun String.pluralize(count: Int, plural: String? = null): String {fun String.pluralize(count: Int, plural: String? = null): String { return if (count != 1) { plural ?: (this + 's') } else { this }}
/** * Converts '-'/'_' lowercase id into a display name */fun String.displayName(): String {fun String.displayName(): String { val id = this // Replace underscores and hyphens with spaces // Split the string into words val words = id.lowercase().split('_', '-') // Capitalize and join val newName = words.joinToString(" ") { it.capitalize() } // Return the new name return newName}
/** * 1st, 2nd, 3rd, etc... */fun Int.toOrdinal(): String {fun Int.toOrdinal(): String { if (this % 100 in 11..13) return "${this}th" return when (this % 10) { 1 -> "${this}st" 2 -> "${this}nd" 3 -> "${this}rd" else -> "${this}th" }}