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

core.constructor

v1.0.4

Published

a constructor for a bare skeleton that can be extended by plugins

Downloads

528

Readme

Core

Kind: global class

new Core(options)

| Param | Type | Description | | --- | --- | --- | | options | object | instance options. | | options.name | string | a unique name for the instance. | | options.plugins | array | an array of plugins to initialize on the instance. | | options.extend | object | if provided, this object will be merged in to the new instance. |

Example

var core = new Core({
    name: 'client-core',
    plugins: [
        require('./pluginA'),
        require('./pluginB')
    ],
    extend: {
        doStuff(){ ... }
    }
});

core.typeOf(thing) ⇒ string

Returns the correct native type in javascript ( unlike the 'typeof' operator ).

Kind: instance method of Core
Returns: string - The native javascript type - 'undefined', 'null', 'boolean', 'number', 'string', 'array', 'object' or 'function'.

| Param | Type | Description | | --- | --- | --- | | thing | any | anything you want. |

Example

typeof null; // 'object'
typeof []; // 'object'

core.typeOf(null); // 'null'
core.typeOf([]); // 'array'

core.isUndefined(thing) ⇒ boolean

Checks if a value is undefined.

Kind: instance method of Core
Returns: boolean - - true if 'thing' is undefined. false otherwise.

| Param | Type | Description | | --- | --- | --- | | thing | any | anything you want. |

Example

core.isUndefined(null); // false

core.isNull(thing) ⇒ boolean

Checks if a value is null.

Kind: instance method of Core
Returns: boolean - - true if 'thing' is null. false otherwise.

| Param | Type | Description | | --- | --- | --- | | thing | any | anything you want. |

Example

core.isNull(null); // true

core.isBoolean(thing) ⇒ boolean

Checks if a value is a boolean.

Kind: instance method of Core
Returns: boolean - - true if 'thing' is boolean. false otherwise.

| Param | Type | Description | | --- | --- | --- | | thing | any | anything you want. |

Example

core.isBoolean(false); // true
core.isBoolean(''); // false

core.isNumber(thing) ⇒ boolean

Checks if a value is a number.

Kind: instance method of Core
Returns: boolean - - true if 'thing' is a number. false otherwise.

| Param | Type | Description | | --- | --- | --- | | thing | any | anything you want. |

Example

core.isNumber('35'); // false
core.isNumber(35); // true

core.isString(thing) ⇒ boolean

Checks if a value is a string.

Kind: instance method of Core
Returns: boolean - - true if 'thing' is a string. false otherwise.

| Param | Type | Description | | --- | --- | --- | | thing | any | anything you want. |

Example

core.isString('35'); // true
core.isString(35); // false

core.isDate(thing) ⇒ boolean

Checks if a value is a date object.

Kind: instance method of Core
Returns: boolean - - true if 'thing' is an array. false otherwise.

| Param | Type | Description | | --- | --- | --- | | thing | any | anything you want. |

Example

core.isDate('6/3/81'); // false
core.isDate(new Date('6/3/81')); // true

core.isArray(thing) ⇒ boolean

Checks if a value is an array.

Kind: instance method of Core
Returns: boolean - - true if 'thing' is an array. false otherwise.

| Param | Type | Description | | --- | --- | --- | | thing | any | anything you want. |

Example

core.isArray({}); // false
core.isArray([]); // true

core.isObject(thing) ⇒ boolean

Checks if a value is an object.

Kind: instance method of Core
Returns: boolean - - true if 'thing' is an object. false otherwise.

| Param | Type | Description | | --- | --- | --- | | thing | any | anything you want. |

Example

core.isObject({}); // true
core.isObject([]); // false

core.isFunction(thing) ⇒ boolean

Checks if a value is a function.

Kind: instance method of Core
Returns: boolean - - true if 'thing' is a function. false otherwise.

| Param | Type | Description | | --- | --- | --- | | thing | any | anything you want. |

Example

core.isFunction({}); // false
core.isFunction(e => {}); // true

core.assign(target, source, assignFunc) ⇒ object

Copies all properties from 'source' to 'target', similar to Object.assign.

Kind: instance method of Core
Returns: object - - The target object ( the first parameter ).

| Param | Type | Description | | --- | --- | --- | | target | object | The target object. properties will be copied to this object. | | source | object | A source, or a number of source objects. | | assignFunc | function | A function that will be called for each property assignment. if provided, the assigned value will be the return value of this function. |

Example

core.assign({}, {a: 1, b: 2}, (property, key, source) => property + 1);   // { a: 2, b: 3 }

core.extend(properties) ⇒ object

Copies all members in 'properties' to the core instance.

Kind: instance method of Core
Returns: object - - Returns the target object ( the first parameter ).

| Param | Type | Description | | --- | --- | --- | | properties | object | An |

Example

core.extend({
    getData(){ return this.myData; },
    myData: 45
});

core.getData();  // 45.
core.myData;  // 45.

core.channel(name, array) ⇒ undefined

Adds a new channel to the channels namespace object.

Kind: instance method of Core

| Param | Type | Description | | --- | --- | --- | | name | string | The name of the channel. | | array | array | Optional array of functions. |

Example

core.channel('collection');
core.channels.collection; // [].

core.tap(name, func) ⇒ undefined

tap to a channel.

Kind: instance method of Core

| Param | Type | Description | | --- | --- | --- | | name | string | The name of the channel. | | func | function | A function to attach to the channel. |

Example

core.channel('dataType');

core.tap('dataType', (dataType, done) => {
    dataType.test = 'ok';
    done(dataType);
});

core.fire('dataType', {}, (dataType) => {
    dataType.test; // 'ok'
});

core.fire(name, data, callback) ⇒ undefined

Runs data through a named channel.

Kind: instance method of Core

| Param | Type | Description | | --- | --- | --- | | name | string | The name of the channel. | | data | any | Data to be passed through the channel. | | callback | function | A function that will be called when the job completes. |

Example

core.channel('dataType', (dataType, done) => {
    dataType.test = 'ok';
    done(dataType);
});

core.fire('dataType', {}, (dataType) => {
    dataType.test; // 'ok'
});

core.plugin(definition, callback) ⇒ undefined

Adds a plugin to core instance.

Kind: instance method of Core

| Param | Type | Description | | --- | --- | --- | | definition | object | The plugin definition. | | definition.name | string | The name of the plugin. | | callback | function | A function that will be called when the job completes. |

Example

core.plugin({
    name: 'myPlugin',
    extend: {
        getData(){ return core.plugins.myPlugin.data; }
    },
    init(def, done){
        done({ data: 47 })
    }
});
core.getData();  // 47.