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

qi-nodes

v1.0.1

Published

Base implementation for composite patterns in JavaScript.

Downloads

8

Readme

Version npmBuild StatusDependenciesCoverage StatusAPI Documentation

Qi Nodes

http://drkibitz.github.io/qi-nodes/

Base implementation for composite patterns in JavaScript.

Usage

Any object with its property of "root" set, qualifies as a rooted node. The root property is simply propagated up and down the leaves.

The module itself is a rooted NodeObject.

var nodes = require('qi-nodes');
console.log(nodes.root === nodes);
// > true

The previous fact doesn't limit you from having more rooted trees.

var root = nodes.createRoot();
console.log(root.root === nodes);
// > false

There are many ways to work with the API, but they follow the same pattern.

// pretty straight forward
n1 = root.append(nodes.create());
n2 = nodes.create().appendTo(root);

// The last argument is always the node context
n3 = nodes.append(nodes.create(), root);   // In this case it's the parent
n4 = nodes.appendTo(root, nodes.create()); // In this case it's the child

// Automatically append a newly created node by passing the parent to the create method.
n5 = nodes.create(root);

// > root -> n1, n2, n3, n4, n5, n6

Use instances of NodeObject to automatically use "this" as the node context. Which means the default value of the last optional argument in methods (With the exception of the create method), will be itself.

var singleNode = nodes.create();
n3 = singleNode.swap(n3);
// root -> n1, n2, singleNode, n4, n5, n6

The API works with generic objects. This is possible because members are simply property based. The only reason to use or extend the NodeObject constructor is if you like that flavor of API.

var root2 = nodes.createRoot(),
	n2_1 = nodes.append({}, root2),
    n2_2 = nodes.append({}, n2_1),
    n2_3 = nodes.append({}, n2_2);
// root2 -> n2_1 -> n2_2 -> n2_3

n2_3 = nodes.swap(n2_3, n2_1);
// root2 -> n2_3 -> n2_2 -> n2_1

Create a class that extends NodeObject as normal.

function MyNodeExtended() {}
MyNodeExtended.prototype = Object.create(nodes.NodeObject.prototype, {
	constructor: {value: MyNodeExtended}
});

var root = MyNodeExtended.prototype.createRoot();
var node = root.create(root);

console.log(root instanceof MyNodeExtended); // true
console.log(node instanceof MyNodeExtended); // true

Assign (mixin) the NodeObject prototype.

function MyNodeAssigned() {}
Object.assign(MyNodeAssigned.prototype, nodes.NodeObject.prototype);

var root = MyNodeAssigned.prototype.createRoot();
var node = root.create(root);

console.log(root instanceof MyNodeAssigned); // true
console.log(node instanceof MyNodeAssigned); // true

Swap nodes from one tree to another.

var root3 = nodes.createRoot();
    n3_1 = nodes.create(root3),
    n3_2 = nodes.create(n3_2),
    n3_3 = nodes.create(n3_3);
// root3 -> n3_1 -> n3_2 -> n3_3

n2_2 = n3_2.swap(n2_2);
// root2 -> n2_3 -> n3_2 -> n2_1
// root3 -> n3_1 -> n2_2 -> n3_3