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

message-catalog-manager

v3.0.1

Published

message catalog manager

Downloads

116

Readme

message-catalog-manager

Build Status Coverage Status

Overview

This module provides a mechanism for translating messages to provide user readable information. Messages support named and positional inserts to give context to the messages. Messages can include messages and actions, as well as urls for more information. A catloggedError class carries catalog message context information so errors thrown around a system can be translated at the appropriate point.

Catalog file format

The catalog manager works with a set of json message catalog files contain message text. These are indexed in a separate catalog index file which is provided to the catalog manager.

For an example of the catalog file format see: messages.json For an example of the catalog index file format see: catalog-index.json

Using message-catalog-manager

var MessageCatalogManager = require("message-catalog-manager").MessageCatalogManager;
var catalogManager = new MessageCatalogManager("/catalog-index.json");
var formattedMessage = catalogManager.getMessage("catalog1", "0001", {}, ["myapp"]);

Using catalogedError

var CatalogedError = require("message-catalog").CatalogedError;
throw new CatalogedError("0001", "catalog1", "An error occurred", ["myapp"]);

Express Middleware

If your Express application generates or receives a CatalogedError you can use the formattingMiddleware middleware to intercept all responses and attempt to format error responses before they are sent.

app.use(new ErrorFormattingMiddleware('catalog-index.json'));

There is a simple application that always responds with a CatalogedError in example. Start it like

node example/errorMiddlewareApp/errorMiddlewareApp.js

Release Notes

v1.0.0

  • Initial release

v2.0.0

  • Positional and named inserts can now be of type: undefined and object, in addition to string, number, boolean Objects and arrays will be stringified with the normal toString()
  • catalogedError constructor will throw for unsupported insert types

v2.1.0

  • Classes MessageCatalogManager and CatalogedError are exported with a capitalised class names
  • The message identifier for a CatalogedError instance renamed messageCode instead of messageNumber (it's type is string)
  • formattingMiddleware should be called as a function (not with new)
  • formattingMiddleware supports an optional function to transform messages before formatting:
    function myTransform(msg){
      // transform msg as required
      return msg;
    }
    app.use(messageCatalogManager.formattingMiddleware('catalog-index.json', myTransform));
    The function can be synchronous (return a transformed message object) or asynchronous (return a promise to a transformed message object)

v2.2.0

  • getMessage support for returning a data object.
    • Build data using a regex pattern matching keys in the namedInserts
    • Build data using a static definition in the catalog entry