Skip to content
This repository was archived by the owner on Feb 8, 2020. It is now read-only.

Commit ce2e969

Browse files
author
Charlike Mike Reagent
committed
fix(misc): obviously manual publishing...
previous commit seems to not published TAG: latest fixes #118 and fixes #119
1 parent e5c0dd1 commit ce2e969

File tree

6 files changed

+205
-44
lines changed

6 files changed

+205
-44
lines changed

.helarc.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
"build": [
55
"hela clean",
66
"hela build:node"
7-
],
8-
"release": [
9-
"hela style",
10-
"hela build",
11-
"rm -rf ./dist/test.js",
12-
"npx -p node@8 new-release"
137
]
148
}
159
}

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ script: yarn test
2626

2727
after_success:
2828
- bash <(curl -s https://codecov.io/bash)
29-
- yarn hela release
3029

3130
branches:
3231
except:

.verb.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
## Quality Assurance :100:
1414

15-
[![Code Climate][codeclimate-img]][codeclimate-url]
1615
[![Code Style Standard][standard-img]][standard-url]
1716
[![Linux Build][travis-img]][travis-url]
1817
[![Code Coverage][codecov-img]][codecov-url]
@@ -228,7 +227,7 @@ Project scaffolded and managed with [hela][].
228227
[github-release-img]: https://img.shields.io/github/release/{%= repository %}.svg
229228

230229
[license-url]: https://github.com/{%= repository %}/blob/master/LICENSE
231-
[license-img]: https://img.shields.io/npm/l/{%= name %}.svg
230+
[license-img]: https://img.shields.io/npm/l/{%= name %}.svg?colorB=blue
232231

233232
[downloads-weekly-url]: https://www.npmjs.com/package/{%= name %}
234233
[downloads-weekly-img]: https://img.shields.io/npm/dw/{%= name %}.svg
@@ -263,13 +262,13 @@ Project scaffolded and managed with [hela][].
263262
[prettier-url]: https://github.com/prettier/prettier
264263
[prettier-img]: https://img.shields.io/badge/styled_with-prettier-f952a5.svg
265264

266-
[nodesecurity-url]: https://nodesecurity.io/orgs/tunnckocore-dev/projects/{%= nspId %}
267-
[nodesecurity-img]: https://nodesecurity.io/orgs/tunnckocore-dev/projects/{%= nspId %}/badge
265+
[nodesecurity-url]: https://nodesecurity.io/orgs/tunnckocore/projects/{%= nspId %}
266+
[nodesecurity-img]: https://nodesecurity.io/orgs/tunnckocore/projects/{%= nspId %}/badge
268267
<!-- the original color of nsp:
269268
[nodesec-img]: https://img.shields.io/badge/nsp-no_known_vulns-35a9e0.svg -->
270269

271-
[semantic-release-url]: https://github.com/semantic-release/semantic-release
272-
[semantic-release-img]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
270+
[semantic-release-url]: https://github.com/apps/new-release
271+
[semantic-release-img]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-new--release-e10079.svg
273272

274273
[ccommits-url]: https://conventionalcommits.org/
275274
[ccommits-img]: https://img.shields.io/badge/conventional_commits-1.0.0-yellow.svg

README.md

Lines changed: 171 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ You might also be interested in [hela](https://github.com/tunnckoCore/hela#readm
1212

1313
## Quality Assurance :100:
1414

15-
[![Code Climate][codeclimate-img]][codeclimate-url]
1615
[![Code Style Standard][standard-img]][standard-url]
1716
[![Linux Build][travis-img]][travis-url]
1817
[![Code Coverage][codecov-img]][codecov-url]
@@ -50,6 +49,10 @@ You may also read the [Contributing Guide](./CONTRIBUTING.md). There, beside _"H
5049
* [Real anonymous function](#real-anonymous-function)
5150
* [Plugins Architecture](#plugins-architecture)
5251
- [API](#api)
52+
* [parseFunction](#parsefunction)
53+
* [.parse](#parse)
54+
* [.use](#use)
55+
* [.define](#define)
5356
* [Result](#result)
5457
- [Related](#related)
5558
- [Contributing](#contributing)
@@ -186,6 +189,168 @@ you can add more properties if you want.
186189
## API
187190
Review carefully the provided examples and the working [tests](./test/index.js).
188191

192+
### [parseFunction](src/index.js#L60)
193+
> Initializes with optional `opts` object which is passed directly to the desired parser and returns an object with `.use` and `.parse` methods. The default parse which is used is [babylon][]'s `.parseExpression` method from `v7`.
194+
195+
**Params**
196+
197+
* `opts` **{Object}**: optional, merged with options passed to `.parse` method
198+
* `returns` **{Object}** `app`: object with `.use` and `.parse` methods
199+
200+
**Example**
201+
202+
```js
203+
const parseFunction = require('parse-function')
204+
205+
const app = parseFunction({
206+
ecmaVersion: 2017
207+
})
208+
209+
const fixtureFn = (a, b, c) => {
210+
a = b + c
211+
return a + 2
212+
}
213+
214+
const result = app.parse(fixtureFn)
215+
console.log(result)
216+
217+
// see more
218+
console.log(result.name) // => null
219+
console.log(result.isNamed) // => false
220+
console.log(result.isArrow) // => true
221+
console.log(result.isAnonymous) // => true
222+
223+
// array of names of the arguments
224+
console.log(result.args) // => ['a', 'b', 'c']
225+
226+
// comma-separated names of the arguments
227+
console.log(result.params) // => 'a, b, c'
228+
```
229+
230+
### [.parse](src/index.js#L101)
231+
> Parse a given `code` and returns a `result` object with useful properties - such as `name`, `body` and `args`. By default it uses Babylon parser, but you can switch it by passing `options.parse` - for example `options.parse: acorn.parse`. In the below example will show how to use `acorn` parser, instead of the default one.
232+
233+
**Params**
234+
235+
* `code` **{Function|String}**: any kind of function or string to be parsed
236+
* `options` **{Object}**: directly passed to the parser - babylon, acorn, espree
237+
* `options.parse` **{Function}**: by default `babylon.parseExpression`, all `options` are passed as second argument to that provided function
238+
* `returns` **{Object}** `result`: see [result section](#result) for more info
239+
240+
**Example**
241+
242+
```js
243+
const acorn = require('acorn')
244+
const parseFn = require('parse-function')
245+
const app = parseFn()
246+
247+
const fn = function foo (bar, baz) { return bar * baz }
248+
const result = app.parse(fn, {
249+
parse: acorn.parse,
250+
ecmaVersion: 2017
251+
})
252+
253+
console.log(result.name) // => 'foo'
254+
console.log(result.args) // => ['bar', 'baz']
255+
console.log(result.body) // => ' return bar * baz '
256+
console.log(result.isNamed) // => true
257+
console.log(result.isArrow) // => false
258+
console.log(result.isAnonymous) // => false
259+
console.log(result.isGenerator) // => false
260+
```
261+
262+
### [.use](src/index.js#L173)
263+
> Add a plugin `fn` function for extending the API or working on the AST nodes. The `fn` is immediately invoked and passed with `app` argument which is instance of `parseFunction()` call. That `fn` may return another function that accepts `(node, result)` signature, where `node` is an AST node and `result` is an object which will be returned [result](#result) from the `.parse` method. This retuned function is called on each node only when `.parse` method is called.
264+
265+
_See [Plugins Architecture](#plugins-architecture) section._
266+
267+
**Params**
268+
269+
* `fn` **{Function}**: plugin to be called
270+
* `returns` **{Object}** `app`: instance for chaining
271+
272+
**Example**
273+
274+
```js
275+
// plugin extending the `app`
276+
app.use((app) => {
277+
app.define(app, 'hello', (place) => `Hello ${place}!`)
278+
})
279+
280+
const hi = app.hello('World')
281+
console.log(hi) // => 'Hello World!'
282+
283+
// or plugin that works on AST nodes
284+
app.use((app) => (node, result) => {
285+
if (node.type === 'ArrowFunctionExpression') {
286+
result.thatIsArrow = true
287+
}
288+
return result
289+
})
290+
291+
const result = app.parse((a, b) => (a + b + 123))
292+
console.log(result.name) // => null
293+
console.log(result.isArrow) // => true
294+
console.log(result.thatIsArrow) // => true
295+
296+
const result = app.parse(function foo () { return 123 })
297+
console.log(result.name) // => 'foo'
298+
console.log(result.isArrow) // => false
299+
console.log(result.thatIsArrow) // => undefined
300+
```
301+
302+
### [.define](src/index.js#L234)
303+
> Define a non-enumerable property on an object. Just a convenience mirror of the [define-property][] library, so check out its docs. Useful to be used in plugins.
304+
305+
**Params**
306+
307+
* `obj` **{Object}**: the object on which to define the property
308+
* `prop` **{String}**: the name of the property to be defined or modified
309+
* `val` **{Any}**: the descriptor for the property being defined or modified
310+
* `returns` **{Object}** `obj`: the passed object, but modified
311+
312+
**Example**
313+
314+
```js
315+
const parseFunction = require('parse-function')
316+
const app = parseFunction()
317+
318+
// use it like `define-property` lib
319+
const obj = {}
320+
app.define(obj, 'hi', 'world')
321+
console.log(obj) // => { hi: 'world' }
322+
323+
// or define a custom plugin that adds `.foo` property
324+
// to the end result, returned from `app.parse`
325+
app.use((app) => {
326+
return (node, result) => {
327+
// this function is called
328+
// only when `.parse` is called
329+
330+
app.define(result, 'foo', 123)
331+
332+
return result
333+
}
334+
})
335+
336+
// fixture function to be parsed
337+
const asyncFn = async (qux) => {
338+
const bar = await Promise.resolve(qux)
339+
return bar
340+
}
341+
342+
const result = app.parse(asyncFn)
343+
344+
console.log(result.name) // => null
345+
console.log(result.foo) // => 123
346+
console.log(result.args) // => ['qux']
347+
348+
console.log(result.isAsync) // => true
349+
console.log(result.isArrow) // => true
350+
console.log(result.isNamed) // => false
351+
console.log(result.isAnonymous) // => true
352+
```
353+
189354
**[back to top](#thetop)**
190355

191356
### Result
@@ -249,7 +414,7 @@ Project scaffolded and managed with [hela][].
249414
[github-release-img]: https://img.shields.io/github/release/tunnckoCore/parse-function.svg
250415

251416
[license-url]: https://github.com/tunnckoCore/parse-function/blob/master/LICENSE
252-
[license-img]: https://img.shields.io/npm/l/parse-function.svg
417+
[license-img]: https://img.shields.io/npm/l/parse-function.svg?colorB=blue
253418

254419
[downloads-weekly-url]: https://www.npmjs.com/package/parse-function
255420
[downloads-weekly-img]: https://img.shields.io/npm/dw/parse-function.svg
@@ -284,13 +449,13 @@ Project scaffolded and managed with [hela][].
284449
[prettier-url]: https://github.com/prettier/prettier
285450
[prettier-img]: https://img.shields.io/badge/styled_with-prettier-f952a5.svg
286451

287-
[nodesecurity-url]: https://nodesecurity.io/orgs/tunnckocore-dev/projects/5d75a388-acfe-4668-ad18-e98564e387e1
288-
[nodesecurity-img]: https://nodesecurity.io/orgs/tunnckocore-dev/projects/5d75a388-acfe-4668-ad18-e98564e387e1/badge
452+
[nodesecurity-url]: https://nodesecurity.io/orgs/tunnckocore/projects/42a5e14a-70da-49ee-86e7-d1f39ed08603
453+
[nodesecurity-img]: https://nodesecurity.io/orgs/tunnckocore/projects/42a5e14a-70da-49ee-86e7-d1f39ed08603/badge
289454
<!-- the original color of nsp:
290455
[nodesec-img]: https://img.shields.io/badge/nsp-no_known_vulns-35a9e0.svg -->
291456

292-
[semantic-release-url]: https://github.com/semantic-release/semantic-release
293-
[semantic-release-img]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
457+
[semantic-release-url]: https://github.com/apps/new-release
458+
[semantic-release-img]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-new--release-e10079.svg
294459

295460
[ccommits-url]: https://conventionalcommits.org/
296461
[ccommits-img]: https://img.shields.io/badge/conventional_commits-1.0.0-yellow.svg

package.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "parse-function",
3-
"version": "5.1.2",
3+
"version": "5.1.4",
44
"description": "Parse a function into an object using espree, acorn or babylon parsers. Extensible through Smart Plugins",
55
"repository": "tunnckoCore/parse-function",
66
"homepage": "https://github.com/tunnckoCore/parse-function",
77
"author": "Charlike Mike Reagent <@tunnckoCore> (https://i.am.charlike.online)",
8-
"nspId": "5d75a388-acfe-4668-ad18-e98564e387e1",
8+
"nspId": "42a5e14a-70da-49ee-86e7-d1f39ed08603",
99
"src": "./src/**/*.js",
1010
"main": "./dist/index.js",
1111
"module": "./dist/index.es.js",
@@ -39,8 +39,7 @@
3939
"hela": "1.1.3",
4040
"hela-preset-tunnckocore": "0.5.19",
4141
"husky": "0.14.3",
42-
"mukla": "0.4.9",
43-
"new-release": "4.0.1"
42+
"mukla": "0.4.9"
4443
},
4544
"keywords": [
4645
"args",
@@ -106,8 +105,5 @@
106105
"acorn",
107106
"espree"
108107
]
109-
},
110-
"release": {
111-
"analyzeCommits": "simple-commit-message"
112108
}
113109
}

0 commit comments

Comments
 (0)