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

@krab/op

v1.0.1

Published

Basic building block of domain logic

Downloads

5

Readme

op

v1.0.0

We follow [breaking].[feature].[fix] versioning

npm install --save @krab/op

This module provides a building-block for domain logic. Any software can be writtent using op in such a way that all of the domain logic in the software will be completely unit-testable. Usage given below.

Usage
import Op from '@krab/op'; // in projects with ES7 modules
const  Op = require('@krab/op/common'); // in projects with common JS modules

const domainOp = new Op(({db, api}) => {
  return db.getResults() // returns a promise
    .then((dbResults) => api.processData(dbResults))
  ;
});

// OR

const domainOp = new Op(async ({db, api}) => {
  const dbResults = await db.getResults();
  const apiResults = await api.processData(dbResults);

  return apiResults;
}, { // this param is optional
  doc: 'Does somthing with db and api',
  types: {
    db: (db) => db instanceof Db,
    api: (api) => api instanceof Api
  }
});

domainOp.mount({db: new Db(config.db), api: new Api(config.api)});
const results = await domainOp.run();
domainOp.run().then((results) => {});

// OR

domainOp.run({db: new Db(config.db), api: new Api(config.api)});
Features
  1. An op is either async, or returns a Promise.
  2. Failure to comply with 1. will result in a runtime-error.
  3. An op can have a doc string attached to it.
  4. An op can have types associated with it, which will be used to validate the params supplied to the op.
  5. An op can be run in 2 ways: op.run(params) or op.mount(params).run().
  6. op.mount mounts a set of params in the op, so that op.run can be called without any arguments.
  7. An op can be cloned using op.clone().
  8. An op.vent is an event-aggregator on which the events 'start', 'err', 'done', and 'end' are emitted at appropriate times in the lifecyclt of the op.
Op Events

op uses @krab/vent(link). Each instance of class Op has a property vent, which is an event aggregator attached to that instance. Usage of op.vent given below.

const op = new Op(...);

op.vent.on('start', ({op, params}) => {...});
op.vent.on('err', ({op, err, params}) => {...});
op.vent.on('done', ({op, result, params}) => {...});
op.vent.on('end', ({op, success, params}) => {...});