New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

koka-ts

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koka-ts

A TypeScript library to handle errors.

latest
npmnpm
Version
0.1.4
Version published
Weekly downloads
1
-50%
Maintainers
1
Weekly downloads
 
Created
Source

Kōka


Kōka helps you craft elegant and secure TypeScript code. It enables easy error handling, streamlines development processes, and enhances code maintainability.

効果 (こうか): This means "effect" or "effectiveness." It can be used to talk about the impact or result of something.

npm i koka-ts

Usage/Examples

trySync and tryAsync

async function getData(): Promise<string> {
  const res = await tryAsync(fetch("https://api.sampleapis.com/coffee/hot"));
  if (res.isErr()) {
    const err = res.getErr();
    return err.message;
  }
  const data = await tryAsync(res.unwrap().json());
  if (data.isErr()) {
    const err = data.getErr();
    return err.message;
  }
  return data.unwrap()[0].title;
}

guardSync and guardAsync

async function getUser(userId: number): Promise<User> {
  const user = await guardAsync(db.users.findOne(userId)).throw();
  return user;
}
async function getUserName(userId: number): Promise<string> {
  const userName = (await db.users.findOne(1)).name;
  return guardSync(userName).or("John Doe");
}

FAQs

Package last updated on 07 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts