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

remotedev-utils

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remotedev-utils - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

52

lib/index.js

@@ -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 */

2

package.json
{
"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 */
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