npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

renai-js

v0.0.6

Published

no more throw

Downloads

5

Readme

Renai-js

Renai-js was created to simplify the difficult-to-see try-catch blocks.

Feature

  • Replace try-catch in typescript
  • Based on generator function ※ function*() { ... }
  • I think I got the name wrong

Why?

  • In TypeScript(or JS), when writing code, can't know which function might cause which error.
    ※ It's not really a big deal, but I just made it because I was uncomfortable.

Getting Started

First, install Renai-js using npm.

npm install --save-dev renai-js

Second, Find error throwing function in your code.

// error.ts
export function randomOops(): '+_+' {
  const { 
    random, 
    floor 
  } = Math;
  const result: 0 | 1 | 2 | 3 = floor( random() * 100 ) % 4;
  
  switch( result ) {
    case 1: throw new Error('T_T'); break;
    case 2: throw new Error('X_X'); break;
    case 3: throw new Error('U_U'); break;
    default: return '+_+';
  }
}

Third, Convert code like this

// oops.ts
import { LabeledError } from 'renai-js';

export class T_TError extends LabeledError<'T_TError'> {};
export class X_XError extends LabeledError<'X_XError'> {};
export class U_UError extends LabeledError<'U_UError'> {};

export function* randomOops(): '+_+' {
  const { 
    random, 
    floor 
  } = Math;
  const result: 0 | 1 | 2 | 3 = floor( random() * 100 ) % 4;

  switch( result ) {
    case 1: yield T_TError.of('T_T'); break;
    case 2: yield X_XError.of('X_X'); break;
    case 3: yield U_UError.of('U_U'); break;
    default: return '+_+';
  }
}

Fourth, Find and Replace try-catch block using Renai-js.

/** Before ▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼ */
// play.ts
try {
  const result = randomOops();
}
catch(e) {
  switch( e.message ) {
    case 'T_T': /** error handling1 */ break;
    case 'X_X': /** error handling2 */ break;
    case 'U_U': /** error handling3 */ break;
    default   : /** unexcepted error handling */ break;
  }
}

/** After ▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼ */
// play.ts
import { renai, UnknownError } from 'renai-js';
import { randomOops, T_TError, X_XError, U_UError } from './oops';

/** if you want literal type attach 'as const' behind return value or set literal return type. */
const result: number | string | boolean | UnknownError = renai(
  randomOops,
  {
    'T_TError': (error: T_TError): number => { /** error handling1 */ },
    'X_XError': (error: X_XError): string => { /** error handling2 */ },
    'U_UError': (error: U_UError): boolean => { /** error handling3 */ },
    'UnknownError': (error: UnknownError): UnknownError => { /** unexcepted error handling */ }
  }
);

Browser Version Support

chorme 55+

| Browser | Version | |----------------|-------------| | Chorme | 55+ | | Edge | 15+ | | Safari | 11+ | | Firefox | 52+ | | Opera | 42+ | | IE | Not Support | ※ referenced by "https://caniuse.com/"