1.6.3 • Published 1 year ago

@nathanpb/kext v1.6.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

The f

I think that the ECMAScript stdlib is not enough for me, so I'm attempting to rewrite all of the usefull Kotlin's stdlib into Typescript.

Yes, it's that simple

If you get any questions or suggestions just open a discussion or an issue

Installation

This package is published in npmjs:

npm i @nathanpb/kext or yarn add @nathanpb/kext

If you want to try the unstable features, use the next tag: npm i @nathanpb/kext@next.

Example and Use Cases

Generic array usage

import { any, sumBy } from '@nathanpb/kext/array'

const hasNonFriends = any(users, it => !it.areFriends(user))
const agesSum = sumBy(users, it => it.age)

Try/catch as an expression

Typescript:

let token: JwtPayload | undefined = undefined // mutable variable bad, also can't have it's type inferred
try {
  token = jwt.verify(req.body, secret)
} catch (e) {
  throw error(403, 'Token not present')
}

// Here, the TS compiler still thinks that ``token`` can be undefined

Typescript + @nathanpb/kext:

import { runCatching, throwExpr } from "@nathanpb/kext/error";

const token = runCatching(() => jwt.verify(req.body, secret))
  .onFailure(() => throwExpr(error(403, 'Token not present')))
  .getOrUndefined()!!
const token = runCatching(() => jwt.verify(req.body, secret))
  .recover(() => throwExpr(error(403, 'Token not present')))
  .getOrThrow()
const token = runCatching(() => jwt.verify(req.body, secret))
  .recover(() => { throw error(403, 'Token not present') })
  .getOrThrow()

Documentation

For detailed information, see the API Reference.

This library is all inspired by Kotlin, so their documentation may be useful.

  • Arrays - Functions for array manipulation. Details on the Kotlin imp here
  • Scope - Functions for scope manipulation. Details on the Kotlin imp here
  • Math - Functions for common math equations. Still incomplete.
  • Error - Functions for error/exception manipulation that I find handy.

Showcase (Brief demonstration of the Arrays Module)

showcase

Performance

I'm putting a huge effort in making this library perform well, and the benchmarks tell that it can already perform better than the stdlib in the tested functions.

You can check the benchmarks here. Navigate through the logs and attached report files...

Remamber, this code very fast

What's next

  • Do a proper documentation
  • Finish the unit tests and benchmarks for the Arrays module
  • Write a typescript plugin to invoke array functions as an extension-like function
  • Async-compatible functions

Side Notes

  • Project is in the very beginning
  • Performance is questionable

License

Copyright 2021 Nathan P. Bombana

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Do whatever you want with my code just don't make it boring

Thanks, JetBrains

1.6.3

1 year ago

1.6.2

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.4.0

3 years ago

1.3.0-1

3 years ago

1.5.0

3 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.3

4 years ago

0.0.4

4 years ago

0.0.2

4 years ago

0.0.1-1

4 years ago

0.0.1

4 years ago