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

chain-of-custody

v2.0.0

Published

This demonstrates the chain of custody design pattern

Downloads

7

Readme

#chain-of-custody Chain of Custody design pattern for cleanly dealing with sequences of operations that may be asynchronous. ##Install npm install chain-of-custody

##Usage There are two key components, ChainItem and ChainBuilder. You won't care about ChainItem. The intent is to create a nice, readable chain of steps that are executed one by one with a generate way to exit the chain (i.e. by using an event) in the event of a failure.

###Example

import {ChainBuilder} from './../lib';
import {ICaughtException} from './../lib';
import * as fs from 'fs';

let chainBuilder = new ChainBuilder((data, next, error) => {
    fs.readFile(`${__dirname}/test.json`, 'UTF-8', (err, data) => {
        if(err){
            error(err);
        } else {
            next(data);
        }
    });
}).then((data, next, error) => {
    let json = JSON.parse(data.toString());
    json.updated = true;
    next(json);
}).then((data, next, error) => {
    fs.writeFile(`${__dirname}/tested.json`, JSON.stringify(data), (err) => {
        if(err){
            error(err);
        } else {
            next();
        }
    });
});

chainBuilder.on('exception', (err : ICaughtException) => {
    console.log(err);
});

chainBuilder.on('error', (err)=>{
    console.log(err);
});

chainBuilder.on('done', () => {
    console.log('ok');
});

chainBuilder.execute();

##API ###ChainBuilder::constructor(closure : (data?:any, next:(data?:any)=>void, error:(data?:any)=>void)) ###ChainBuilder::execute(data?:any):void Takes any data object as an initializer, if desired. ###ChainBuilder::then(closure : (data?:any, next:(data?:any)=>void, error:(data?:any)=>void)):void Next step in the chain. Must be a closure of that type. ###Events There are three events.

  • 'done' indicates that the chain has completed execution.
  • 'error' indicates that the chain has exited early due to an error condition because logic in the chain explicitly called the error function.
  • 'exception' indicates that there was an uncaught exception in the chain that was caught in ChainBuilder. The error object produced is an ICaughtException that contains an exception attribute (the exception object), and the data so that the state of the chain can be evaluated.

##Executing from Source The project is written in TypeScript because TypeScript is amazing. To get this to work, npm install -g typescript and then to get the typings support npm install -g typings and then run npm install in the project directory.