parse-function
Advanced tools
Comparing version 5.6.2 to 5.6.3
@@ -6,2 +6,15 @@ # Change Log | ||
## [5.6.3](https://github.com/tunnckoCore/opensource/compare/parse-function@5.6.2...parse-function@5.6.3) (2020-02-04) | ||
### Bug Fixes | ||
* bugs, missing deps, docs ([e769ef4](https://github.com/tunnckoCore/opensource/commit/e769ef467a254e534948bc6ca0a59db52cc55b3f)) | ||
* coverage bugs, regen ([997f459](https://github.com/tunnckoCore/opensource/commit/997f459bff26b47f9119b4b7046f7b7d8b7afd6c)) | ||
* readme generation, API heading ([aa96c3f](https://github.com/tunnckoCore/opensource/commit/aa96c3f06af5a27b0e3b4119b92a9f7978e0e251)) | ||
## [5.6.2](https://github.com/tunnckoCore/opensource/compare/parse-function@5.6.1...parse-function@5.6.2) (2020-02-03) | ||
@@ -8,0 +21,0 @@ |
{ | ||
"name": "parse-function", | ||
"version": "5.6.2", | ||
"version": "5.6.3", | ||
"licenseStart": 2016, | ||
@@ -86,3 +86,3 @@ "license": "MPL-2.0", | ||
"method": "preWrite", | ||
"maxdepth": 4 | ||
"maxdepth": 3 | ||
}, | ||
@@ -115,3 +115,3 @@ "layout": "empty", | ||
}, | ||
"gitHead": "53ea9daed9e587e9f61d03f59cbbcad9e5ea1d17" | ||
"gitHead": "36720fdd18247b0ce9134b9631a6d5848e6c6c0d" | ||
} |
189
README.md
@@ -13,4 +13,3 @@ <p align="center"> | ||
> Parse a function into an object using espree, acorn or babylon parsers. | ||
> Extensible through Smart Plugins | ||
> Parse a function into an object using espree, acorn or babylon parsers. Extensible through Smart Plugins | ||
@@ -93,27 +92,34 @@ Please consider following this project's author, | ||
- [Install](#install) | ||
- [parseFunction](#parsefunction) | ||
- [Signature](#signature) | ||
- [Params](#params) | ||
- [Examples](#examples) | ||
- [.parse](#parse) | ||
- [Params](#params-1) | ||
- [Examples](#examples-1) | ||
- [.use](#use) | ||
- [Params](#params-2) | ||
- [Examples](#examples-2) | ||
- [.define](#define) | ||
- [Params](#params-3) | ||
- [Examples](#examples-3) | ||
- [Which version to use?](#which-version-to-use) | ||
- [Notes](#notes) | ||
* [Throws in one specific case](#throws-in-one-specific-case) | ||
* [Function named _"anonymous"_](#function-named-_anonymous_) | ||
* [Real anonymous function](#real-anonymous-function) | ||
* [Plugins Architecture](#plugins-architecture) | ||
- [API](#api) | ||
* [parseFunction](#parsefunction) | ||
+ [Signature](#signature) | ||
+ [Params](#params) | ||
+ [Examples](#examples) | ||
* [.parse](#parse) | ||
+ [Params](#params-1) | ||
+ [Examples](#examples-1) | ||
* [.use](#use) | ||
+ [Params](#params-2) | ||
+ [Examples](#examples-2) | ||
* [.define](#define) | ||
+ [Params](#params-3) | ||
+ [Examples](#examples-3) | ||
- [Contributing](#contributing) | ||
- [Guides and Community](#guides-and-community) | ||
- [Support the project](#support-the-project) | ||
* [Guides and Community](#guides-and-community) | ||
* [Support the project](#support-the-project) | ||
- [Contributors](#contributors) | ||
- [License](#license) | ||
_(TOC generated by [verb](https://github.com/verbose/verb) using | ||
[markdown-toc](https://github.com/jonschlinkert/markdown-toc))_ | ||
_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_ | ||
## Install | ||
This project requires [**Node.js**](https://nodejs.org) **>=8.11** _(see | ||
This project requires [**Node.js**](https://nodejs.org) **>=8.11** | ||
_(see | ||
[Support & Release Policy](https://github.com/tunnckoCoreLabs/support-release-policy))_. | ||
@@ -128,2 +134,136 @@ Install it using [**yarn**](https://yarnpkg.com) or | ||
## Which version to use? | ||
There's no breaking changes between the `v2.x` version. The only breaking is | ||
`v2.1` which also is not working properly, so no use it. | ||
**Use v2.0.x** | ||
When you don't need support for `arrow functions` and `es6 default params`. This | ||
version uses a RegExp expression to work. | ||
**Use v2.2.x** | ||
Only when you need a _basic_ support for `es6 features` like arrow functions. | ||
This version uses a RegExp expression to work. | ||
**Use v2.3.x** | ||
When you want _full\*_ support for `arrow functions` and `es6 default params`. | ||
Where this "full", means "almost full", because it has bugs. This version also | ||
uses (`acorn.parse`) real parser to do the parsing. | ||
**Use v3.x** | ||
When you want to use different parser instead of the default `babylon.parse`, by | ||
passing custom parse function to the `options.parse` option. **From this version | ||
we require `node >= 4`**. | ||
**Use v4.x** | ||
When you want full customization and most stable support for old and modern | ||
features. This version uses `babylon.parseExpression` for parsing and provides a | ||
[Plugins API](#plugins-architecture). See the [Features](#features) section for | ||
more info. | ||
**Use v5.x** | ||
It is basically the same as `v4`, but requires Node 6 & npm 5. Another is | ||
boilerplate stuff. | ||
**[back to top](#readme)** | ||
## Notes | ||
### Throws in one specific case | ||
> _see: [issue #3](https://github.com/tunnckoCore/parse-function/issues/3) and | ||
> [test/index.js#L229-L235](https://github.com/tunnckoCore/parse-function/blob/master/test/index.js#L229-L235)_ | ||
It may throw in one specific case, otherwise it won't throw, so you should relay | ||
on the `result.isValid` for sure. | ||
### Function named _"anonymous"_ | ||
> _see: | ||
> [test/index.js#L319-L324](https://github.com/tunnckoCore/parse-function/blob/master/test/index.js#L319-L324) | ||
> and [Result](#result) section_ | ||
If you pass a function which is named _"anonymous"_ the `result.name` will be | ||
`'anonymous'`, but the `result.isAnonymous` will be `false` and `result.isNamed` | ||
will be `true`, because in fact it's a named function. | ||
### Real anonymous function | ||
> _see: | ||
> [test/index.js#L326-L331](https://github.com/tunnckoCore/parse-function/blob/master/test/index.js#L326-L331) | ||
> and [Result](#result) section_ | ||
Only if you pass really an anonymous function you will get `result.name` equal | ||
to `null`, `result.isAnonymous` equal to `true` and `result.isNamed` equal to | ||
`false`. | ||
**[back to top](#readme)** | ||
### Plugins Architecture | ||
> _see: the [.use](#use) method, | ||
> [test/index.js#L305-L317](https://github.com/tunnckoCore/parse-function/blob/master/test/index.js#L305-L317) | ||
> and | ||
> [test/index.js#L396-L414](https://github.com/tunnckoCore/parse-function/blob/master/test/index.js#L396-L414)_ | ||
A more human description of the plugin mechanism. Plugins are **synchronous** - | ||
no support and no need for **async** plugins here, but notice that you can do | ||
that manually, because that exact architecture. | ||
The first function that is passed to the [.use](#use) method is used for | ||
extending the core API, for example adding a new method to the `app` instance. | ||
That function is immediately invoked. | ||
```js | ||
const parseFunction = require('parse-function'); | ||
const app = parseFunction(); | ||
app.use((self) => { | ||
// self is same as `app` | ||
console.log(self.use); | ||
console.log(self.parse); | ||
console.log(self.define); | ||
self.define(self, 'foo', (bar) => bar + 1); | ||
}); | ||
console.log(app.foo(2)); // => 3 | ||
``` | ||
On the other side, if you want to access the AST of the parser, you should | ||
return a function from that plugin, which function is passed with | ||
`(node, result)` signature. | ||
This function is lazy plugin, it is called only when the [.parse](#parse) method | ||
is called. | ||
```js | ||
const parseFunction = require('parse-function'); | ||
const app = parseFunction(); | ||
app.use((self) => { | ||
console.log('immediately called'); | ||
return (node, result) => { | ||
console.log('called only when .parse is invoked'); | ||
console.log(node); | ||
console.log(result); | ||
}; | ||
}); | ||
``` | ||
Where **1)** the `node` argument is an object - actual and real AST Node coming | ||
from the parser and **2)** the `result` is an object too - the end | ||
[Result](#result), on which you can add more properties if you want. | ||
**[back to top](#readme)** | ||
## API | ||
<!-- docks-start --> | ||
@@ -404,5 +544,6 @@ | ||
Copyright (c) 2016-present, [Charlike Mike Reagent](https://tunnckocore.com) | ||
`<opensource@tunnckocore.com>` & [contributors](#wonderful-contributors).<br> | ||
Released under the [MPL-2.0 License][license-url]. | ||
Copyright (c) 2016-present, | ||
[Charlike Mike Reagent](https://tunnckocore.com) `<opensource@tunnckocore.com>` | ||
& [contributors](#wonderful-contributors).<br> Released under the | ||
[MPL-2.0 License][license-url]. | ||
@@ -510,2 +651,2 @@ <!-- badges --> | ||
[koa]: https://github.com/koajs/koa | ||
[tiny-glob]: https://github.com/terkelg/tiny-glob | ||
[tiny-glob]: https://github.com/terkelg/tiny-glob |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
61172
647