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

kind-error

v2.0.0

Published

Base class for easily creating meaningful and quiet by default Error classes with sane defaults and assertion in mind.

Downloads

68

Readme

kind-error npmjs.com The MIT License

Base class for easily creating meaningful and quiet by default Error classes.

code climate standard code style travis build status coverage status dependency status

Install

npm i kind-error --save

Features

  • You can customize error name with name property in options object.
  • By default won't have stack property in the composed error object.
  • You should pass showStack: true in options if you want stacktraces.
  • Composes meaningful error output if actual and expected given.
  • If actual and expected is given, will compose message automatically.

Usage

For more use-cases see the tests

const KindError = require('kind-error')

KindError

Initialize KindError class with message and options.

Params

Example

const err = new KindError('msg', {
  showStack: true,
  custom: 123
})

console.log(err) // => [KindError: msg]
console.log(err.custom) // => 123
console.log(err.stack) // => error stack trace

Or if you give actual and expected it will make default message. See this example.

const assert = require('assert')
const err = new KindError({
  actual: [1, 2, 3],
  expected: {foo: 'bar'}
})

assert.deepEqual(err.actual, [1, 2, 3])
assert.deepEqual(err.expected, {foo: 'bar'})
assert.strictEqual(err.stack, undefined)
assert.strictEqual(err.type.actual, 'array')
assert.strictEqual(err.type.expected, 'object')
assert.strictEqual(err.inspect.actual, '[ 1, 2, 3 ]')
assert.strictEqual(err.inspect.expected, '{ foo: \'bar\' }')
assert.strictEqual(err.message, 'expect `object`, but `array` given')

Example AppError

Here we show how to create new error class

var util = require('util')
var KindError = require('kind-error')

function AppError () {
  KindError.apply(this, arguments)
  this.name = 'AppError'
}

util.inherits(AppError, KindError)

AppError.prototype.foo = function () {
  return 123
}

var err = new AppError('foo bar', {baz: 'qux'})
//=> err
// err.name => 'AppError'
// err.message => 'foo bar'
// err.baz => 'qux'
// err.foo() => 123

Related

  • abbrev-kindof: Use abbreviations for checking type of given value. Like kindof(val, 'soa') to check that value is string, object or array.
  • assert-kindof: Check native type of the given value and throw TypeError if not okey. Expressive, elegant, behavior-driven API, good descriptive default error messages, simple and clean syntax.
  • is-kindof: Check type of given javascript value. Support promises, generators, streams, and native types. Thin wrapper around kind-of module.
  • kind-of-extra: Extends kind-of type check utility with support for promises, generators, streams and errors. Like kindof(Promise.resolve(1)) //=> 'promise' and etc.
  • kind-of-types: List of all javascript types. Used and useful for checking, validation, sanitizing and testing. Like isStream, isPromise, isWeakset and etc.
  • error-base: Create custom Error classes.

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.

Charlike Make Reagent new message to charlike freenode #charlike

tunnckocore.tk keybase tunnckocore tunnckoCore npm tunnckoCore twitter tunnckoCore github