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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@zerointermittency/error

v1.0.6

Published

Base para el manejo de errores para cualquier proyecto.

Readme

Bienvenido

Base para el manejo de errores para cualquier proyecto.

Instalación

yarn add @zerointermittency/error
# npm i --save @zerointermittency/error

Api

El modulo consta de una sola clase llamada ZIError.

ZIError

constructor

Este método es el que se llama cuando se realiza el siguiente código:

const ZIError = require('@zerointermittency/error');
let error = new ZIError(params);

Argumentos:

  • params (Object):
    • level (String) required: identifica el nivel al que pertenece el error, estos están definidos en el atributo estático level de la clase
    • code (Number) required: numero que identifique su error
    • name (String): nombre que identifica el error
    • message (String): mensaje con mayor detalle respecto al error o informativo
    • extra (Object): objeto para poder tener referencia a variables o objetos cuyos valores son necesarios para un correcto funcionamiento y ayudar a identificar de mejor manera porque se produjo el error
    • error (Error): es una instancia de Error nativo de javascript, para poder sobrescribir el stack, mensaje y nombre que identifique el error en caso que necesitemos validarlo.
    • prefix (String): para identificar donde se esta produciendo el error.

Retorna:

(ZIError): Retorna la instancia de la clase ZIError.

level

Están definidos actualmente solo 3 niveles de error fatal, error y warning.

const ZIError = require('@zerointermittency/error');

let levelError = ZIError.level.error,
    levelFatal = ZIError.level.fatal,
    levelWarning = ZIError.level.warning;

Recomendación

Para su uso es importante destacar que se puede extender de esta clase ZIError, por ejemplo:

'use strict';

const ZIError = require('@zerointermittency/error');

class AuthError extends ZIError {

    constructor(opts) {
        opts.prefix = 'auth';
        super(opts);
    }

}

module.exports = {
    internalError: new AuthError({
        code: 0,
        name: 'internalError',
        message: 'internalError',
        level: ZIError.level.fatal,
    }),
    secretRequired: new AuthError({
        code: 1,
        name: 'secretRequired',
        message: 'secret required',
        level: ZIError.level.error,
    }),
    appRequired: (extra) => new AuthError({
        code: 2,
        name: 'appRequired',
        message: 'app required to create payload',
        level: ZIError.level.error,
        extra: extra,
    }),
};

En este caso obtenemos una clase de error llamada AuthError, definiendo específicamente el prefijo ('auth') en el constructor, lo cual nos permitiría saber que los errores pertenecen a dicha clase.

Pruebas funcionales (Unit Testing)

Se llevaron a cabo 2 pruebas funcionales las cuales evalúan todos los casos de éxito al momento de crear la instancia de ZIError y los casos en que va a dar error si los parámetros especificados no tienen los elementos requeridos. Para ejecutar las pruebas:

yarn test

Pruebas de rendimiento (benchmark)

Con el objetivo de que sea optimo el código se realizaron 2 pruebas de rendimiento, de las cuales se determino que:

yarn benchmark benchmark/StringConcatenate.js

Template Literal x 562,432,004 ops/sec ±0.85% (85 runs sampled)
operate String x 561,491,894 ops/sec ±0.77% (85 runs sampled)
Concatenate String x 48,848,307 ops/sec ±4.89% (82 runs sampled)
add String x 556,429,141 ops/sec ±1.05% (87 runs sampled)
Fastest is Template Literal,operate String,add String
  • Utilizar de manera global el atributo estático de niveles para la clase ZIError, es mucho mejor en rendimiento que utilizar de manera local el objeto. Para correr la prueba:
yarn benchmark benchmark/LocalvsGlobalStaticAttrClass.js

local static attrs x 63,716,107 ops/sec ±5.69% (81 runs sampled)
global static attrs x 557,872,339 ops/sec ±0.85% (84 runs sampled)
Fastest is global static attrs

Changelog

Todos los cambios importantes son escritos aquí