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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kabeep/exception

v1.2.3

Published

Exception is a custom error library for Node.js that provides a more flexible and customizable way of handling errors.

Downloads

20

Readme

Exception is a custom error library for Node.js that provides a more flexible and customizable way of handling errors.


NodeJS License NPM Codecov Codacy CircleCI

English | 简体中文

Alt

Inheritance and the prototype chain

📖 Introduction

Inspired by the work of sindresorhus, I decided to open source the most repetitive encapsulation work I do in CLI development.

I do not like disorder. Often, unexpected situations arise due to our insufficient consideration. Therefore, I encourage those around me to engage in more comprehensive error collection work.

The goal of Exception is to transform unexpected occurrences into anticipated outcomes as much as possible.

It allows Error objects to throw exception and stack information in a more aesthetically pleasing and intuitive manner, and can also serve as Notify to output critical information in workflows.

⚙️ Installation

npm install @kabeep/exception --save
yarn add @kabeep/exception
pnpm add @kabeep/exception

🚀 Usage

Plain text or Error object

example

Plain-text-or-Error-object

import Exception from '@kabeep/exception';

// Plain text
throw new Exception('Argument example');

// or Error object
throw new Exception(new Error('Argument example'));

Using in Asynchronous Contexts

example

Using-in-Asynchronous-Contexts

import Exception from '@kabeep/exception';

(
    async () => {
        throw new Exception('Promise example');
    }
)().catch(console.log);

Custom Styles

example

Custom-Styles

import Exception from '@kabeep/exception';

// Use custom style with hex or rgb
const stylish = '(51,51,51).bg#f56c6c';

console.log(
    new Exception('Stylish example', stylish)
);

Custom Exceptions

example

Custom-Exceptions

import Exception from '@kabeep/exception';

// > Warning
class Warning extends Exception {
    constructor (message: string | Error) {
        super(message, '( 51 ,51, 51 ).bg#e6a23c');
    }
}

const warn = new Warning('Inherited example');
// Warning: Inherited example [Without style]
console.log(`${warn}`);
console.log(warn);

Print Key Information

example

Print-Key-Information

import Exception from '@kabeep/exception';

// > Info
const infoStyle = '(51,51,51).bg#409eff';

class Info extends Exception {
    constructor (message) {
        super(message, infoStyle);
    }

    toString () {
        return this.info(styles);
    }
}

const tip = new Info('Inherited example');
// Without stack
console.log(`${tip}`);

// > Success
const successStyle = '(51,51,51).bg#67c23a';

class Success extends Exception {
    constructor (message) {
        super(message, successStyle);
    }

    toString () {
        return this.info(styles);
    }
}

const pass = new Success('Inherited example');
// Without stack
console.log(pass.toString());

🎨 Supported styles

"dim.italic.underline"
"magenta.cyan"
"bgMagenta.bgCyan"
"#fff.bg#333333"
"(51,51,51).bg(24,124,255)"
"cyan.bgDarkblue"

🔗 Related

  • chalk - Terminal string styling done right
  • chalk-pipe - Create chalk style schemes with simpler style strings

🤝 Contribution

Contributions via Pull Requests or Issues are welcome.

📄 License

This project is licensed under the MIT License. See the LICENSE file for details.