js2string
v1.0.2
Published
Convert JS functions, variables and etc... to String
Downloads
2
Readme
Simple code inside index.js:
export default function js2string(InputFunction) {
// {([^}]*)}
const regex = /{([^]*)}/g;
const exit = regex.exec(InputFunction.toString());
return exit[1];
}
RegExp Patterns
/{([^]*)}/g
– All In One Group/{([^}]*)}/g
– Multiply groups devided by (){}
inside of main (){}
/g
– is for global
search.
Examples
example.js
// Example code to convert
const body = () => {
console.log('Simple Example of source usage');
};
// Convert `const body` to string
function js2string(INPUT) {
const regex = /{([^]*)}/g;
const exit = regex.exec(INPUT.toString());
console.log(`${exit}`);
}
js2string(body);
Returns
${exit}
{
console.log('Simple Example of source usage');
},
console.log('Simple Example of source usage');
${exit[1]}
console.log('dataCollector() run SUCCESS');
/
exampleSoHard.js
// Example code to convert
const soHardExample = () => {
console.log('dataCollector() run SUCCESS');
const getInside = () => {
// so sweet.
}
const getMeOtherFunction = () => {
// so sweet too...
const sheDrivesMeCrazy = () => {
// mmm okay
}
() => {
// ahcucaraacha
}
}
};
// Convert `const body` to string
function js2string(INPUT) {
const regex = /{([^]*)}/g;
const exit = regex.exec(INPUT.toString());
console.log(`${exit}`);
}
js2string(soHardExample);
Returns
${exit[1]}
console.log('dataCollector() run SUCCESS');
const getInside = () => {
// so sweet.
}
const getMeOtherFunction = () => {
// so sweet too...
const sheDrivesMeCrazy = () => {
// mmm okay
}
() => {
// ahcucaraacha
}
}
Conclusion
You can modify that library to optimize some processes... any way it's just a simple code. It's all about mysterious...
😈 . . . 🔮 . . .