/kt.ts

WIP: Porting Kotlin stdlib api to typescript

Primary LanguageTypeScript

kt.ts banner

Kotlin Stdlib API in Typescript

Porting the Kotlin standard library design rationale to typescript. Boost the productivity by using the wise API design.

(WIP: This project is under active development. You are welcome to contribute.)

Getting Started to Contribute

Pick the not-yet-implemented API(below list) and try to create a GitHub issues with the feature template. There is a full check-list for you to contribute this project :). Here is the example.

Getting Started

This module designed to be used in Typescript environment for utilizing strict type-checking and IDE auto-complete experience that similar to Kotlin Development.

If your want to use it in javascript project, I highly recommend you to use a relatively new VSCode feature @ts-check Or Intellij-based IDE to enable type checking.

npm install kt.ts

# OR

yarn add kt.ts

Typescript project

// index.ts
import 'kt.ts'

// `flatMap` require { "lib": ["es2019"] } in tsconfig.json
const result = [1,2,[3,3]].flatMap(it => it).distinct()

console.log(result)

NodeJs CommonJS style

// index.js
require('kt.ts')

// node >= 11.0 support `flatMap`
const result = [1,2,[3,3]].flatMap(it => it).distinct()

console.log(result)

Project Status

Kotlin List API

  • contains
  • elementAt
  • elementAtOrElse
  • elementAtOrNull
  • find
  • findLast
  • first
  • first
  • firstOrNull
  • firstOrNull
  • getOrElse
  • getOrNull
  • indexOf
  • indexOfFirst
  • indexOfLast
  • last
  • last
  • lastIndexOf
  • lastOrNull
  • random
  • single
  • single
  • singleOrNull
  • singleOrNull
  • drop
  • dropLast
  • dropLastWhile
  • dropWhile
  • filter
  • filterIndexed
  • filterNot
  • filterNotNull
  • slice
  • take
  • takeLast
  • takeLastWhile
  • takeWhile
  • reverse
  • reversed
  • sortBy
  • sortByDescending
  • sortDescending
  • sorted
  • sortedBy
  • sortedByDescending
  • sortedDescending
  • sortedWith
  • associate
  • associateBy
  • associateBy
  • associateWith
  • toSet
  • groupBy
  • groupBy
  • mapIndexed
  • mapIndexedNotNull
  • mapNotNull
  • withIndex
  • distinct
  • distinctBy
  • intersect
  • subtract
  • union
  • all
  • any
  • any
  • count
  • count
  • fold
  • foldIndexed
  • foldRight
  • foldRightIndexed
  • forEach
  • forEachIndexed
  • max
  • maxBy
  • maxWith
  • min
  • minBy
  • minWith
  • none
  • none
  • onEach
  • reduce
  • reduceIndexed
  • reduceRight
  • reduceRightIndexed
  • sumBy
  • requireNoNulls
  • requireNoNulls
  • chunked
  • chunked
  • minus
  • minus
  • minusElement
  • partition
  • plus
  • plus
  • plusElement
  • windowed
  • windowed
  • zip
  • zip
  • zip
  • zip
  • zipWithNext
  • zipWithNext
  • joinTo
  • joinToString
  • average
  • sum
  • containsAll
  • get
  • isEmpty
  • iterator
  • subList
  • size
  • lastIndex

Extra for TS and Kotlin-Like API

  • filterNotEmpty