Skip to content
Vitali Haradkou edited this page Aug 11, 2023 · 13 revisions

Welcome to the rslike wiki!

Audi_RS_logo

here is you find:

  1. Installation
  2. Adding global functions and classes
  3. API

Reasons to install @rsLike/std?

  1. Less undefined behavior, when using Option and Result.
  2. Well tested. 100% test coverage
  3. JSDoc with examples.
  4. Typescript ready - d.ts types are generated with tsc.
  5. first-class CJS and ESM support.
  6. Zero dependencies.
  7. 2kB for min+gzip and 7.6kB for minified. See in bundlefobia.
  8. Deno?

Installation

NPM:

npm i @rslike/std

YARN/PNPM:

yarn add @rslike/std
# or
pnpm add @rslike/std

globals

  1. Install package
  2. In your entry file write next:
// your main file

// add global types in globalThis: Some, None, Option, Result, Ok, Err functions
import '@rslike/std/globals';

// rest your file

Option

Option is the same as for rust Option object

You can find the Option API here

Result

Result<T,E> is a same as for rust Result object

You can find API here

Async

Tries to resolve Promise<T> into Result<Option<T>, E>.

You can find API and examples here

Bind

Wraps function call into Result<Option<T>, E>. Easily to combine with match function

You can find API and examples here

Match

unwraps Option or Result and execute one of 2 callbacks depending on result.

If result is Ok or Some - 1 callback will be executed

If result is Err or None - 2 callback will be executed

You can find API and examples here

Clone this wiki locally