npm.io
0.0.2 • Published 4 years ago

fundefstr

Licence
MIT
Version
0.0.2
Deps
1
Size
5 kB
Vulns
0
Weekly
0

fundefstr

Function Definition String

Usage

import { compile } from 'fundefstr';

const exec = compile({
  func_1(params, next, back){
    return [params[0], params[1]]; // as same as: next([params[0], params[1]])
  },

  func_2([ value, counter ], next, back){
    if (counter < 10)
      back([value, counter + 1]);
    else
      next([value, counter]);
  },

  func_3(params, next, back){
    return params;
  }
});

const str = 'func_1,func_2,func_3:param_1,param_2';
const rel = await exec(str, { param_1: 'This is a param', param_2: 0 });

console.log(rel); // ['This is a param', 10]

Keywords