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

yocto-status-codes

v1.2.3

Published

Manage and retreive status code & more defined data from given rules.

Downloads

4

Readme

NPM

alt text Code Climate Test Coverage Issue Count Build Status

Overview

This module is a part of yocto node modules for NodeJS.

Please see our NPM repository for complete list of available tools (completed day after day).

Manage and retrieve status code & more defined data from given rules.

Motivation

Create a standard response format for our yocto-core-stack application

Which format have response ?

All reponse given by this module has format below :

{
  status  : "success|error", // Always success or error
  code    : "200|400|500", // At the moment only this three values
  message : "", // a specific message, can be overload
  data    : {} // a specific data, can be overload
}

Configuration file

The configuration file give you the possibility to load predefined data in an jSON file.

Childs categories can only up to 999 like 200999

Structure of file :

[
  // define some parents categories
  {
    "category"  : 200,
    // define some childs categories
    "childs"    :  [
      {
        "code"      : "000",
        "codeHTTP"  : 200,
        "status"    : "success",
        "label"     : "success-base-code",
        "message"   : "Success base code"
      }
    ]
  },
  {
    "category"  : 206,
    // Define childs for level 2060xx like 206000
    "childs"    :  [
      {
        "code"      : "000",
        "codeHTTP"  : 200,
        "status"    : "success",
        "label"     : "success-partial",
        "message"   : "default"
      },
      {
        "category" : 100,
        // Define childs for level 2061xx like 206101
        "childs"   :  [
          {
            "code"      : "101",
            "status"    : "error",
            "codeHTTP"  : 200,
            "label"     : "account-base-error-code",
            "message"   : ""
          }
        ]
      }
    ]
  }
]

How to use

At the moment we only have 5 method implemented, see below :


var status = require('yocto-status-codes');

var successData = { message : 'Yeah !', data : { foo : 'bar' } };
var errorData = { message : 'Bad !', data : { foo : 'bar error' } };
var systemErrorData = { message : 'Very bad !', data : { foo : 'bar system' } };

// To retrieve a success reponse
status.success(successData);

// To add a specific message on base response just do
status.success(successData, 'message');
// it works too for error and system erro

// To retrieve an error reponse
status.error(errorData);

// To retrieve an system error reponse
status.systemError(systemErrorData);

// Load an JSON config file by passing his path
status.loadConfig('/home/config.json');

// Get an existing StatusCode from configuration file
status.get(200, 100);

// Get an existing StatusCode and override field "data" or/and "message"
status.get(200, 100, {
  message : 'overriden message', // optional field
  data    : [ 'this data was overriden' ] // optional field
});

Changelog

All history is here