Socket
Socket
Sign inDemoInstall

async-to-gen

Package Overview
Dependencies
3
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.3.0 to 1.3.1

5

package.json
{
"name": "async-to-gen",
"version": "1.3.0",
"version": "1.3.1",
"description": "Transform async functions to generator functions with speed and simplicity.",

@@ -28,3 +28,4 @@ "author": "Lee Byron <lee@leebyron.com> (http://leebyron.com/)",

"async-to-gen",
"async-node"
"async-node",
"LICENSE"
],

@@ -31,0 +32,0 @@ "keywords": [

28

README.md

@@ -89,14 +89,24 @@ async-to-gen

As always, don't forget to use `async-to-gen` to compile files before distributing
your code on npm, as using the require hook affects the whole runtime and not
just your module.
You can also provide options to the require hook:
```js
// Include inline source maps for use with development tools.
require('flow-remove-types/register')({ sourceMaps: true })
// Disable inline source maps for use with development tools.
require('async-to-gen/register')({ sourceMaps: false })
```
Use options to define exactly which files to `includes` or `excludes` with regular
expressions. All files are included by default except those found in the
`node_modules` folder, which is excluded by default. Pass `excludes: null` to not
exclude any files.
```js
require('async-to-gen/register')({ includes: /\/custom_path\// })
```
> #### Don't use the require hook in packages distributed on NPM
> As always, don't forget to use `async-to-gen` to compile files before distributing
> your code on npm, as using the require hook affects the whole runtime and not
> just your module and may hurt the runtime performance of code that includes it.
## Use in Build Systems:

@@ -153,7 +163,7 @@

Testing your [express](http://expressjs.com/) app?
Try [supertest-as-promised](https://github.com/WhoopInc/supertest-as-promised) and async functions:
Try [supertest](https://github.com/visionmedia/supertest/) and async functions:
```js
const express = require('express')
const request = require('supertest-as-promised')
const request = require('supertest')

@@ -167,3 +177,3 @@ const app = express()

const response = await request(app).get('/foo')
expect(response).to.equal('bar')
expect(response.body).to.equal('bar')
})

@@ -170,0 +180,0 @@

@@ -5,6 +5,8 @@ var asyncToGen = require('./index');

//
// - sourceMaps: Include inline source maps. (default: false)
// - includes: A Regexp to determine which files should be transformed.
// - excludes: A Regexp to determine which files should not be transformed,
// defaults to ignoring /node_modules/, set to null to excludes nothing.
// - sourceMaps: Include inline source maps. (default: true)
// - includes: A Regexp/String to determine which files should be transformed.
// (alias: include)
// - excludes: A Regexp/String to determine which files should not be
// transformed, defaults to ignoring /node_modules/, provide null
// to exclude nothing. (alias: exclude)
var options;

@@ -28,3 +30,3 @@ module.exports = function setOptions(newOptions) {

module._compile = function _compile(code, filename) {
var sourceMaps = options && options.sourceMaps;
var sourceMaps = options && 'sourceMaps' in options ? options.sourceMaps : true;
var result = asyncToGen(code, options);

@@ -47,5 +49,31 @@ var code = result.toString();

function shouldTransform(filename, options) {
var includes = options && options.includes;
var excludes = options && 'excludes' in options ? options.excludes : /\/node_modules\//;
return (!includes || include.test(filename)) && !(excludes && excludes.test(filename));
var includes = options && regexpPattern(options.includes || options.include);
var excludes =
options && 'excludes' in options ? regexpPattern(options.excludes) :
options && 'exclude' in options ? regexpPattern(options.exclude) :
/\/node_modules\//;
return (!includes || includes.test(filename)) && !(excludes && excludes.test(filename));
}
// Given a null | string | RegExp | any, returns null | Regexp or throws a
// more helpful error.
function regexpPattern(pattern) {
if (!pattern) {
return pattern;
}
// A very simplified glob transform which allows passing legible strings like
// "myPath/*.js" instead of a harder to read RegExp like /\/myPath\/.*\.js/.
if (typeof pattern === 'string') {
pattern = pattern.replace(/\./g, '\\.').replace(/\*/g, '.*');
if (pattern[0] !== '/') {
pattern = '/' + pattern;
}
return new RegExp(pattern);
}
if (typeof pattern.test === 'function') {
return pattern;
}
throw new Error(
'async-to-gen: includes and excludes must be RegExp or path strings. Got: ' + pattern
);
}
SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc