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

wellspring

v1.3.1

Published

Prototype library for pluggable systems.

Downloads

2

Readme

Wellspring

Install

npm install --save wellspring

API

ws(object) -> wellspring instance

ws would be the constructor of wellspring.

ws(object).inherit() -> new object

Create a new object that inherits from object.

The new object will have object as its prototype.

This is a style of differential inheritance.

ws(object).extend(source) -> object

Add properties from a source object to the object.

ws(object).extendReadOnly(source) -> object

Add read only properties to the object from a source object.

Warning: Right now properties set with extendReadOnly are iterable, and configurable. This could change in the future.

ws(object).compose(objects, ...) -> new object

Create a new object that inherits from object, and has all the properties of the objects. :)

Objects in the right most position have precedence so if more the one of the objects has the same property the right most wins.

Compose pretty much works like extend, but creates a new object as well.

ws(object).inject(arg(s), ..., callback) -> promise

Pass a callback to inject that will be called immediately.

The arg(s) argument is optional. arg(s) is the arguments of callback arg(s) can be an array.

When no arg(s) is passed then the default argument is the object.

Return a promise from the callback to preserve asynchronous integrity.

inject always returns a promise, but if you do synchronous stuff in the inject callback you don't have to wait for the promise to resolve. You can use what ever you do in the callback right away.

You can return anything from the callback. inject will always return a promise. Even if you don't use that promise.

ws().create(object) -> wellspring instance

Create a wellspring instance that operates on object. You shouldn't need to do this usually.

ws(object).define(name, descriptor) -> object

Create a property on object with name using a javascript property descriptor.

ws(object).has(name, onThePrototype) -> boolean

Check if the property name exists on the object.

onThePrototype is an optional boolean argument to allow checking on the prototype chain.

ws(object).clean() -> undefined

Calling clean deletes all the properties of an object.

ws(object).affix(source, ...|enumerable) -> object

Extend object with enumerable, and emutable properties from source.

Add as many sources as you want.

You can allow the properties to be enumerable by passing true to the enumerable argument. The enumerable argument is just the last argument even if you pass multiple sources.

ws(object).bind(source, descriptor) -> undefined

bind gives all the methods of source to object. source should at least have some enumerable properties that have functions as values.

Those methods have there this variable set to source.

descriptor is an optional argument that should be a property data descriptor. This property descriptor is cloned, and applied to all methods set to object. The descriptor's value is set to those method functions from source.

Example:

var ws = require('wellspring');

var obj = {};

ws(obj).extend({
    greeting: 'Hi',
    print: function(val){
        console.log(val);
    }
});


ws(obj).inject((obj) => {
    ws(obj).extend({
        greet: function(){
            this.print(this.greeting + ' all!')
        }
    });
});

ws(obj).inject((obj) => {
    return new Promise(resolve => {
        obj.bla = 'bla'
        resolve();
    });
}).then(function(){
    //The bla property would be ready now.
});

// Create a new object that has obj as it's prototype.
var obj2 = ws(obj).inherit();

obj2.greet() //Hi all!

See the EXAMPLES.md file in the wellspring git repository for more.

Why?

Differential inheritance is good for speedy programming, inheritance, and plugin systems.

There is also stampit which is a nice library you might want to try. stampit is the original differential inheritance library.

When?

In the opinion of the creator of this library differential inheritance can be used anywhere, but is best used for plugin systems.

Reading

This library is using the super permissive license WTFPL.