Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gengojs-core-modules

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gengojs-core-modules - npm Package Compare versions

Comparing version 2.1.1 to 2.1.2

8

CHANGELOG.md

@@ -0,1 +1,9 @@

2.1.1 / 2015-10-08
==================
* Release v2.1.1.
* Update
Updated change log.
Updated lib?
2.1.0 / 2015-10-08

@@ -2,0 +10,0 @@ ==================

108

lib/modules/plugify.js

@@ -18,15 +18,17 @@ import _ from 'lodash';

this.plugins = (() => {
// Check if defaults is empty
if (_.isEmpty(defaults)) {
// Fill the defaults with placeholders (functions that don't do anything)
_.forEach(['api', 'backend', 'parser', 'header', 'localize', 'router'], item => {
this.defaults[this.normalize(item)] = () => {};
this.defaults[Plugify.normalize(item)] = () => {};
});
return this.defaults;
}
_.forOwn(defaults, (value, key) => {
if (_.isFunction(value) && _.isPlainObject(value()))
this.defaults[key] = value();
} else Plugify.unPack(defaults, (key, plugin) => {
// Unpack the gengo-pack and generate the default plugins
Plugify.setPlugin(this.defaults, plugin, this.options);
});
return this.defaults;
})();
// Register the plugins
this.register(plugins);
// Debug
_.forOwn(this.plugins, (value, key) => {

@@ -38,2 +40,3 @@ var name = value.package ? value.package.name : '';

});
// Create the default options
_.defaultsDeep(options, this.options);

@@ -46,42 +49,52 @@ }

register(plugins) {
log.debug(`class: ${Plugify.name}`, `process: register`);
var process = (plugin) => {
if (_.isPlainObject(plugin)) {
if (!_.has(plugin, 'main') && (() => {
return _.forEach(Object.keys(plugin), key =>
key === 'api' || key === 'parser' || key === 'backend' ||
key === 'header' || key === 'localize' || key === 'router');
})()) {
if (_.forOwn(plugin, value => this.assert((() => {
return _.isFunction(value) ? value() :
_.isPlainObject(value) ? value : undefined;
})())))
_.forOwn(plugin, value => {
value = _.isFunction(value) ? value() :
_.isPlainObject(value) ? value : undefined;
this.setPlugin(value);
});
} else {
if (this.assert(plugin)) {
this.setPlugin(plugin);
log.debug(`class: ${Plugify.name}`, `process: register`);
var process = (plugin) => {
if (_.isPlainObject(plugin)) {
if (Plugify.isPack(plugin)) {
Plugify.unPack(plugin, (key, p) => {
if (Plugify.assert(p)) {
Plugify.setPlugin(this.plugins, p, this.options);
}
}
});
} else
if (Plugify.assert(plugin)) {
Plugify.setPlugin(this.plugins, plugin, this.options);
}
};
if (_.isArray(plugins)) {
_.forEach(plugins, plugin => {
plugin = _.isFunction(plugin) ? plugin() :
_.isPlainObject(plugin) ? plugin : undefined;
process(plugin);
});
} else if (_.isFunction(plugins)) {
process(plugins());
} else if (_.isPlainObject(plugins)) process(plugins);
}
};
if (_.isArray(plugins)) {
_.forEach(plugins, plugin => {
plugin = _.isFunction(plugin) ? plugin() :
_.isPlainObject(plugin) ? plugin : undefined;
process(plugin);
});
} else if (_.isFunction(plugins)) {
process(plugins());
} else if (_.isPlainObject(plugins)) process(plugins);
}
static isPack(plugin) {
return !_.has(plugin, 'main') && (() => {
return _.forEach(Object.keys(plugin), key =>
key === 'api' || key === 'parser' || key === 'backend' ||
key === 'header' || key === 'localize' || key === 'router');
})();
}
/**
* Unpacks the gengo-pack and returns the plugin
* through a callback
* @param {Object | Function} plugins The plugins to unpack.
* @param {Function} callback The callback function
*/
static unPack(plugins, callback) {
_.forOwn(plugins, (plugin, type) => {
callback(type, _.isFunction(plugin) ? plugin() : plugin);
});
}
/**
* Sets the attributes of the plugin
* @param {Object} plugin The plugin to set its attributes.
* @param {Object} object The object to set its attributes.
* @param {Object} plugin The plugin to apply to the object
* @param {Object} options The options to apply
*/
setPlugin(plugin) {
static setPlugin(object, plugin, options) {
log.debug(`class: ${Plugify.name}`, `process: setPlugin`);

@@ -94,11 +107,11 @@ var {

} = plugin.package;
type = this.normalize(type);
if (this.plugins[type]) this.plugins[type] = {};
type = Plugify.normalize(type);
if (object[type]) object[type] = {};
// Set the plugin fn
this.plugins[type] = main;
object[type] = main;
// Set the package
this.plugins[type].package = plugin.package;
object[type].package = plugin.package;
// Set the default options
if (!this.options[type])
this.options[type] = defaults;
if (!options[type])
options[type] = defaults;
}

@@ -111,3 +124,3 @@ /**

*/
normalize(str) {
static normalize(str) {
return str.toLowerCase().replace('-', '');

@@ -120,3 +133,3 @@ }

*/
assert(plugin) {
static assert(plugin) {
log.debug(`class: ${Plugify.name}`, `process: assert`);

@@ -138,3 +151,2 @@ try {

}
/**

@@ -141,0 +153,0 @@ * Returns the plugins after creating an instance

{
"name": "gengojs-core-modules",
"version": "2.1.1",
"version": "2.1.2",
"description": "gengo.js core modules is a set of modules that helps the core to function properly.",

@@ -5,0 +5,0 @@ "main": "src/modules/index.js",

@@ -41,14 +41,17 @@ 'use strict';

this.plugins = (function () {
// Check if defaults is empty
if (_lodash2['default'].isEmpty(defaults)) {
// Fill the defaults with placeholders (functions that don't do anything)
_lodash2['default'].forEach(['api', 'backend', 'parser', 'header', 'localize', 'router'], function (item) {
_this.defaults[_this.normalize(item)] = function () {};
_this.defaults[Plugify.normalize(item)] = function () {};
});
return _this.defaults;
}
_lodash2['default'].forOwn(defaults, function (value, key) {
if (_lodash2['default'].isFunction(value) && _lodash2['default'].isPlainObject(value())) _this.defaults[key] = value();
} else Plugify.unPack(defaults, function (key, plugin) {
// Unpack the gengo-pack and generate the default plugins
Plugify.setPlugin(_this.defaults, plugin, _this.options);
});
return _this.defaults;
})();
// Register the plugins
this.register(plugins);
// Debug
_lodash2['default'].forOwn(this.plugins, function (value, key) {

@@ -58,2 +61,3 @@ var name = value['package'] ? value['package'].name : '';

});
// Create the default options
_lodash2['default'].defaultsDeep(options, this.options);

@@ -84,19 +88,10 @@ }

if (_lodash2['default'].isPlainObject(plugin)) {
if (!_lodash2['default'].has(plugin, 'main') && (function () {
return _lodash2['default'].forEach(Object.keys(plugin), function (key) {
return key === 'api' || key === 'parser' || key === 'backend' || key === 'header' || key === 'localize' || key === 'router';
if (Plugify.isPack(plugin)) {
Plugify.unPack(plugin, function (key, p) {
if (Plugify.assert(p)) {
Plugify.setPlugin(_this2.plugins, p, _this2.options);
}
});
})()) {
if (_lodash2['default'].forOwn(plugin, function (value) {
return _this2.assert((function () {
return _lodash2['default'].isFunction(value) ? value() : _lodash2['default'].isPlainObject(value) ? value : undefined;
})());
})) _lodash2['default'].forOwn(plugin, function (value) {
value = _lodash2['default'].isFunction(value) ? value() : _lodash2['default'].isPlainObject(value) ? value : undefined;
_this2.setPlugin(value);
});
} else {
if (_this2.assert(plugin)) {
_this2.setPlugin(plugin);
}
} else if (Plugify.assert(plugin)) {
Plugify.setPlugin(_this2.plugins, plugin, _this2.options);
}

@@ -114,6 +109,30 @@ }

}
}], [{
key: 'isPack',
value: function isPack(plugin) {
return !_lodash2['default'].has(plugin, 'main') && (function () {
return _lodash2['default'].forEach(Object.keys(plugin), function (key) {
return key === 'api' || key === 'parser' || key === 'backend' || key === 'header' || key === 'localize' || key === 'router';
});
})();
}
/**
* Unpacks the gengo-pack and returns the plugin
* through a callback
* @param {Object | Function} plugins The plugins to unpack.
* @param {Function} callback The callback function
*/
}, {
key: 'unPack',
value: function unPack(plugins, callback) {
_lodash2['default'].forOwn(plugins, function (plugin, type) {
callback(type, _lodash2['default'].isFunction(plugin) ? plugin() : plugin);
});
}
/**
* Sets the attributes of the plugin
* @param {Object} plugin The plugin to set its attributes.
* @param {Object} object The object to set its attributes.
* @param {Object} plugin The plugin to apply to the object
* @param {Object} options The options to apply

@@ -123,3 +142,3 @@ */

key: 'setPlugin',
value: function setPlugin(plugin) {
value: function setPlugin(object, plugin, options) {
log.debug('class: ' + Plugify.name, 'process: setPlugin');

@@ -130,10 +149,10 @@ var main = plugin.main;

type = this.normalize(type);
if (this.plugins[type]) this.plugins[type] = {};
type = Plugify.normalize(type);
if (object[type]) object[type] = {};
// Set the plugin fn
this.plugins[type] = main;
object[type] = main;
// Set the package
this.plugins[type]['package'] = plugin['package'];
object[type]['package'] = plugin['package'];
// Set the default options
if (!this.options[type]) this.options[type] = defaults;
if (!options[type]) options[type] = defaults;
}

@@ -140,0 +159,0 @@

@@ -23,4 +23,23 @@ var assert = require('chai').assert;

})(), {}, plugs());
assert.isFunction(plugins.parser);
assert.equal(plugins.parser.package.name, 'override-parser');
assert.isFunction(plugins.router);
assert.equal(plugins.router.package.name, 'mocha-router');
plugins = plugify({}, {}, plugs());
assert.isFunction(plugins.router);
assert.equal(plugins.router.package.name, 'mocha-router');
plugins = plugify([(function(){
return {
main:function ship(){},
package: { name : 'override-parser', 'type': 'parser' },
defaults: {
greet:'hello'
}
};
})], {}, plugs());
assert.equal(plugins.parser.package.name, 'override-parser');
assert.isFunction(plugins.router);
assert.equal(plugins.router.package.name, 'mocha-router');
});

@@ -27,0 +46,0 @@ });

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc