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

menhera

Package Overview
Dependencies
Maintainers
1
Versions
139
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

menhera - npm Package Compare versions

Comparing version 0.4.8 to 0.5.0

4

dist/menhera.js

@@ -16,4 +16,4 @@ "use strict";

_.hooks = {};
_.hooks._hooks = [_plugins._hooks];
_.hooks._mount = [_plugins._mount];
_.hooks._hooks = { _: [_plugins._hooks] };
_.hooks._mount = { _: [_plugins._mount] };
_.$use = (0, _plugins.$use)({ _: _ });

@@ -20,0 +20,0 @@ _.$use(parms);

@@ -10,4 +10,8 @@ "use strict";

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _utils = require("./utils");
var _lodash = require("lodash");
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

@@ -18,72 +22,84 @@

return function (parms) {
Object.keys(parms).forEach(function (_key) {
(0, _utils.bindHook)({ _: _, _key: _key, cp: parms });
});
};
};
var isVariable = function isVariable(_ref2) {
var object = _ref2.object,
depth = _ref2.depth,
_key = _ref2._key,
_val = _ref2._val;
var _hooks = exports._hooks = function _hooks(_ref2) {
var _ = _ref2._,
_key = _ref2._key,
_val = _ref2._val,
cp = _ref2.cp;
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
var hooks = (0, _lodash.get)(_.hooks, depth, []);
hooks.length > 0 && hooks.forEach(function (h) {
return h({ _: _, _key: _key, _val: _val, cp: parms });
});
};
var isObject = function isObject(_ref3) {
var object = _ref3.object,
depth = _ref3.depth,
_key = _ref3._key,
_val = _ref3._val;
try {
for (var _iterator = Object.entries(_val.bind(cp)())[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _ref3 = _step.value;
var rootHookDepth = (0, _utils.getRootHookDepth)(depth);
var hooks = (0, _lodash.get)(_.hooks, rootHookDepth, []);
hooks.length > 0 && hooks.forEach(function (h) {
return h({ _: _, _key: _key, _val: _val, cp: parms });
});
var _ref4 = _slicedToArray(_ref3, 2);
(0, _utils.scanObject)({ object: object, depth: depth, isObject: isObject, isVariable: isVariable, isFunction: isVariable });
};
var key = _ref4[0];
var val = _ref4[1];
if ((typeof parms === "undefined" ? "undefined" : _typeof(parms)) === "object") {
isObject({ object: parms });
}
return _;
};
};
if (val) {
if (!_.hooks[key]) {
_.hooks[key] = [];
}
var _hooks = exports._hooks = function _hooks(_ref4) {
var _ = _ref4._,
_key = _ref4._key,
_val = _ref4._val,
cp = _ref4.cp;
if (!_.hooks[key].includes(val.bind(cp))) {
_.hooks[key].push(val.bind(cp));
}
}
var isFunction = function isFunction(_ref5) {
var depth = _ref5.depth,
_val = _ref5._val;
var target = (0, _lodash.get)(_.hooks, depth, []);
if (!target.includes(_val.bind(cp))) {
target.push(_val.bind(cp));
(0, _lodash.set)(_.hooks, depth, target);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
};
var isObject = function isObject(_ref6) {
var object = _ref6.object,
depth = _ref6.depth,
_key = _ref6._key,
_val = _ref6._val;
(0, _utils.scanObject)({ object: object, depth: depth, isObject: isObject, isFunction: isFunction });
};
if ((typeof _val === "undefined" ? "undefined" : _typeof(_val)) === "object") {
isObject({ object: _val });
}
};
var _mount = exports._mount = function _mount(_ref5) {
var _ = _ref5._,
_key = _ref5._key,
_val = _ref5._val,
cp = _ref5.cp;
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
var _mount = exports._mount = function _mount(_ref7) {
var _ = _ref7._,
_key = _ref7._key,
_val = _ref7._val,
cp = _ref7.cp;
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator2 = Object.entries(_val)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _ref6 = _step2.value;
for (var _iterator = Object.entries(_val)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _ref8 = _step.value;
var _ref7 = _slicedToArray(_ref6, 2);
var _ref9 = _slicedToArray(_ref8, 2);
var key = _ref7[0];
var cps = _ref7[1];
var key = _ref9[0];
var val = _ref9[1];
cps.forEach(function () {
var _ref8 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(component) {
val.forEach(function () {
var _ref10 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(component) {
var cp, name;

@@ -98,9 +114,5 @@ return regeneratorRuntime.wrap(function _callee$(_context) {

_.cps[name] = cp;
_.$use(_.cps[name]);
_context.next = 5;
return Object.keys(cp).forEach(function (_key) {
(0, _utils.bindHook)({ _: _, _key: _key, cp: cp });
});
case 5:
case 4:
case "end":

@@ -114,3 +126,3 @@ return _context.stop();

return function (_x) {
return _ref8.apply(this, arguments);
return _ref10.apply(this, arguments);
};

@@ -120,12 +132,12 @@ }());

} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
if (_didIteratorError) {
throw _iteratorError;
}

@@ -136,83 +148,91 @@ }

var _config = exports._config = function _config(_ref9) {
var _ = _ref9._,
_key = _ref9._key,
_val = _ref9._val,
cp = _ref9.cp;
var _config = exports._config = {
_: function _(_ref11) {
var _ = _ref11._,
_key = _ref11._key,
_val = _ref11._val,
cp = _ref11.cp;
_.config = (0, _utils.ConfigMerger)(_.config, _val);
_.config = (0, _utils.ConfigMerger)(_.config, _val);
}
};
var _command = exports._command = function _command(_ref10) {
var _ = _ref10._,
_key = _ref10._key,
_val = _ref10._val,
cp = _ref10.cp;
var start = _val.start;
var _command = exports._command = {
_: function _(_ref12) {
var _this = this;
if (start) {
var _$config$lifeCycle = _.config.lifeCycle,
lifeCycle = _$config$lifeCycle === undefined ? [] : _$config$lifeCycle;
var _ = _ref12._,
_key = _ref12._key,
_val = _ref12._val,
cp = _ref12.cp;
var start = _val.start;
Object.values(_.cps).forEach(function () {
var _ref11 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(cp) {
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return lifeCycle.forEach(function (key) {
cp[key] && cp[key]();
});
if (start) {
var _$config$lifeCycle = _.config.lifeCycle,
lifeCycle = _$config$lifeCycle === undefined ? [] : _$config$lifeCycle;
case 2:
case "end":
return _context2.stop();
Object.values(_.cps).forEach(function () {
var _ref13 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(cp) {
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return lifeCycle.forEach(function (key) {
cp[key] && cp[key]();
});
case 2:
case "end":
return _context2.stop();
}
}
}
}, _callee2, undefined);
}));
}, _callee2, _this);
}));
return function (_x2) {
return _ref11.apply(this, arguments);
};
}());
return function (_x2) {
return _ref13.apply(this, arguments);
};
}());
}
}
};
var _methods = exports._methods = function _methods(_ref12) {
var _ = _ref12._,
_key = _ref12._key,
_val = _ref12._val,
cp = _ref12.cp;
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
var _methods = exports._methods = {
_: function _(_ref14) {
var _ = _ref14._,
_key = _ref14._key,
_val = _ref14._val,
cp = _ref14.cp;
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator3 = Object.entries(_val)[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var _ref13 = _step3.value;
try {
for (var _iterator2 = Object.entries(_val)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _ref15 = _step2.value;
var _ref14 = _slicedToArray(_ref13, 2);
var _ref16 = _slicedToArray(_ref15, 2);
var key = _ref14[0];
var val = _ref14[1];
var key = _ref16[0];
var val = _ref16[1];
if (!cp[key]) {
cp[key] = val.bind(cp);
} else {
console.warn(cp.name + " : \"" + key + "\" in methods is valid, Please use another one");
if (!cp[key]) {
cp[key] = val.bind(cp);
} else {
console.warn(cp.name + " : \"" + key + "\" in methods is valid, Please use another one");
}
}
}
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return) {
_iterator3.return();
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}

@@ -223,22 +243,26 @@ }

var _data = exports._data = function _data(_ref15) {
var _ = _ref15._,
_key = _ref15._key,
_val = _ref15._val,
cp = _ref15.cp;
var _iteratorNormalCompletion4 = true;
var _didIteratorError4 = false;
var _iteratorError4 = undefined;
var _data = exports._data = function _data(_ref17) {
var _ = _ref17._,
_key = _ref17._key,
_val = _ref17._val,
cp = _ref17.cp;
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
try {
for (var _iterator4 = Object.entries(_val.bind(cp)())[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
var _ref16 = _step4.value;
for (var _iterator3 = Object.entries(_val.bind(cp)())[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var _ref18 = _step3.value;
var _ref17 = _slicedToArray(_ref16, 2);
var _ref19 = _slicedToArray(_ref18, 2);
var key = _ref17[0];
var val = _ref17[1];
var key = _ref19[0];
var val = _ref19[1];
if (!cp[key]) {
cp[key] = val;
if (typeof val === "function") {
cp[key] = val.bind(cp);
} else {
cp[key] = val;
}
} else {

@@ -249,12 +273,12 @@ console.warn(cp.name + " : \"" + key + " \" is data is valid, Please use another one");

} catch (err) {
_didIteratorError4 = true;
_iteratorError4 = err;
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion4 && _iterator4.return) {
_iterator4.return();
if (!_iteratorNormalCompletion3 && _iterator3.return) {
_iterator3.return();
}
} finally {
if (_didIteratorError4) {
throw _iteratorError4;
if (_didIteratorError3) {
throw _iteratorError3;
}

@@ -261,0 +285,0 @@ }

@@ -7,2 +7,6 @@ "use strict";

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

@@ -12,29 +16,9 @@

var bindHook = exports.bindHook = function bindHook(_ref) {
var _ = _ref._,
_key = _ref._key,
cp = _ref.cp;
var hook = _.hooks[_key];
var _val = cp[_key];
if (Array.isArray(hook)) {
hook.forEach(function (h) {
if (typeof h === "function") {
h({ _: _, _key: _key, _val: _val, cp: cp });
}
});
} else {
if (typeof hook === "function") {
hook({ _: _, _key: _key, _val: _val, cp: cp });
}
}
};
var initConfig = { lifeCycle: ["awake", "start"] };
var ConfigMerger = function ConfigMerger() {
var currentConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initConfig;
var _ref2 = arguments[1];
var _ref = arguments[1];
var lifeCycle = _ref2.lifeCycle,
other = _objectWithoutProperties(_ref2, ["lifeCycle"]);
var lifeCycle = _ref.lifeCycle,
other = _objectWithoutProperties(_ref, ["lifeCycle"]);

@@ -45,2 +29,76 @@ return _extends({

};
exports.ConfigMerger = ConfigMerger;
exports.ConfigMerger = ConfigMerger;
var scanObject = exports.scanObject = function scanObject(_ref2) {
var object = _ref2.object,
_ref2$depth = _ref2.depth,
depth = _ref2$depth === undefined ? null : _ref2$depth,
_ref2$isObject = _ref2.isObject,
isObject = _ref2$isObject === undefined ? function () {} : _ref2$isObject,
_ref2$isFunction = _ref2.isFunction,
isFunction = _ref2$isFunction === undefined ? function () {} : _ref2$isFunction,
_ref2$isVariable = _ref2.isVariable,
isVariable = _ref2$isVariable === undefined ? function () {} : _ref2$isVariable;
if (object) {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = Object.entries(object)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _ref3 = _step.value;
var _ref4 = _slicedToArray(_ref3, 2);
var _key = _ref4[0];
var _val = _ref4[1];
if (_val) {
var newDepth = depth ? depth + ("." + _key) : _key;
if (typeof _val === "function") {
isFunction({
object: object,
depth: newDepth,
_key: _key,
_val: _val
});
} else if ((typeof _val === "undefined" ? "undefined" : _typeof(_val)) === "object" && !Array.isArray(_val)) {
isObject({
object: object[_key],
depth: newDepth,
_key: _key,
_val: _val
});
} else {
isVariable({
object: object,
depth: newDepth,
_key: _key,
_val: _val
});
}
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
} else {
console.warn("scanObject: object must be valid");
}
};
var getRootHookDepth = exports.getRootHookDepth = function getRootHookDepth(depth) {
return depth + "._";
};
{
"name": "menhera",
"version": "0.4.8",
"version": "0.5.0",
"main": "dist",

@@ -16,2 +16,3 @@ "files": [

"@types/koa": "^2.0.44",
"@types/koa-router": "^7.0.27",
"@types/minimist": "^1.2.0",

@@ -22,2 +23,3 @@ "babel-cli": "^6.26.0",

"koa": "^2.5.0",
"koa-router": "^7.4.0",
"menhera": "^0.4.5",

@@ -27,3 +29,6 @@ "minimist": "^1.2.0",

},
"dependencies": {}
"dependencies": {
"@types/lodash": "^4.14.104",
"lodash": "^4.17.5"
}
}

@@ -12,18 +12,15 @@ # Menhera

const _data = ({ _val }) => {
const { data } = _val;
console.log(data);
};
const test = ({ _val }) => console.log(_val);
const _ = new Menhera({
_hooks: () => ({
_data
}),
_data: {
data: "foo"
_hooks: {
data: {
test1: test,
test2: test
}
},
data: {
test1: "foo",
test2: "bar"
}
}).$use({
_data: {
data: "bar"
}
});

@@ -35,10 +32,12 @@ ```

const _data = {
const test = ({ _val }) => console.log(_val);
const mount = {
name: "data",
_hooks: () => ({
_data: ({ _val }) => {
const { data } = _val;
console.log(data);
_hooks: {
data: {
test1: test,
test2: test
}
})
}
};

@@ -48,12 +47,10 @@

_mount: {
foo: [_data]
},
_data: {
data: "foo"
foo: [mount]
}
}).$use({
_data: {
data: "bar"
data: {
test1: "foo",
test2: "bar"
}
});
```
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