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

ctxobj

v0.3.0

Published

Objects with context, especially good for contextual logging

Downloads

1,579

Readme

ctxobj

Adds immutable context to objects. Good for contextual logging.

ctxobj.new(obj)

Decorates obj with a context. pushctx or popctx will create a child-object with the extended context. Child objects maintains an invisible link to parents.

var ctxobj = require('../main');

// just an object
var obj0 = { x: 1, y: { val: 2 } }

// decorate with context
var obj1 = ctxobj.new(obj0)

// create child objects by pushing and poping data to the context
var obj2 = obj1.pushctx('c1')
var obj3 = obj2.pushctx('c2a').pushctx('c2b')
var obj4 = obj1.pushctx('c3')
var obj5 = obj3.popctx().popctx();

// this will only change 'x' on obj5
obj5.x = 99;

// this will change y.val on all the objects (because we are not setting `y` itself)
obj5.y.val = 99;

Output:

obj0 --> { x: 1,  y: { val: 99 }, ctx: undefined }
obj1 --> { x: 1,  y: { val: 99 }, ctx: [] }
obj2 --> { x: 1,  y: { val: 99 }, ctx: [ 'c1' ] }
obj3 --> { x: 1,  y: { val: 99 }, ctx: [ 'c1', 'c2a', 'c2b' ] }
obj4 --> { x: 1,  y: { val: 99 }, ctx: [ 'c3' ] }
obj5 --> { x: 99, y: { val: 99 }, ctx: [ 'c1' ] }

ctxobj.console(console)

Decorates console-like objects with a context that is prepended to each console.xxx() call.

var ctxobj = require('ctxobj');

var log0 = ctxobj.console(console);
log0.info('no context yet');

var log1 = log0.pushctx('c1').pushctx('c2');
log1.warn('now with a two items in the context');

var log2 = log1.popctx();
log2.error('only one item in the context now');

Output:

no context yet
[c1] [c2] now with a two items in the context
[c1] only one item in the context now

ctxobj.object(parent)

Creates a child object from to parent. The child object is linked to that parent object via it's prototype, so properties of the parent object are available through the child.

Inspired by Douglas Crockford’s parasitic inheritence.

Licence

MIT