отчет
This commit is contained in:
39
Lab/node_modules/regexparam/dist/index.js
generated
vendored
Normal file
39
Lab/node_modules/regexparam/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
function parse(str, loose) {
|
||||
if (str instanceof RegExp) return { keys:false, pattern:str };
|
||||
var c, o, tmp, ext, keys=[], pattern='', arr = str.split('/');
|
||||
arr[0] || arr.shift();
|
||||
|
||||
while (tmp = arr.shift()) {
|
||||
c = tmp[0];
|
||||
if (c === '*') {
|
||||
keys.push('wild');
|
||||
pattern += '/(.*)';
|
||||
} else if (c === ':') {
|
||||
o = tmp.indexOf('?', 1);
|
||||
ext = tmp.indexOf('.', 1);
|
||||
keys.push( tmp.substring(1, !!~o ? o : !!~ext ? ext : tmp.length) );
|
||||
pattern += !!~o && !~ext ? '(?:/([^/]+?))?' : '/([^/]+?)';
|
||||
if (!!~ext) pattern += (!!~o ? '?' : '') + '\\' + tmp.substring(ext);
|
||||
} else {
|
||||
pattern += '/' + tmp;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
keys: keys,
|
||||
pattern: new RegExp('^' + pattern + (loose ? '(?=$|\/)' : '\/?$'), 'i')
|
||||
};
|
||||
}
|
||||
|
||||
var RGX = /(\/|^)([:*][^/]*?)(\?)?(?=[/.]|$)/g;
|
||||
|
||||
// error if key missing?
|
||||
function inject(route, values) {
|
||||
return route.replace(RGX, (x, lead, key, optional) => {
|
||||
x = values[key=='*' ? 'wild' : key.substring(1)];
|
||||
return x ? '/'+x : (optional || key=='*') ? '' : '/' + key;
|
||||
});
|
||||
}
|
||||
|
||||
exports.inject = inject;
|
||||
exports.parse = parse;
|
||||
1
Lab/node_modules/regexparam/dist/index.min.js
generated
vendored
Normal file
1
Lab/node_modules/regexparam/dist/index.min.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.regexparam={})}(this,(function(e){var n=/(\/|^)([:*][^/]*?)(\?)?(?=[/.]|$)/g;e.inject=function(e,t){return e.replace(n,(e,n,i,r)=>(e=t["*"==i?"wild":i.substring(1)])?"/"+e:r||"*"==i?"":"/"+i)},e.parse=function(e,n){if(e instanceof RegExp)return{keys:!1,pattern:e};var t,i,r,f,s=[],p="",o=e.split("/");for(o[0]||o.shift();r=o.shift();)"*"===(t=r[0])?(s.push("wild"),p+="/(.*)"):":"===t?(i=r.indexOf("?",1),f=r.indexOf(".",1),s.push(r.substring(1,~i?i:~f?f:r.length)),p+=~i&&!~f?"(?:/([^/]+?))?":"/([^/]+?)",~f&&(p+=(~i?"?":"")+"\\"+r.substring(f))):p+="/"+r;return{keys:s,pattern:new RegExp("^"+p+(n?"(?=$|/)":"/?$"),"i")}}}));
|
||||
36
Lab/node_modules/regexparam/dist/index.mjs
generated
vendored
Normal file
36
Lab/node_modules/regexparam/dist/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
export function parse(str, loose) {
|
||||
if (str instanceof RegExp) return { keys:false, pattern:str };
|
||||
var c, o, tmp, ext, keys=[], pattern='', arr = str.split('/');
|
||||
arr[0] || arr.shift();
|
||||
|
||||
while (tmp = arr.shift()) {
|
||||
c = tmp[0];
|
||||
if (c === '*') {
|
||||
keys.push('wild');
|
||||
pattern += '/(.*)';
|
||||
} else if (c === ':') {
|
||||
o = tmp.indexOf('?', 1);
|
||||
ext = tmp.indexOf('.', 1);
|
||||
keys.push( tmp.substring(1, !!~o ? o : !!~ext ? ext : tmp.length) );
|
||||
pattern += !!~o && !~ext ? '(?:/([^/]+?))?' : '/([^/]+?)';
|
||||
if (!!~ext) pattern += (!!~o ? '?' : '') + '\\' + tmp.substring(ext);
|
||||
} else {
|
||||
pattern += '/' + tmp;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
keys: keys,
|
||||
pattern: new RegExp('^' + pattern + (loose ? '(?=$|\/)' : '\/?$'), 'i')
|
||||
};
|
||||
}
|
||||
|
||||
var RGX = /(\/|^)([:*][^/]*?)(\?)?(?=[/.]|$)/g;
|
||||
|
||||
// error if key missing?
|
||||
export function inject(route, values) {
|
||||
return route.replace(RGX, (x, lead, key, optional) => {
|
||||
x = values[key=='*' ? 'wild' : key.substring(1)];
|
||||
return x ? '/'+x : (optional || key=='*') ? '' : '/' + key;
|
||||
});
|
||||
}
|
||||
26
Lab/node_modules/regexparam/index.d.ts
generated
vendored
Normal file
26
Lab/node_modules/regexparam/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
export function parse(route: string, loose?: boolean): {
|
||||
keys: string[];
|
||||
pattern: RegExp;
|
||||
}
|
||||
|
||||
export function parse(route: RegExp): {
|
||||
keys: false;
|
||||
pattern: RegExp;
|
||||
}
|
||||
|
||||
export type RouteParams<T extends string> =
|
||||
T extends `${infer Prev}/*/${infer Rest}`
|
||||
? RouteParams<Prev> & { wild: string } & RouteParams<Rest>
|
||||
: T extends `${string}:${infer P}?/${infer Rest}`
|
||||
? { [K in P]?: string } & RouteParams<Rest>
|
||||
: T extends `${string}:${infer P}/${infer Rest}`
|
||||
? { [K in P]: string } & RouteParams<Rest>
|
||||
: T extends `${string}:${infer P}?`
|
||||
? { [K in P]?: string }
|
||||
: T extends `${string}:${infer P}`
|
||||
? { [K in P]: string }
|
||||
: T extends `${string}*`
|
||||
? { wild: string }
|
||||
: {};
|
||||
|
||||
export function inject<T extends string>(route: T, values: RouteParams<T>): string;
|
||||
21
Lab/node_modules/regexparam/license
generated
vendored
Normal file
21
Lab/node_modules/regexparam/license
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Luke Edwards <luke.edwards05@gmail.com> (lukeed.com)
|
||||
|
||||
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.
|
||||
48
Lab/node_modules/regexparam/package.json
generated
vendored
Normal file
48
Lab/node_modules/regexparam/package.json
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"name": "regexparam",
|
||||
"version": "2.0.2",
|
||||
"repository": "lukeed/regexparam",
|
||||
"description": "A tiny (394B) utility that converts route patterns into RegExp. Limited alternative to `path-to-regexp` 🙇",
|
||||
"unpkg": "dist/index.min.js",
|
||||
"module": "dist/index.mjs",
|
||||
"main": "dist/index.js",
|
||||
"types": "index.d.ts",
|
||||
"license": "MIT",
|
||||
"author": {
|
||||
"name": "Luke Edwards",
|
||||
"email": "luke.edwards05@gmail.com",
|
||||
"url": "https://lukeed.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "bundt",
|
||||
"test": "uvu -r esm test"
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./index.d.ts",
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.js",
|
||||
"default": "./dist/index.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"files": [
|
||||
"*.d.ts",
|
||||
"dist"
|
||||
],
|
||||
"keywords": [
|
||||
"regexp",
|
||||
"route",
|
||||
"routing",
|
||||
"inject",
|
||||
"parse"
|
||||
],
|
||||
"devDependencies": {
|
||||
"bundt": "1.1.2",
|
||||
"esm": "3.2.25",
|
||||
"uvu": "0.5.1"
|
||||
}
|
||||
}
|
||||
237
Lab/node_modules/regexparam/readme.md
generated
vendored
Normal file
237
Lab/node_modules/regexparam/readme.md
generated
vendored
Normal file
@@ -0,0 +1,237 @@
|
||||
# regexparam [](https://github.com/lukeed/regexparam/actions/workflows/ci.yml)
|
||||
|
||||
> A tiny (394B) utility that converts route patterns into RegExp. Limited alternative to [`path-to-regexp`](https://github.com/pillarjs/path-to-regexp) 🙇
|
||||
|
||||
With `regexparam`, you may turn a pathing string (eg, `/users/:id`) into a regular expression.
|
||||
|
||||
An object with shape of `{ keys, pattern }` is returned, where `pattern` is the `RegExp` and `keys` is an array of your parameter name(s) in the order that they appeared.
|
||||
|
||||
Unlike [`path-to-regexp`](https://github.com/pillarjs/path-to-regexp), this module does not create a `keys` dictionary, nor mutate an existing variable. Also, this only ships a parser, which only accept strings. Similarly, and most importantly, `regexparam` **only** handles basic pathing operators:
|
||||
|
||||
* Static (`/foo`, `/foo/bar`)
|
||||
* Parameter (`/:title`, `/books/:title`, `/books/:genre/:title`)
|
||||
* Parameter w/ Suffix (`/movies/:title.mp4`, `/movies/:title.(mp4|mov)`)
|
||||
* Optional Parameters (`/:title?`, `/books/:title?`, `/books/:genre/:title?`)
|
||||
* Wildcards (`*`, `/books/*`, `/books/:genre/*`)
|
||||
|
||||
This module exposes three module definitions:
|
||||
|
||||
* **CommonJS**: [`dist/index.js`](https://unpkg.com/regexparam/dist/index.js)
|
||||
* **ESModule**: [`dist/index.mjs`](https://unpkg.com/regexparam/dist/index.mjs)
|
||||
* **UMD**: [`dist/index.min.js`](https://unpkg.com/regexparam/dist/index.min.js)
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install --save regexparam
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import { parse, inject } from 'regexparam';
|
||||
|
||||
// Example param-assignment
|
||||
function exec(path, result) {
|
||||
let i=0, out={};
|
||||
let matches = result.pattern.exec(path);
|
||||
while (i < result.keys.length) {
|
||||
out[ result.keys[i] ] = matches[++i] || null;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
// Parameter, with Optional Parameter
|
||||
// ---
|
||||
let foo = parse('/books/:genre/:title?')
|
||||
// foo.pattern => /^\/books\/([^\/]+?)(?:\/([^\/]+?))?\/?$/i
|
||||
// foo.keys => ['genre', 'title']
|
||||
|
||||
foo.pattern.test('/books/horror'); //=> true
|
||||
foo.pattern.test('/books/horror/goosebumps'); //=> true
|
||||
|
||||
exec('/books/horror', foo);
|
||||
//=> { genre: 'horror', title: null }
|
||||
|
||||
exec('/books/horror/goosebumps', foo);
|
||||
//=> { genre: 'horror', title: 'goosebumps' }
|
||||
|
||||
|
||||
// Parameter, with suffix
|
||||
// ---
|
||||
let bar = parse('/movies/:title.(mp4|mov)');
|
||||
// bar.pattern => /^\/movies\/([^\/]+?)\.(mp4|mov)\/?$/i
|
||||
// bar.keys => ['title']
|
||||
|
||||
bar.pattern.test('/movies/narnia'); //=> false
|
||||
bar.pattern.test('/movies/narnia.mp3'); //=> false
|
||||
bar.pattern.test('/movies/narnia.mp4'); //=> true
|
||||
|
||||
exec('/movies/narnia.mp4', bar);
|
||||
//=> { title: 'narnia' }
|
||||
|
||||
|
||||
// Wildcard
|
||||
// ---
|
||||
let baz = parse('users/*');
|
||||
// baz.pattern => /^\/users\/(.*)\/?$/i
|
||||
// baz.keys => ['wild']
|
||||
|
||||
baz.pattern.test('/users'); //=> false
|
||||
baz.pattern.test('/users/lukeed'); //=> true
|
||||
|
||||
exec('/users/lukeed/repos/new', baz);
|
||||
//=> { wild: 'lukeed/repos/new' }
|
||||
|
||||
|
||||
// Injecting
|
||||
// ---
|
||||
|
||||
inject('/users/:id', {
|
||||
id: 'lukeed'
|
||||
}); //=> '/users/lukeed'
|
||||
|
||||
inject('/movies/:title.mp4', {
|
||||
title: 'narnia'
|
||||
}); //=> '/movies/narnia.mp4'
|
||||
|
||||
inject('/:foo/:bar?/:baz?', {
|
||||
foo: 'aaa'
|
||||
}); //=> '/aaa'
|
||||
|
||||
inject('/:foo/:bar?/:baz?', {
|
||||
foo: 'aaa',
|
||||
baz: 'ccc'
|
||||
}); //=> '/aaa/ccc'
|
||||
|
||||
inject('/posts/:slug/*', {
|
||||
slug: 'hello',
|
||||
}); //=> '/posts/hello'
|
||||
|
||||
inject('/posts/:slug/*', {
|
||||
slug: 'hello',
|
||||
wild: 'x/y/z',
|
||||
}); //=> '/posts/hello/x/y/z'
|
||||
|
||||
// Missing non-optional value
|
||||
// ~> keeps the pattern in output
|
||||
inject('/hello/:world', {
|
||||
abc: 123
|
||||
}); //=> '/hello/:world'
|
||||
```
|
||||
|
||||
> **Important:** When matching/testing against a generated RegExp, your path **must** begin with a leading slash (`"/"`)!
|
||||
|
||||
## Regular Expressions
|
||||
|
||||
For fine-tuned control, you may pass a `RegExp` value directly to `regexparam` as its only parameter.
|
||||
|
||||
In these situations, `regexparam` **does not** parse nor manipulate your pattern in any way! Because of this, `regexparam` has no "insight" on your route, and instead trusts your input fully. In code, this means that the return value's `keys` is always equal to `false` and the `pattern` is identical to your input value.
|
||||
|
||||
This also means that you must manage and parse your own `keys`~!<br>
|
||||
You may use [named capture groups](https://javascript.info/regexp-groups#named-groups) or traverse the matched segments manually the "old-fashioned" way:
|
||||
|
||||
> **Important:** Please check your target browsers' and target [Node.js runtimes' support](https://node.green/#ES2018-features--RegExp-named-capture-groups)!
|
||||
|
||||
```js
|
||||
// Named capture group
|
||||
const named = regexparam.parse(/^\/posts[/](?<year>[0-9]{4})[/](?<month>[0-9]{2})[/](?<title>[^\/]+)/i);
|
||||
const { groups } = named.pattern.exec('/posts/2019/05/hello-world');
|
||||
console.log(groups);
|
||||
//=> { year: '2019', month: '05', title: 'hello-world' }
|
||||
|
||||
// Widely supported / "Old-fashioned"
|
||||
const named = regexparam.parse(/^\/posts[/]([0-9]{4})[/]([0-9]{2})[/]([^\/]+)/i);
|
||||
const [url, year, month, title] = named.pattern.exec('/posts/2019/05/hello-world');
|
||||
console.log(year, month, title);
|
||||
//=> 2019 05 hello-world
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### regexparam.parse(input: RegExp)
|
||||
### regexparam.parse(input: string, loose?: boolean)
|
||||
Returns: `Object`
|
||||
|
||||
Parse a route pattern into an equivalent RegExp pattern. Also collects the names of pattern's parameters as a `keys` array. An `input` that's already a RegExp is kept as is, and `regexparam` makes no additional insights.
|
||||
|
||||
Returns a `{ keys, pattern }` object, where `pattern` is always a `RegExp` instance and `keys` is either `false` or a list of extracted parameter names.
|
||||
|
||||
> **Important:** The `keys` will _always_ be `false` when `input` is a RegExp and it will _always_ be an Array when `input` is a string.
|
||||
|
||||
#### input
|
||||
Type: `string` or `RegExp`
|
||||
|
||||
When `input` is a string, it's treated as a route pattern and an equivalent RegExp is generated.
|
||||
|
||||
> **Note:** It does not matter if `input` strings begin with a `/` — it will be added if missing.
|
||||
|
||||
When `input` is a RegExp, it will be used **as is** – no modifications will be made.
|
||||
|
||||
#### loose
|
||||
Type: `boolean`<br>
|
||||
Default: `false`
|
||||
|
||||
Should the `RegExp` match URLs that are longer than the [`str`](#str) pattern itself?<br>
|
||||
By default, the generated `RegExp` will test that the URL begins and _ends with_ the pattern.
|
||||
|
||||
> **Important:** When `input` is a RegExp, the `loose` argument is ignored!
|
||||
|
||||
```js
|
||||
const { parse } = require('regexparam');
|
||||
|
||||
parse('/users').pattern.test('/users/lukeed'); //=> false
|
||||
parse('/users', true).pattern.test('/users/lukeed'); //=> true
|
||||
|
||||
parse('/users/:name').pattern.test('/users/lukeed/repos'); //=> false
|
||||
parse('/users/:name', true).pattern.test('/users/lukeed/repos'); //=> true
|
||||
```
|
||||
|
||||
|
||||
### regexparam.inject(pattern: string, values: object)
|
||||
Returns: `string`
|
||||
|
||||
Returns a new string by replacing the `pattern` segments/parameters with their matching values.
|
||||
|
||||
> **Important:** Named segments (eg, `/:name`) that _do not_ have a `values` match will be kept in the output. This is true _except for_ optional segments (eg, `/:name?`) and wildcard segments (eg, `/*`).
|
||||
|
||||
#### pattern
|
||||
Type: `string`
|
||||
|
||||
The route pattern that to receive injections.
|
||||
|
||||
#### values
|
||||
Type: `Record<string, string>`
|
||||
|
||||
The values to be injected. The keys within `values` must match the `pattern`'s segments in order to be replaced.
|
||||
|
||||
> **Note:** To replace a wildcard segment (eg, `/*`), define a `values.wild` key.
|
||||
|
||||
|
||||
## Deno
|
||||
|
||||
As of version `1.3.0`, you may use `regexparam` with Deno. These options are all valid:
|
||||
|
||||
```ts
|
||||
// The official Deno registry:
|
||||
import regexparam from 'https://deno.land/x/regexparam/src/index.js';
|
||||
// Third-party CDNs with ESM support:
|
||||
import regexparam from 'https://cdn.skypack.dev/regexparam';
|
||||
import regexparam from 'https://esm.sh/regexparam';
|
||||
```
|
||||
|
||||
> **Note:** All registries support versioned URLs, if desired. <br>The above examples always resolve to the latest published version.
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [trouter](https://github.com/lukeed/trouter) - A server-side HTTP router that extends from this module.
|
||||
- [matchit](https://github.com/lukeed/matchit) - Similar (650B) library, but relies on String comparison instead of `RegExp`s.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Luke Edwards](https://lukeed.com)
|
||||
Reference in New Issue
Block a user