Skip to content

Repository files navigation

Function to Code

github actioncodecov

func2code's main usage is to get the inner code of a function.

As a by-product, func2code can also get various information of the function, like params, name and name-code.

Import

ESM

importfunc2codefrom'func2code';

CJS

constfunc2code=require('func2code');

HTML

<scriptsrc="func2code/index.js"></script><script>/// <reference path="func2code/global.d.ts" />console.log(func2code);</script>

Usage

// Inputfunc2code.getInnerCode(()=>1+1);// Output'return 1+1;'
// Inputfunc2code.split(asyncfunctionabc(a,k,{[`${[1,2,3].join('')}`]: b},[c,d]){return1+2;});// Output{params: ['a','k',"{[`${[1,2,3].join('')}`]: b}",'[c, d]'],innerCode: '\n return 1 + 2;\n',nameCode: '"abc"',name: 'abc',isArrow: false,isAsync: true,isGetter: false,isSetter: false,isGenerator: false}
// Inputfunc2code.getNameCode({['n'+`${(()=>1+1)[['to','St','ri','ng',].join('')]()}`+123](n){returnn+1;}}['n()=>1+1123'])// Output"'n'+`${(()=>1+1)[[ 'to', 'St', 'ri', 'ng', ].join('')]()}`+123"

See all the test cases

About

Turn functions into strings

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages