Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/e0selmy4v/func2code
Turn functions into strings
https://github.com/e0selmy4v/func2code
code convert converter func function inline inner parser source
Last synced: 20 days ago
JSON representation
Turn functions into strings
- Host: GitHub
- URL: https://github.com/e0selmy4v/func2code
- Owner: E0SelmY4V
- License: mit
- Created: 2023-01-14T19:32:29.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-07-04T16:21:46.000Z (over 1 year ago)
- Last Synced: 2024-12-19T14:39:58.432Z (21 days ago)
- Topics: code, convert, converter, func, function, inline, inner, parser, source
- Language: JavaScript
- Homepage:
- Size: 57.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Function to Code
[![github action](https://github.com/E0SelmY4V/func2code/actions/workflows/test.yml/badge.svg)](https://github.com/E0SelmY4V/func2code/actions)
[![codecov](https://codecov.io/gh/E0SelmY4V/func2code/branch/master/graph/badge.svg?token=LAZE5B30HX)](https://codecov.io/gh/E0SelmY4V/func2code)*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
```ts
import func2code from 'func2code';
```### CJS
```js
const func2code = require('func2code');
```### HTML
```html
/// <reference path="func2code/global.d.ts" />
console.log(func2code);```
## Usage
```js
// Input
func2code.getInnerCode(()=>1+1);// Output
'return 1+1;'
``````js
// Input
func2code.split(async function abc(
a, k,
{[`${[1,2,3].join('')}`]: b},
[c, d]
) {
return 1 + 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
}
``````js
// Input
func2code.getNameCode({
['n'+`${(()=>1+1)[[
'to',
'St',
'ri',
'ng',
].join('')]()}`+123](n) {
return n + 1;
}
}['n()=>1+1123'])// Output
"'n'+`${(()=>1+1)[[ 'to', 'St', 'ri', 'ng', ].join('')]()}`+123"
```[See all the test cases](https://github.com/E0SelmY4V/func2code/blob/master/test/fn.js)