1.0.4 • Published 5 years ago

core.constructor v1.0.4

Weekly downloads
3
License
ISC
Repository
-
Last release
5 years ago

Core

Kind: global class

new Core(options)

ParamTypeDescription
optionsobjectinstance options.
options.namestringa unique name for the instance.
options.pluginsarrayan array of plugins to initialize on the instance.
options.extendobjectif 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'.

ParamTypeDescription
thinganyanything 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.

ParamTypeDescription
thinganyanything 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.

ParamTypeDescription
thinganyanything 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.

ParamTypeDescription
thinganyanything 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.

ParamTypeDescription
thinganyanything 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.

ParamTypeDescription
thinganyanything 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.

ParamTypeDescription
thinganyanything 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.

ParamTypeDescription
thinganyanything 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.

ParamTypeDescription
thinganyanything 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.

ParamTypeDescription
thinganyanything 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 ).

ParamTypeDescription
targetobjectThe target object. properties will be copied to this object.
sourceobjectA source, or a number of source objects.
assignFuncfunctionA 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 ).

ParamTypeDescription
propertiesobjectAn

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

ParamTypeDescription
namestringThe name of the channel.
arrayarrayOptional array of functions.

Example

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

core.tap(name, func) ⇒ undefined

tap to a channel.

Kind: instance method of Core

ParamTypeDescription
namestringThe name of the channel.
funcfunctionA 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

ParamTypeDescription
namestringThe name of the channel.
dataanyData to be passed through the channel.
callbackfunctionA 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

ParamTypeDescription
definitionobjectThe plugin definition.
definition.namestringThe name of the plugin.
callbackfunctionA 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.
1.0.4

5 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago