|
| 1 | + |
| 2 | +<a href="https://www.typescriptlang.org/"> |
| 3 | + <img |
| 4 | + src="https://raw.githubusercontent.com/typescript-package/core/refs/heads/main/ts-package-barcode-logo-512.png" |
| 5 | + width="20%" |
| 6 | + title="@typescript-package/middleware - A lightweight TypeScript library for middleware." |
| 7 | + /> |
| 8 | +</a> |
| 9 | + |
| 10 | +## @typescript-package/middleware |
| 11 | + |
| 12 | +<!-- npm badge --> |
| 13 | +[![npm version][typescript-package-npm-badge-svg]][typescript-package-npm-badge] |
| 14 | +[![GitHub issues][typescript-package-badge-issues]][typescript-package-issues] |
| 15 | +[![GitHub license][typescript-package-badge-license]][typescript-package-license] |
| 16 | + |
| 17 | +A **lightweight** TypeScript library for middleware. |
| 18 | + |
| 19 | +## Features |
| 20 | + |
| 21 | +## Table of contents |
| 22 | + |
| 23 | +- [Installation](#installation) |
| 24 | +- [Api](#api) |
| 25 | + - Class |
| 26 | + - [`Middleware`](#middleware) |
| 27 | +- [Contributing](#contributing) |
| 28 | +- [Support](#support) |
| 29 | +- [Code of Conduct](code-of-conduct) |
| 30 | +- [Git](#git) |
| 31 | + - [Commit](#commit) |
| 32 | + - [Versioning](#versioning) |
| 33 | +- [License](#license) |
| 34 | +- [Related packages](#related-packages) |
| 35 | + |
| 36 | +## Installation |
| 37 | + |
| 38 | +### 1. Install the package |
| 39 | + |
| 40 | +```bash |
| 41 | +npm install @typescript-package/middleware --save-peer |
| 42 | +``` |
| 43 | + |
| 44 | +## Api |
| 45 | + |
| 46 | +### `Middleware` |
| 47 | + |
| 48 | +```typescript |
| 49 | +import { Middleware } from '@typescript-package/middleware'; |
| 50 | + |
| 51 | +// Initialize. |
| 52 | +const middleware = new Middleware(); |
| 53 | + |
| 54 | +// Add middleware. |
| 55 | +middleware.use((args, next) => { |
| 56 | + console.log('Middleware 1 executed with args:', args); |
| 57 | + |
| 58 | + // Modify args. |
| 59 | + args[0].newKey = 'newValue'; |
| 60 | + |
| 61 | + // Execute next. |
| 62 | + next(); |
| 63 | +}); |
| 64 | + |
| 65 | +middleware.use((args, next) => { |
| 66 | + console.log('Middleware 2 executed with args:', args); |
| 67 | + |
| 68 | + // Execute next. |
| 69 | + next(); |
| 70 | +}); |
| 71 | + |
| 72 | +// logs |
| 73 | +// Middleware 1 executed with args: [ { key: 'value' } ] |
| 74 | +// Middleware 2 executed with args: [ { key: 'value', newKey: 'newValue' } ] |
| 75 | +middleware.execute({ key: 'value' }); |
| 76 | + |
| 77 | + |
| 78 | +// Async |
| 79 | +middleware.use(async (args, next) => { |
| 80 | + console.log('Async middleware 1 start with args:', args); |
| 81 | + args[0].newKey = 'newValue'; |
| 82 | + await new Promise(resolve => setTimeout(resolve, 2000)); |
| 83 | + console.log('Async middleware end'); |
| 84 | + next(); |
| 85 | +}); |
| 86 | + |
| 87 | +middleware.use(async (args, next) => { |
| 88 | + console.log('Async middleware 2 start with args:', args); |
| 89 | + next(); |
| 90 | +}); |
| 91 | + |
| 92 | +middleware.onComplete((args) => { |
| 93 | + console.log('All middlewares completed with args:', args); |
| 94 | +}); |
| 95 | + |
| 96 | +middleware.executeAsync({ key: 'value' }); |
| 97 | +``` |
| 98 | + |
| 99 | +## Contributing |
| 100 | + |
| 101 | +Your contributions are valued! If you'd like to contribute, please feel free to submit a pull request. Help is always appreciated. |
| 102 | + |
| 103 | +## Support |
| 104 | + |
| 105 | +If you find this package useful and would like to support its and general development, you can contribute through one of the following payment methods. Your support helps maintain the packages and continue adding new. |
| 106 | + |
| 107 | +Support via: |
| 108 | + |
| 109 | +- [Stripe](https://donate.stripe.com/dR614hfDZcJE3wAcMM) |
| 110 | +- [Revolut](https://checkout.revolut.com/pay/048b10a3-0e10-42c8-a917-e3e9cb4c8e29) |
| 111 | +- [GitHub](https://github.com/sponsors/angular-package/sponsorships?sponsor=sciborrudnicki&tier_id=83618) |
| 112 | +- [DonorBox](https://donorbox.org/become-a-sponsor-to-the-angular-package?default_interval=o) |
| 113 | +- [Patreon](https://www.patreon.com/checkout/angularpackage?rid=0&fan_landing=true&view_as=public) |
| 114 | + |
| 115 | +or via Trust Wallet |
| 116 | + |
| 117 | +- [XLM](https://link.trustwallet.com/send?coin=148&address=GAFFFB7H3LG42O6JA63FJDRK4PP4JCNEOPHLGLLFH625X2KFYQ4UYVM4) |
| 118 | +- [USDT (BEP20)](https://link.trustwallet.com/send?coin=20000714&address=0xA0c22A2bc7E37C1d5992dFDFFeD5E6f9298E1b94&token_id=0x55d398326f99059fF775485246999027B3197955) |
| 119 | +- [ETH](https://link.trustwallet.com/send?coin=60&address=0xA0c22A2bc7E37C1d5992dFDFFeD5E6f9298E1b94) |
| 120 | +- [BTC](https://link.trustwallet.com/send?coin=0&address=bc1qnf709336tfl57ta5mfkf4t9fndhx7agxvv9svn) |
| 121 | +- [BNB](https://link.trustwallet.com/send?coin=20000714&address=0xA0c22A2bc7E37C1d5992dFDFFeD5E6f9298E1b94) |
| 122 | + |
| 123 | +## Code of Conduct |
| 124 | + |
| 125 | +By participating in this project, you agree to follow **[Code of Conduct](https://www.contributor-covenant.org/version/2/1/code_of_conduct/)**. |
| 126 | + |
| 127 | +## GIT |
| 128 | + |
| 129 | +### Commit |
| 130 | + |
| 131 | +Please follow the following commit message conventions: |
| 132 | + |
| 133 | +- [AngularJS Git Commit Message Conventions][git-commit-angular] |
| 134 | +- [Karma Git Commit Msg][git-commit-karma] |
| 135 | +- [Conventional Commits][git-commit-conventional] |
| 136 | + |
| 137 | +### Versioning |
| 138 | + |
| 139 | +The package follows [Semantic Versioning 2.0.0][git-semver] for all releases. The versioning format is: |
| 140 | + |
| 141 | +**Given a version number MAJOR.MINOR.PATCH, increment the:** |
| 142 | + |
| 143 | +- MAJOR version when you make incompatible API changes, |
| 144 | +- MINOR version when you add functionality in a backwards-compatible manner, and |
| 145 | +- PATCH version when you make backwards-compatible bug fixes. |
| 146 | + |
| 147 | +Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format. |
| 148 | + |
| 149 | +**FAQ** |
| 150 | +How should I deal with revisions in the 0.y.z initial development phase? |
| 151 | + |
| 152 | +> The simplest thing to do is start your initial development release at 0.1.0 and then increment the minor version for each subsequent release. |
| 153 | +
|
| 154 | +How do I know when to release 1.0.0? |
| 155 | + |
| 156 | +> If your software is being used in production, it should probably already be 1.0.0. If you have a stable API on which users have come to depend, you should be 1.0.0. If you’re worrying a lot about backwards compatibility, you should probably already be 1.0.0. |
| 157 | +
|
| 158 | +## License |
| 159 | + |
| 160 | +MIT © typescript-package ([license][typescript-package-license]) |
| 161 | + |
| 162 | +## Related packages |
| 163 | + |
| 164 | +- **[@typescript-package/chain-descriptor](https://github.com/typescript-package/chain-descriptor)**: A **TypeScript** library for chain property descriptor. |
| 165 | +- **[@typescript-package/controller](https://github.com/typescript-package/controller)**: A **TypeScript** package with for various kind of controllers. |
| 166 | +- **[@typescript-package/descriptor](https://github.com/typescript-package/descriptor)**: A **TypeScript** library for property descriptor. |
| 167 | +- **[@typescript-package/descriptor-chain](https://github.com/typescript-package/descriptor-chain)**: A **TypeScript** library for property descriptor chain. |
| 168 | +- **[@typescript-package/descriptors](https://github.com/typescript-package/descriptors)**: A **TypeScript** library for property descriptors. |
| 169 | +- **[@typescript-package/property](https://github.com/typescript-package/property)**: A **TypeScript** package with features to handle object properties. |
| 170 | +- **[@typescript-package/wrap-descriptor](https://github.com/typescript-package/wrap-descriptor)**: A **TypeScript** package for wrapping object descriptors. |
| 171 | +- **[@typescript-package/wrap-property](https://github.com/typescript-package/wrap-property)**: A **TypeScript** package for wrapping object properties. |
| 172 | +- **[@typescript-package/wrapped-descriptor](https://github.com/typescript-package/wrapped-descriptor)**: A **TypeScript** library for wrapped property descriptor. |
| 173 | +- **[@xtypescript/property](https://github.com/xtypescript/property)** - A comprehensive, reactive **TypeScript** library for precise and extensible object property control. |
| 174 | + |
| 175 | +<!-- This package: typescript-package --> |
| 176 | + <!-- GitHub: badges --> |
| 177 | + [typescript-package-badge-issues]: https://img.shields.io/github/issues/typescript-package/middleware |
| 178 | + [isscript-package-badge-forks]: https://img.shields.io/github/forks/typescript-package/middleware |
| 179 | + [typescript-package-badge-stars]: https://img.shields.io/github/stars/typescript-package/middleware |
| 180 | + [typescript-package-badge-license]: https://img.shields.io/github/license/typescript-package/middleware |
| 181 | + <!-- GitHub: badges links --> |
| 182 | + [typescript-package-issues]: https://github.com/typescript-package/middleware/issues |
| 183 | + [typescript-package-forks]: https://github.com/typescript-package/middleware/network |
| 184 | + [typescript-package-license]: https://github.com/typescript-package/middleware/blob/master/LICENSE |
| 185 | + [typescript-package-stars]: https://github.com/typescript-package/middleware/stargazers |
| 186 | +<!-- This package --> |
| 187 | + |
| 188 | +<!-- Package: typescript-package --> |
| 189 | + <!-- npm --> |
| 190 | + [typescript-package-npm-badge-svg]: https://badge.fury.io/js/@typescript-package%2Fmiddleware.svg |
| 191 | + [typescript-package-npm-badge]: https://badge.fury.io/js/@typescript-package%2Fmiddleware |
| 192 | + |
| 193 | +<!-- GIT --> |
| 194 | +[git-semver]: http://semver.org/ |
| 195 | + |
| 196 | +<!-- GIT: commit --> |
| 197 | +[git-commit-angular]: https://gist.github.com/stephenparish/9941e89d80e2bc58a153 |
| 198 | +[git-commit-karma]: http://karma-runner.github.io/0.10/dev/git-commit-msg.html |
| 199 | +[git-commit-conventional]: https://www.conventionalcommits.org/en/v1.0.0/ |
0 commit comments