Skip to content
This repository has been archived by the owner on Nov 18, 2023. It is now read-only.

Commit

Permalink
docs: format markdown files
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Sep 21, 2020
1 parent aee898b commit a99f47b
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 59 deletions.
10 changes: 7 additions & 3 deletions .github/COMMIT_CONVENTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
Using conventional commit messages, we can automate the process of generating the CHANGELOG file. All commits messages will automatically be validated against the following regex.

``` js
/^(revert: )?(feat|fix|docs|style|refactor|perf|test|workflow|ci|chore|types|build|improvement)((.+))?: .{1,50}/
```js
;/^(revert: )?(feat|fix|docs|style|refactor|perf|test|workflow|ci|chore|types|build|improvement)((.+))?: .{1,50}/
```
## Commit Message Format
A commit message consists of a **header**, **body** and **footer**. The header has a **type**, **scope** and **subject**:
> The **scope** is optional
Expand All @@ -26,6 +27,7 @@ Prefix makes it easier to append a path to a group of routes
5. The optional **footer** can be added after the body, followed by a blank line.

## Types

Only one type can be used at a time and only following types are allowed.

- feat
Expand All @@ -44,12 +46,15 @@ Only one type can be used at a time and only following types are allowed.
If a type is `feat`, `fix` or `perf`, then the commit will appear in the CHANGELOG.md file. However if there is any BREAKING CHANGE, the commit will always appear in the changelog.

### Revert

If the commit reverts a previous commit, it should begin with `revert:`, followed by the header of the reverted commit. In the body it should say: `This reverts commit <hash>`., where the hash is the SHA of the commit being reverted.

## Scope

The scope could be anything specifying place of the commit change. For example: `router`, `view`, `querybuilder`, `database`, `model` and so on.

## Subject

The subject contains succinct description of the change:

- use the imperative, present tense: "change" not "changed" nor "changes".
Expand All @@ -67,4 +72,3 @@ The footer should contain any information about **Breaking Changes** and is also
reference GitHub issues that this commit **Closes**.

**Breaking Changes** should start with the word `BREAKING CHANGE:` with a space or two newlines. The rest of the commit message is then used for this.

5 changes: 3 additions & 2 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ We do our best to reply to all the issues on time. If you will follow the given
- Ensure the issue isn't already reported.
- Ensure you are reporting the bug in the correct repo.

*Delete the above section and the instructions in the sections below before submitting*
_Delete the above section and the instructions in the sections below before submitting_

## Description

If this is a feature request, explain why it should be added. Specific use-cases are best.

For bug reports, please provide as much *relevant* info as possible.
For bug reports, please provide as much _relevant_ info as possible.

## Package version

<!-- YOUR ANSWER -->

## Error Message & Stack Trace
Expand Down
2 changes: 0 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
build
README.md
docs
*.md
config.json
.eslintrc.json
package.json
Expand Down
10 changes: 9 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,13 @@
"quoteProps": "consistent",
"bracketSpacing": true,
"arrowParens": "always",
"printWidth": 100
"printWidth": 100,
"overrides": [
{
"files": "*.md",
"options": {
"useTabs": false
}
}
]
}
99 changes: 49 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
</div>

# Co Compose

> Compose an array of functions to be executed one after the other. Similar to Koa and AdonisJS middlewares.
[![circleci-image]][circleci-url] [![typescript-image]][typescript-url] [![npm-image]][npm-url] [![license-image]][license-url] [![audit-report-image]][audit-report-url]
Expand All @@ -12,9 +13,9 @@ Co compose composes an array of middleware to be executed in sequence. The libra
<details>
<summary> <strong>Benchmarks</strong> </summary>

Co Compose x 488,078 ops/sec ±0.32% (82 runs sampled)
fastseries x 94,426 ops/sec ±6.53% (47 runs sampled)
middie x 80,062 ops/sec ±8.71% (47 runs sampled)
Co Compose x 488,078 ops/sec ±0.32% (82 runs sampled)
fastseries x 94,426 ops/sec ±6.53% (47 runs sampled)
middie x 80,062 ops/sec ±8.71% (47 runs sampled)

<p> <strong> Fastest is Co Compose </strong> </p>
</details>
Expand All @@ -32,6 +33,7 @@ Co compose composes an array of middleware to be executed in sequence. The libra
<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Installation

```sh
npm i co-compose

Expand All @@ -40,18 +42,19 @@ yarn add co-compose
```

## Usage

Checkout the following example to run an array of middleware functions.

```ts
import { Middleware } from 'co-compose'
async function fn1 (next) {
console.log('executing fn1')
await next()
async function fn1(next) {
console.log('executing fn1')
await next()
}

async function fn2 (next) {
console.log('executing fn2')
await next()
async function fn2(next) {
console.log('executing fn2')
await next()
}

const middleware = new Middleware()
Expand All @@ -61,101 +64,97 @@ await middleware.runner().run([])
```

### Passing values

You can also pass values to all middleware functions. An `array` of values passed to `runner.run()` will be passed to middleware functions as multiple arguments.

```js
async function fn1 (ctx, next) {
ctx.stack.push('fn1')
await next()
async function fn1(ctx, next) {
ctx.stack.push('fn1')
await next()
}

async function fn2 (ctx, next) {
ctx.stack.push('fn2')
await next()
async function fn2(ctx, next) {
ctx.stack.push('fn2')
await next()
}

const ctx = {
stack: []
stack: [],
}

await middleware.runner().run([ctx])
assert.deepEqual(ctx.stack, ['fn1', 'fn2'])
```

### Custom executors

The default behavior is to define middleware as functions. However, you can define them in any shape and then stick a custom executor to execute them.

Check the following example where `ES6 classes` are used.

```js
class Middleware1 {
async handle (ctx, next) {
ctx.stack.push('fn1')
await next()
}
async handle(ctx, next) {
ctx.stack.push('fn1')
await next()
}
}

class Middleware2 {
async handle (ctx, next) {
ctx.stack.push('fn2')
await next()
}
async handle(ctx, next) {
ctx.stack.push('fn2')
await next()
}
}

const middleware = new Middleware()
const ctx = {
stack: []
stack: [],
}

middleware.register([Middleware1, Middleware2])

await middleware
.runner()
.executor(async function (MiddlewareClass, params) {
const instance = new MiddlewareClass() // 👈
await instance.handle(...params) // 👈
})
.run([ctx])
.runner()
.executor(async function (MiddlewareClass, params) {
const instance = new MiddlewareClass() // 👈
await instance.handle(...params) // 👈
})
.run([ctx])
```

### Final Handler

The final handler is a executed when the entire middleware chain ends by calling `next`. This makes it easier to execute custom functions, which are not part of the chain, however must be executed when chain ends.

> Also, the arguments for the final handler can be different from the middleware arguments
```js
async function fn1 (ctx, next) {
ctx.stack.push('fn1')
await next()
async function fn1(ctx, next) {
ctx.stack.push('fn1')
await next()
}

async function finalHandler () {
ctx.stack.push('final handler')
async function finalHandler() {
ctx.stack.push('final handler')
}

const ctx = {
stack: []
stack: [],
}

await middleware
.runner()
.finalHandler(finalHandler, [ctx])
.run([ctx])
await middleware.runner().finalHandler(finalHandler, [ctx]).run([ctx])

assert.deepEqual(ctx.stack, ['fn1', 'final handler'])
```

[circleci-image]: https://img.shields.io/circleci/project/github/poppinss/co-compose/master.svg?style=for-the-badge&logo=circleci
[circleci-url]: https://circleci.com/gh/poppinss/co-compose "circleci"

[circleci-url]: https://circleci.com/gh/poppinss/co-compose 'circleci'
[typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
[typescript-url]: "typescript"

[typescript-url]: "typescript"
[npm-image]: https://img.shields.io/npm/v/co-compose.svg?style=for-the-badge&logo=npm
[npm-url]: https://npmjs.org/package/co-compose "npm"

[npm-url]: https://npmjs.org/package/co-compose 'npm'
[license-image]: https://img.shields.io/npm/l/co-compose?color=blueviolet&style=for-the-badge
[license-url]: LICENSE.md "license"

[license-url]: LICENSE.md 'license'
[audit-report-image]: https://img.shields.io/badge/-Audit%20Report-blueviolet?style=for-the-badge
[audit-report-url]: https://htmlpreview.github.io/?https://github.com/poppinss/co-compose/blob/develop/npm-audit.html "audit-report"
[audit-report-url]: https://htmlpreview.github.io/?https://github.com/poppinss/co-compose/blob/develop/npm-audit.html 'audit-report'
2 changes: 1 addition & 1 deletion npm-audit.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h5 class="card-title">
<div class="card">
<div class="card-body">
<h5 class="card-title">
September 21st 2020, 6:06:30 am
September 21st 2020, 6:08:49 am
</h5>
<p class="card-text">Last updated</p>
</div>
Expand Down

0 comments on commit a99f47b

Please sign in to comment.