Skip to content

gfffrtt/typescript-option

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Typescript Option

Rust options for typescript

⚙️ Installation

Here i'm using pnpm but you can use any package manager you prefer.

$ pnpm i typescript-option -S

🛠️ Api

❓ Helper functions to help you deal with options

  • wrap
  • some
  • none

Option

⚡ All functions you can call on an option

  • unwrap
  • unwrap_or
  • unwrap_or_else
  • run
  • transform
  • map
  • map_or
  • map_or_else

📖 Types

📌 All types available

  • Option
  • Some
  • None

🎯 Features

🚀 Checkout some examples

Examples

function getUserPlan(userId: string): Option<UserPlan> { ... }

function getJwtPayload(token: string): Option<JwtPayload> { ... }

const token = wrap(cookies.get("access-token"))

const plan = token
    .map(getJwtPayload)
    .map((payload) => getUserPlan(payload.userId))
    .run(sendUserPlanEmail)
    .unwrap()

// Plan will be either Some<UserPlan> or None

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published