lukeed

rewrite-async

Rewrite async functions as generators; via RegExp

Unlike async-to-gen, this does not register a runtime. Instead, the "transpiling" occurs only as needed.

Also, this is only executes a string conversion! You will have to look to other modules in order to execute the returned string.

Note: Although eval() will work, it's generally (and strongly) not recommended.

Built with Bluebird.coroutine in mind. 😉

#Install

$ npm install --save rewrite-async

#Usage

const rewriteAsync = require('rewrite-async');

rewriteAsync('async function (one, two) {}');
//=> 'function* (one, two) {}'

rewriteAsync('var foo = async (req, res) => {}');
//=> 'var foo = function* (one, two) {}'

rewriteAsync('async one => await foo(one)');
//=> 'function* (one) {return yield foo(one)}'

#API

#rewriteAsync(input)

#input

Type: string

A function's contents (via .toString()) or any utf-8 string that contains function definitions.

#License

MIT © Luke Edwards

See also

clsx(3), @polka/cluster(3), @pwa/cli(3), uvu(3), taskr(3), sockette(3), klona(3), kleur(3), dequal(3), sirv-cli(3)