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 🙏

© 2026 – Pkg Stats / Ryan Hefner

digs-common

v0.2.11

Published

A moatload of common objects and functions shared by various Digs-related packages

Readme

digs-common NPM

Build Status Join the chat at https://gitter.im/digsjs/digs

A moatload of common objects and functions shared by various Digs-related packages

Usage

const common = require('digs-common');
const _ = common.utils; // `lodash` with some mixins
const Promise = common.Promise; // `bluebird`
const validator = common.validator; // `joi`
const define = common.define; // `stampit`
const definitions = common.definitions; // definitions ("stamps")

// example of a mixin (from package `slug`)
_.slugify('Hello, World!') // 'hello-world' 

API

Definitions

A "definition" is simply a "stamp". These are provided for use in plugins. They ease the addition of common functionality to any object.

const definitions = require('digs-common').definitions;

The following factory functions ("stamps") can be combined in any way you can think of to create new objects.

DigsObject

The DigsObject factory accepts a required second parameter, which is a Digs instance. Of course, this is simply a Hapi Server.

Logging Functionality

The definition provides the following logging methods (configurable), for convenience:

  • error(tags, data)
  • warn(tags, data)
  • info(tags, data)
  • debug(tags, data)
  • ok(tags, data)

Each of these is an alias to Server#log. The "level" used will be added as a tag (in addition to the namespace and project tags, and any other tags passed). For example:

const digs = require('digs');

digs({
  app: {
    namespace: 'digs',
    project: 'home'
  }
})
  .then((digsServer) => {
    const obj = DigsObject({}, digsServer);
    obj.info(['foo'], 'Bar!');
    // -> digsServer.log(['digs', 'home', 'info', 'foo'], 'Bar!');
  });

Additional tags must be specified as an Array. This allows you to simply:

obj.info('Bar!');

if no extra tags are necessary.

A log() method is also available which bypasses the "level":

obj.log(['baz'], 'Quux!');
// -> digsServer.log(['digs', 'home', 'baz'], 'Quux!');
Custom Logging Functions

To configure the "levels", provide a logColors object when instantiating:

const obj = DigsObject({
  logColors: {
    good: 'green',
    bad: 'yellow',
    ugly: 'red'
  }
}, digsServer);

Each color must be a valid chalk color.

Server Method Passthroughs

An object created with DigsObject() also has the following methods which pass through to the Server instance:

  • expose()
  • register()
  • method()
  • handler()
  • route()
  • decorate()

Currently, this list is fixed, but it may be changed to support all Server methods available in a plugin context.

DigsEmitter

DigsEmitter is a handy way to add EventEmitter functionality to any object.

The following code:

const obj = DigsEmitter()
  .methods({
    bonk() {
      this.emit('bonk');
    }
  });

is roughly equivalent to:

class DigsEmitter extends EventEmitter {
  bonk() {
    this.emit('bonk');
  }
};

const obj = new DigsEmitter();

See the stampit docs for more info.

DigsFSM

With DigsFSM, any object can be composed into a Promise-driven finite state machine.

const fsm = DigsFSM
  .methods({
    onbar(options) {
      console.log(`The "bar" event happened in state "${options.from}"`);
    }
  })
  .initial('foo')
  .events([
    {
      name: 'bar',
      from: 'foo',
      to: 'baz'
    }
  ])();

// triggers onbar() above; changes state to "baz"
fsm.bar()
  .then(() => {
    fsm.state === fsm.current === 'baz' // true
  });

The Promise implementation used is bluebird.

See the fsm-as-promised docs for more information.

DigsIdentifier

DigsIdentifier provides a way to identify objects. Each object is assigned a unique identifier (property id) if an identifier is not provided.

In addition, any definition composed from DigsIdentifier can identify itself, creating string representations (via Object.prototype.toString()) convenient for logging.

const HotDog = DigsIdentifier
  .static({
    defName: 'HotDog'
  });

const hotDog = HotDog();
`${hotDog}: I need mustard.`; // HotDog<HotDog#1>: I need mustard.
hotDog.id; // HotDog#1

const anotherHotDog = HotDog();
`${anotherHotDog}: I need ketchup.`; // HotDog<HotDog#2>: I need ketchup.
anotherHotDog.id; // HotDog#2

const bratwurst = HotDog({
  id: 'bratwurst'
});
`${bratwurst}: I need kraut.`; // HotDog<bratwurst>: I need kraut.
bratwurst.id; // bratwurst

DigsParamValidator, DigsPrevalidator & DigsInitValidator

TODO; general idea is that method parameter, object state upon method call, and instantiation can all be easily validated via Joi.

Author

Christopher Hiller

License

MIT