Socket
Socket
Sign inDemoInstall

degenerator

Package Overview
Dependencies
8
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.2 to 0.0.3

.travis.yml

10

History.md
0.0.3 / 2014-04-04
==================
* package: update outdated dependencies
* package: add "respository" field
* index: add JSDoc comments
* index: remove `opts` option logic
* add .travis.yml file
* test: initial test
0.0.2 / 2013-12-06

@@ -3,0 +13,0 @@ ==================

26

index.js

@@ -24,13 +24,11 @@

/**
* Turns a sync JavaScript function into an async Generator Function.
* Turns sync JavaScript code into an JavaScript with async Generator Functions.
*
* @param {String} jsStr JavaScript string to convert
* @param {Array} names Array of function names to add `yield` operators to
* @return {String} Converted JavaScript string with Generator functions injected
* @api public
*/
function degenerator (fn, opts) {
var names;
if (opts) {
if (Array.isArray(opts)) names = opts;
else if (Array.isArray(opts.names)) names = opts.names;
}
function degenerator (jsStr, names) {
if (!Array.isArray(names)) {

@@ -40,3 +38,3 @@ throw new TypeError('an array of async function "names" is required');

var ast = esprima.parse(fn);
var ast = esprima.parse(jsStr);
types.traverse(ast, function (node) {

@@ -65,4 +63,2 @@

//console.error(JSON.stringify(node, null, 2));
//console.error('\n');
});

@@ -74,3 +70,8 @@ return escodegen.generate(ast);

* Returns `true` if `node` has a matching name to one of the entries in the
* `names` array
* `names` array.
*
* @param {types.Node} node
* @param {Array} names Array of function names to return true for
* @return {Boolean}
* @api private
*/

@@ -86,5 +87,4 @@

} else {
throw new Error('don\'t know how to get type for: ' + callee.type);
throw new Error('don\'t know how to get name for: ' + callee.type);
}
//console.error(name);

@@ -91,0 +91,0 @@ // now that we have the `name`, check if any entries match in the `names` array

{
"name": "degenerator",
"version": "0.0.2",
"version": "0.0.3",
"description": "Turns sync functions into async generator functions",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "mocha --reporter spec test/test.js"
},
"author": "Nathan Rajlich <nathan@tootallnate.net> (http://n8.io/)",
"repository": {
"type": "git",
"url": "git://github.com/TooTallNate/node-degenerator.git"
},
"license": "MIT",
"dependencies": {
"esprima": "git://github.com/ariya/esprima.git#harmony",
"escodegen": "~1.0.0",
"ast-types": "~0.3.11"
"escodegen": "~1.3.1",
"ast-types": "~0.3.22"
},
"devDependencies": {
"mocha": "~1.15.1",
"regenerator": "~0.3.1"
"mocha": "~1.18.2"
}
}

@@ -8,3 +8,3 @@ degenerator

This module takes a String to one or more synchronous JavaScript functions, and
returns a new String that with those JS functions transpiled into an ES6 Generator
returns a new String that with those JS functions transpiled into ES6 Generator
Functions.

@@ -70,3 +70,3 @@

var vm = require('vm');
var degenerate = require('degenerate');
var degenerator = require('degenerator');

@@ -90,3 +90,3 @@ // the `get()` function is thunk-based (error handling omitted for brevity)

// convert the JavaScript string provided from the user (assumed to be `str` var)
str = degenerate(str, [ 'get' ]);
str = degenerator(str, [ 'get' ]);

@@ -99,3 +99,5 @@ // at this stage, you could use a transpiler like `facebook/regenerator`

// use `visionmedia/co` to create an async function from the generator function
// use a generator-based flow control library (`visionmedia/co`, `jmar777/suspend`,
// etc.) to create an async function from the generator function.
var asnycFn = co(genFn);

@@ -102,0 +104,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc