js2string

1.0.2 • Public • Published

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...

😈 . . . 🔮 . . .

Readme

Keywords

none

Package Sidebar

Install

npm i js2string

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

2.53 kB

Total Files

3

Last publish

Collaborators

  • zmnv