Website Structure

This commit is contained in:
supalerk-ar66 2026-01-13 10:46:40 +07:00
parent 62812f2090
commit 71f0676a62
22365 changed files with 4265753 additions and 791 deletions

22
Frontend-Learner/node_modules/koa-convert/LICENSE generated vendored Normal file
View file

@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2015 yunsong
Copyright (c) 2020 Koa.js contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

166
Frontend-Learner/node_modules/koa-convert/README.md generated vendored Normal file
View file

@ -0,0 +1,166 @@
# koa-convert
[![Build Status][travis-img]][travis-url]
[![NPM version][npm-badge]][npm-url]
[![License][license-badge]][license-url]
![Code Size][code-size-badge]
<!-- [![Coverage Status][coverage-img]][coverage-url] -->
<!-- ***************** -->
[travis-img]: https://travis-ci.org/koajs/convert.svg?branch=master
[travis-url]: https://travis-ci.org/koajs/convert
<!--
WAIT FOR ACCESS
[coverage-img]: https://coveralls.io/repos/github/koajs/convert/badge.svg?branch=master
[coverage-url]: https://coveralls.io/github/koajs/convert?branch=master
-->
[npm-badge]: https://img.shields.io/npm/v/koa-better-request-id.svg?style=flat
[npm-url]: https://www.npmjs.com/package/koa-better-request-id
[license-badge]: https://img.shields.io/badge/license-MIT-green.svg?style=flat-square
[license-url]: https://github.com/koajs/koa-convert/blob/master/LICENSE
[code-size-badge]: https://img.shields.io/github/languages/code-size/koajs/koa-convert
<!-- ***************** -->
Convert Koa legacy (0.x & 1.x) generator middleware to modern promise middleware (2.x).
It could also convert modern promise middleware back to legacy generator middleware (useful to help modern middleware support Koa v0.x or v1.x).
## Note
Router middleware is special case here. Because it reimplements middleware composition internally, we cannot not simply convert it.
You may use following packages for [routing](https://github.com/koajs/koa/wiki#routing-and-mounting), which are koa 2.x ready now:
* [koa-route@3.0.0](https://github.com/koajs/route/tree/next)
* [koa-simple-router](https://github.com/gyson/koa-simple-router)
* [koa-router@next](https://github.com/alexmingoia/koa-router/tree/master)
* [koa-66](https://github.com/menems/koa-66)
## Installation
```bash
# npm ..
$ npm i koa-convert
# yarn ..
$ yarn add koa-convert
```
## Usage
```js
const Koa = require('koa') // koa v2.x
const convert = require('koa-convert')
const app = new Koa()
app.use(modernMiddleware)
app.use(convert(legacyMiddleware))
app.use(convert.compose(legacyMiddleware, modernMiddleware))
function * legacyMiddleware (next) {
// before
yield next
// after
}
function modernMiddleware (ctx, next) {
// before
return next().then(() => {
// after
})
}
```
## Distinguish legacy and modern middleware
In koa 0.x and 1.x (without experimental flag), `app.use` has an assertion that all (legacy) middleware must be generator function and it's tested with `fn.constructor.name == 'GeneratorFunction'` at [here](https://github.com/koajs/koa/blob/7fe29d92f1e826d9ce36029e1b9263b94cba8a7c/lib/application.js#L105).
Therefore, we can distinguish legacy and modern middleware with `fn.constructor.name == 'GeneratorFunction'`.
## Migration
`app.use(legacyMiddleware)` is everywhere in 0.x and 1.x and it would be painful to manually change all of them to `app.use(convert(legacyMiddleware))`.
You can use following snippet to make migration easier.
```js
const _use = app.use
app.use = x => _use.call(app, convert(x))
```
The above snippet will override `app.use` method and implicitly convert all legacy generator middleware to modern promise middleware.
Therefore, you can have both `app.use(modernMiddleware)` and `app.use(legacyMiddleware)` and your 0.x or 1.x should work without modification.
Complete example:
```js
const Koa = require('koa') // v2.x
const convert = require('koa-convert')
const app = new Koa()
// ---------- override app.use method ----------
const _use = app.use
app.use = x => _use.call(app, convert(x))
// ---------- end ----------
app.use(modernMiddleware)
// this will be converted to modern promise middleware implicitly
app.use(legacyMiddleware)
function * legacyMiddleware (next) {
// before
yield next
// after
}
function modernMiddleware (ctx, next) {
// before
return next().then(() => {
// after
})
}
```
## API
#### `convert()`
Convert legacy generator middleware to modern promise middleware.
```js
modernMiddleware = convert(legacyMiddleware)
```
#### `convert.compose()`
Convert and compose multiple middleware (could mix legacy and modern ones) and return modern promise middleware.
```js
composedModernMiddleware = convert.compose(legacyMiddleware, modernMiddleware)
// or
composedModernMiddleware = convert.compose([legacyMiddleware, modernMiddleware])
```
#### `convert.back()`
Convert modern promise middleware back to legacy generator middleware.
This is useful to help modern promise middleware support koa 0.x or 1.x.
```js
legacyMiddleware = convert.back(modernMiddleware)
```
## License
[MIT](LICENSE)

105
Frontend-Learner/node_modules/koa-convert/index.js generated vendored Normal file
View file

@ -0,0 +1,105 @@
'use strict'
/**
* Module dependencies.
*/
const co = require('co')
const compose = require('koa-compose')
/**
* Expose `convert()`.
*/
module.exports = convert
/**
* Convert Koa legacy generator-based middleware
* to modern promise-based middleware.
*
*
* @api public
* */
function convert (mw) {
if (typeof mw !== 'function') {
throw new TypeError('middleware must be a function')
}
// assume it's Promise-based middleware
if (
mw.constructor.name !== 'GeneratorFunction' &&
mw.constructor.name !== 'AsyncGeneratorFunction'
) {
return mw
}
const converted = function (ctx, next) {
return co.call(
ctx,
mw.call(
ctx,
(function * (next) { return yield next() })(next)
))
}
converted._name = mw._name || mw.name
return converted
}
/**
* Convert and compose multiple middleware
* (could mix legacy and modern ones)
* and return modern promise middleware.
*
*
* @api public
* */
// convert.compose(mw, mw, mw)
// convert.compose([mw, mw, mw])
convert.compose = function (arr) {
if (!Array.isArray(arr)) {
arr = Array.from(arguments)
}
return compose(arr.map(convert))
}
/**
* Convert Koa modern promise-based middleware
* to legacy generator-based middleware.
*
*
* @api public
* */
convert.back = function (mw) {
if (typeof mw !== 'function') {
throw new TypeError('middleware must be a function')
}
// assume it's generator middleware
if (mw.constructor.name === 'GeneratorFunction' || mw.constructor.name === 'AsyncGeneratorFunction') {
return mw
}
const converted = function * (next) {
const ctx = this
let called = false
yield mw(ctx, function () {
if (called) {
// guard against multiple next() calls
// https://github.com/koajs/compose/blob/4e3e96baf58b817d71bd44a8c0d78bb42623aa95/index.js#L36
throw new Error('next() called multiple times')
}
called = true
return co.call(ctx, next)
})
}
converted._name = mw._name || mw.name
return converted
}

64
Frontend-Learner/node_modules/koa-convert/package.json generated vendored Normal file
View file

@ -0,0 +1,64 @@
{
"name": "koa-convert",
"version": "2.0.0",
"description": "convert modern Koa legacy generator-based middleware to promise-based middleware",
"main": "index.js",
"files": [
"index.js"
],
"repository": {
"type": "git",
"url": "git+https://github.com/gyson/koa-convert.git"
},
"standard": {
"ignore": [
"index.spec.js"
]
},
"scripts": {
"lint": "standard",
"pretest": "npm run lint",
"test": "mocha index.spec.js --exit",
"precoverage": "rimraf .nyc_output coverage",
"coverage": "nyc npm run test",
"ci": "npm run coverage"
},
"keywords": [
"koa",
"middleware",
"convert",
"back",
"generator",
"promise",
"generator-based-middleware",
"promise-based-middleware",
"support"
],
"author": "gyson <eilian.yunsong@gmail.com>",
"contributors": [
"gyson <eilian.yunsong@gmail.com>",
"Lloyd Brookes <75pound@gmail.com>",
"Imed Jaberi <imed-jaberi@outlook.com> (https://www.3imed-jaberi.com)"
],
"license": "MIT",
"dependencies": {
"co": "^4.6.0",
"koa-compose": "^4.1.0"
},
"devDependencies": {
"koa": "^2.13.0",
"koa-v1": "npm:koa@1.7.0",
"mocha": "^7.1.1",
"nyc": "^15.1.0",
"rimraf": "^3.0.2",
"standard": "^14.3.4",
"supertest": "^4.0.2"
},
"engines": {
"node": ">= 10"
},
"bugs": {
"url": "https://github.com/gyson/koa-convert/issues"
},
"homepage": "https://github.com/gyson/koa-convert#readme"
}