remotedev-utils
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -7,4 +7,6 @@ 'use strict'; | ||
exports.getMethods = getMethods; | ||
exports.getActionsArray = getActionsArray; | ||
exports.evalAction = evalAction; | ||
exports.evalMethod = evalMethod; | ||
@@ -36,2 +38,22 @@ var _getParams = require('get-params'); | ||
function getMethods(obj) { | ||
if ((typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) !== 'object') return undefined; | ||
var functions = void 0; | ||
var m = void 0; | ||
if (obj.__proto__) m = obj.__proto__.__proto__; | ||
if (!m) m = obj; | ||
Object.getOwnPropertyNames(m).forEach(function (key) { | ||
var prop = m[key]; | ||
if (typeof prop === 'function' && key !== 'constructor') { | ||
if (!functions) functions = []; | ||
functions.push({ | ||
name: key || prop.name || 'anonymous', | ||
args: (0, _getParams2.default)(prop) | ||
}); | ||
} | ||
}); | ||
return functions; | ||
} | ||
function getActionsArray(actionCreators) { | ||
@@ -43,2 +65,14 @@ if (Array.isArray(actionCreators)) return actionCreators; | ||
/* eslint-disable no-new-func */ | ||
var interpretArg = function interpretArg(arg) { | ||
return new Function('return ' + arg)(); | ||
}; | ||
function evalArgs(inArgs, restArgs) { | ||
var args = inArgs.map(interpretArg); | ||
if (!restArgs) return args; | ||
var rest = interpretArg(restArgs); | ||
if (Array.isArray(rest)) return args.concat.apply(args, rest); | ||
throw new Error('rest must be an array'); | ||
} | ||
function evalAction(action, actionCreators) { | ||
@@ -50,14 +84,14 @@ if (typeof action === 'string') { | ||
var actionCreator = actionCreators[action.selected].func; | ||
var interpretArg = function interpretArg(arg) { | ||
return new Function('return ' + arg)(); | ||
}; | ||
var argsToInject = action.args.map(interpretArg); | ||
if (action.rest) { | ||
var _argsToInject; | ||
var args = evalArgs(action.args, action.rest); | ||
return actionCreator.apply(undefined, args); | ||
} | ||
var rest = interpretArg(action.rest); | ||
if (Array.isArray(rest)) argsToInject = (_argsToInject = argsToInject).concat.apply(_argsToInject, rest);else throw new Error('rest must be an array'); | ||
function evalMethod(action, obj) { | ||
if (typeof action === 'string') { | ||
return new Function('obj', 'return obj.' + action)(obj); | ||
} | ||
return actionCreator.apply(undefined, argsToInject); | ||
var args = evalArgs(action.args, action.rest); | ||
return new Function('obj', 'args', 'return obj.' + action.name + '.apply(obj,args)')(obj, args); | ||
} | ||
/* eslint-enable */ |
{ | ||
"name": "remotedev-utils", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Utils for remotedev infrastructure", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -20,2 +20,22 @@ import getParams from 'get-params'; | ||
export function getMethods(obj) { | ||
if (typeof obj !== 'object') return undefined; | ||
let functions; | ||
let m; | ||
if (obj.__proto__) m = obj.__proto__.__proto__; | ||
if (!m) m = obj; | ||
Object.getOwnPropertyNames(m).forEach(key => { | ||
const prop = m[key]; | ||
if (typeof prop === 'function' && key !== 'constructor') { | ||
if (!functions) functions = []; | ||
functions.push({ | ||
name: key || prop.name || 'anonymous', | ||
args: getParams(prop), | ||
}); | ||
} | ||
}); | ||
return functions; | ||
} | ||
export function getActionsArray(actionCreators) { | ||
@@ -27,2 +47,12 @@ if (Array.isArray(actionCreators)) return actionCreators; | ||
/* eslint-disable no-new-func */ | ||
const interpretArg = (arg) => (new Function('return ' + arg))(); | ||
function evalArgs(inArgs, restArgs) { | ||
const args = inArgs.map(interpretArg); | ||
if (!restArgs) return args; | ||
const rest = interpretArg(restArgs); | ||
if (Array.isArray(rest)) return args.concat(...rest); | ||
throw new Error('rest must be an array'); | ||
} | ||
export function evalAction(action, actionCreators) { | ||
@@ -34,11 +64,14 @@ if (typeof action === 'string') { | ||
const actionCreator = actionCreators[action.selected].func; | ||
const interpretArg = (arg) => (new Function('return ' + arg))(); | ||
let argsToInject = action.args.map(interpretArg); | ||
if (action.rest) { | ||
const rest = interpretArg(action.rest); | ||
if (Array.isArray(rest)) argsToInject = argsToInject.concat(...rest); | ||
else throw new Error('rest must be an array'); | ||
const args = evalArgs(action.args, action.rest); | ||
return actionCreator(...args); | ||
} | ||
export function evalMethod(action, obj) { | ||
if (typeof action === 'string') { | ||
return (new Function('obj', 'return obj.' + action))(obj); | ||
} | ||
return actionCreator(...argsToInject); | ||
const args = evalArgs(action.args, action.rest); | ||
return (new Function('obj', 'args', `return obj.${action.name}.apply(obj,args)`))(obj, args); | ||
} | ||
/* eslint-enable */ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7692
139
8