完成中转仓管理
This commit is contained in:
21
datav/node_modules/path-to-regexp/LICENSE
generated
vendored
Normal file
21
datav/node_modules/path-to-regexp/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Blake Embrey (hello@blakeembrey.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.
|
||||
224
datav/node_modules/path-to-regexp/Readme.md
generated
vendored
Normal file
224
datav/node_modules/path-to-regexp/Readme.md
generated
vendored
Normal file
@@ -0,0 +1,224 @@
|
||||
# Path-to-RegExp
|
||||
|
||||
> Turn a path string such as `/user/:name` into a regular expression.
|
||||
|
||||
[![NPM version][npm-image]][npm-url]
|
||||
[![NPM downloads][downloads-image]][downloads-url]
|
||||
[![Build status][build-image]][build-url]
|
||||
[![Build coverage][coverage-image]][coverage-url]
|
||||
[![License][license-image]][license-url]
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
npm install path-to-regexp --save
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const {
|
||||
match,
|
||||
pathToRegexp,
|
||||
compile,
|
||||
parse,
|
||||
stringify,
|
||||
} = require("path-to-regexp");
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
Parameters match arbitrary strings in a path by matching up to the end of the segment, or up to any proceeding tokens. They are defined by prefixing a colon to the parameter name (`:foo`). Parameter names can use any valid JavaScript identifier, or be double quoted to use other characters (`:"param-name"`).
|
||||
|
||||
```js
|
||||
const fn = match("/:foo/:bar");
|
||||
|
||||
fn("/test/route");
|
||||
//=> { path: '/test/route', params: { foo: 'test', bar: 'route' } }
|
||||
```
|
||||
|
||||
### Wildcard
|
||||
|
||||
Wildcard parameters match one or more characters across multiple segments. They are defined the same way as regular parameters, but are prefixed with an asterisk (`*foo`).
|
||||
|
||||
```js
|
||||
const fn = match("/*splat");
|
||||
|
||||
fn("/bar/baz");
|
||||
//=> { path: '/bar/baz', params: { splat: [ 'bar', 'baz' ] } }
|
||||
```
|
||||
|
||||
### Optional
|
||||
|
||||
Braces can be used to define parts of the path that are optional.
|
||||
|
||||
```js
|
||||
const fn = match("/users{/:id}/delete");
|
||||
|
||||
fn("/users/delete");
|
||||
//=> { path: '/users/delete', params: {} }
|
||||
|
||||
fn("/users/123/delete");
|
||||
//=> { path: '/users/123/delete', params: { id: '123' } }
|
||||
```
|
||||
|
||||
## Match
|
||||
|
||||
The `match` function returns a function for matching strings against a path:
|
||||
|
||||
- **path** String, `TokenData` object, or array of strings and `TokenData` objects.
|
||||
- **options** _(optional)_ (Extends [pathToRegexp](#pathToRegexp) options)
|
||||
- **decode** Function for decoding strings to params, or `false` to disable all processing. (default: `decodeURIComponent`)
|
||||
|
||||
```js
|
||||
const fn = match("/foo/:bar");
|
||||
```
|
||||
|
||||
**Please note:** `path-to-regexp` is intended for ordered data (e.g. paths, hosts). It can not handle arbitrarily ordered data (e.g. query strings, URL fragments, JSON, etc).
|
||||
|
||||
## PathToRegexp
|
||||
|
||||
The `pathToRegexp` function returns the `regexp` for matching strings against paths, and an array of `keys` for understanding the `RegExp#exec` matches.
|
||||
|
||||
- **path** String, `TokenData` object, or array of strings and `TokenData` objects.
|
||||
- **options** _(optional)_ (See [parse](#parse) for more options)
|
||||
- **sensitive** Regexp will be case sensitive. (default: `false`)
|
||||
- **end** Validate the match reaches the end of the string. (default: `true`)
|
||||
- **delimiter** The default delimiter for segments, e.g. `[^/]` for `:named` parameters. (default: `'/'`)
|
||||
- **trailing** Allows optional trailing delimiter to match. (default: `true`)
|
||||
|
||||
```js
|
||||
const { regexp, keys } = pathToRegexp("/foo/:bar");
|
||||
|
||||
regexp.exec("/foo/123"); //=> ["/foo/123", "123"]
|
||||
```
|
||||
|
||||
## Compile ("Reverse" Path-To-RegExp)
|
||||
|
||||
The `compile` function will return a function for transforming parameters into a valid path:
|
||||
|
||||
- **path** A string or `TokenData` object.
|
||||
- **options** (See [parse](#parse) for more options)
|
||||
- **delimiter** The default delimiter for segments, e.g. `[^/]` for `:named` parameters. (default: `'/'`)
|
||||
- **encode** Function for encoding input strings for output into the path, or `false` to disable entirely. (default: `encodeURIComponent`)
|
||||
|
||||
```js
|
||||
const toPath = compile("/user/:id");
|
||||
|
||||
toPath({ id: "name" }); //=> "/user/name"
|
||||
toPath({ id: "café" }); //=> "/user/caf%C3%A9"
|
||||
|
||||
const toPathRepeated = compile("/*segment");
|
||||
|
||||
toPathRepeated({ segment: ["foo"] }); //=> "/foo"
|
||||
toPathRepeated({ segment: ["a", "b", "c"] }); //=> "/a/b/c"
|
||||
|
||||
// When disabling `encode`, you need to make sure inputs are encoded correctly. No arrays are accepted.
|
||||
const toPathRaw = compile("/user/:id", { encode: false });
|
||||
|
||||
toPathRaw({ id: "%3A%2F" }); //=> "/user/%3A%2F"
|
||||
```
|
||||
|
||||
## Stringify
|
||||
|
||||
Transform a `TokenData` object to a Path-to-RegExp string.
|
||||
|
||||
- **data** A `TokenData` object.
|
||||
|
||||
```js
|
||||
const data = {
|
||||
tokens: [
|
||||
{ type: "text", value: "/" },
|
||||
{ type: "param", name: "foo" },
|
||||
],
|
||||
};
|
||||
|
||||
const path = stringify(data); //=> "/:foo"
|
||||
```
|
||||
|
||||
## Developers
|
||||
|
||||
- If you are rewriting paths with match and compile, consider using `encode: false` and `decode: false` to keep raw paths passed around.
|
||||
- To ensure matches work on paths containing characters usually encoded, such as emoji, consider using [encodeurl](https://github.com/pillarjs/encodeurl) for `encodePath`.
|
||||
|
||||
### Parse
|
||||
|
||||
The `parse` function accepts a string and returns `TokenData`, which can be used with `match` and `compile`.
|
||||
|
||||
- **path** A string.
|
||||
- **options** _(optional)_
|
||||
- **encodePath** A function for encoding input strings. (default: `x => x`, recommended: [`encodeurl`](https://github.com/pillarjs/encodeurl))
|
||||
|
||||
### Tokens
|
||||
|
||||
`TokenData` has two properties:
|
||||
|
||||
- **tokens** A sequence of tokens, currently of types `text`, `parameter`, `wildcard`, or `group`.
|
||||
- **originalPath** The original path used with `parse`, shown in error messages to assist debugging.
|
||||
|
||||
### Custom path
|
||||
|
||||
In some applications you may not be able to use the `path-to-regexp` syntax, but you still want to use this library for `match` and `compile`. For example:
|
||||
|
||||
```js
|
||||
import { match } from "path-to-regexp";
|
||||
|
||||
const tokens = [
|
||||
{ type: "text", value: "/" },
|
||||
{ type: "parameter", name: "foo" },
|
||||
];
|
||||
const originalPath = "/[foo]"; // To help debug error messages.
|
||||
const path = { tokens, originalPath };
|
||||
const fn = match(path);
|
||||
|
||||
fn("/test"); //=> { path: '/test', index: 0, params: { foo: 'test' } }
|
||||
```
|
||||
|
||||
## Errors
|
||||
|
||||
An effort has been made to ensure ambiguous paths from previous releases throw an error. This means you might be seeing an error when things worked before.
|
||||
|
||||
### Missing parameter name
|
||||
|
||||
Parameter names must be provided after `:` or `*`, for example `/*path`. They can be valid JavaScript identifiers (e.g. `:myName`) or JSON strings (`:"my-name"`).
|
||||
|
||||
### Unexpected `?` or `+`
|
||||
|
||||
In past releases, `?`, `*`, and `+` were used to denote optional or repeating parameters. As an alternative, try these:
|
||||
|
||||
- For optional (`?`), use braces: `/file{.:ext}`.
|
||||
- For one or more (`+`), use a wildcard: `/*path`.
|
||||
- For zero or more (`*`), use both: `/files{/*path}`.
|
||||
|
||||
### Unexpected `(`, `)`, `[`, `]`, etc.
|
||||
|
||||
Previous versions of Path-to-RegExp used these for RegExp features. This version no longer supports them so they've been reserved to avoid ambiguity. To match these characters literally, escape them with a backslash, e.g. `"\\("`.
|
||||
|
||||
### Unterminated quote
|
||||
|
||||
Parameter names can be wrapped in double quote characters, and this error means you forgot to close the quote character. For example, `:"foo`.
|
||||
|
||||
### Express <= 4.x
|
||||
|
||||
Path-To-RegExp breaks compatibility with Express <= `4.x` in the following ways:
|
||||
|
||||
- The wildcard `*` must have a name and matches the behavior of parameters `:`.
|
||||
- The optional character `?` is no longer supported, use braces instead: `/:file{.:ext}`.
|
||||
- Regexp characters are not supported.
|
||||
- Some characters have been reserved to avoid confusion during upgrade (`()[]?+!`).
|
||||
- Parameter names now support valid JavaScript identifiers, or quoted like `:"this"`.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
[npm-image]: https://img.shields.io/npm/v/path-to-regexp
|
||||
[npm-url]: https://npmjs.org/package/path-to-regexp
|
||||
[downloads-image]: https://img.shields.io/npm/dm/path-to-regexp
|
||||
[downloads-url]: https://npmjs.org/package/path-to-regexp
|
||||
[build-image]: https://img.shields.io/github/actions/workflow/status/pillarjs/path-to-regexp/ci.yml?branch=master
|
||||
[build-url]: https://github.com/pillarjs/path-to-regexp/actions/workflows/ci.yml?query=branch%3Amaster
|
||||
[coverage-image]: https://img.shields.io/codecov/c/gh/pillarjs/path-to-regexp
|
||||
[coverage-url]: https://codecov.io/gh/pillarjs/path-to-regexp
|
||||
[license-image]: http://img.shields.io/npm/l/path-to-regexp.svg?style=flat
|
||||
[license-url]: LICENSE.md
|
||||
144
datav/node_modules/path-to-regexp/dist/index.d.ts
generated
vendored
Normal file
144
datav/node_modules/path-to-regexp/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,144 @@
|
||||
/**
|
||||
* Encode a string into another string.
|
||||
*/
|
||||
export type Encode = (value: string) => string;
|
||||
/**
|
||||
* Decode a string into another string.
|
||||
*/
|
||||
export type Decode = (value: string) => string;
|
||||
export interface ParseOptions {
|
||||
/**
|
||||
* A function for encoding input strings.
|
||||
*/
|
||||
encodePath?: Encode;
|
||||
}
|
||||
export interface PathToRegexpOptions {
|
||||
/**
|
||||
* Matches the path completely without trailing characters. (default: `true`)
|
||||
*/
|
||||
end?: boolean;
|
||||
/**
|
||||
* Allows optional trailing delimiter to match. (default: `true`)
|
||||
*/
|
||||
trailing?: boolean;
|
||||
/**
|
||||
* Match will be case sensitive. (default: `false`)
|
||||
*/
|
||||
sensitive?: boolean;
|
||||
/**
|
||||
* The default delimiter for segments. (default: `'/'`)
|
||||
*/
|
||||
delimiter?: string;
|
||||
}
|
||||
export interface MatchOptions extends PathToRegexpOptions {
|
||||
/**
|
||||
* Function for decoding strings for params, or `false` to disable entirely. (default: `decodeURIComponent`)
|
||||
*/
|
||||
decode?: Decode | false;
|
||||
}
|
||||
export interface CompileOptions {
|
||||
/**
|
||||
* Function for encoding input strings for output into the path, or `false` to disable entirely. (default: `encodeURIComponent`)
|
||||
*/
|
||||
encode?: Encode | false;
|
||||
/**
|
||||
* The default delimiter for segments. (default: `'/'`)
|
||||
*/
|
||||
delimiter?: string;
|
||||
}
|
||||
/**
|
||||
* Plain text.
|
||||
*/
|
||||
export interface Text {
|
||||
type: "text";
|
||||
value: string;
|
||||
}
|
||||
/**
|
||||
* A parameter designed to match arbitrary text within a segment.
|
||||
*/
|
||||
export interface Parameter {
|
||||
type: "param";
|
||||
name: string;
|
||||
}
|
||||
/**
|
||||
* A wildcard parameter designed to match multiple segments.
|
||||
*/
|
||||
export interface Wildcard {
|
||||
type: "wildcard";
|
||||
name: string;
|
||||
}
|
||||
/**
|
||||
* A set of possible tokens to expand when matching.
|
||||
*/
|
||||
export interface Group {
|
||||
type: "group";
|
||||
tokens: Token[];
|
||||
}
|
||||
/**
|
||||
* A token that corresponds with a regexp capture.
|
||||
*/
|
||||
export type Key = Parameter | Wildcard;
|
||||
/**
|
||||
* A sequence of `path-to-regexp` keys that match capturing groups.
|
||||
*/
|
||||
export type Keys = Array<Key>;
|
||||
/**
|
||||
* A sequence of path match characters.
|
||||
*/
|
||||
export type Token = Text | Parameter | Wildcard | Group;
|
||||
/**
|
||||
* Tokenized path instance.
|
||||
*/
|
||||
export declare class TokenData {
|
||||
readonly tokens: Token[];
|
||||
readonly originalPath?: string | undefined;
|
||||
constructor(tokens: Token[], originalPath?: string | undefined);
|
||||
}
|
||||
/**
|
||||
* ParseError is thrown when there is an error processing the path.
|
||||
*/
|
||||
export declare class PathError extends TypeError {
|
||||
readonly originalPath: string | undefined;
|
||||
constructor(message: string, originalPath: string | undefined);
|
||||
}
|
||||
/**
|
||||
* Parse a string for the raw tokens.
|
||||
*/
|
||||
export declare function parse(str: string, options?: ParseOptions): TokenData;
|
||||
/**
|
||||
* Compile a string to a template function for the path.
|
||||
*/
|
||||
export declare function compile<P extends ParamData = ParamData>(path: Path, options?: CompileOptions & ParseOptions): (params?: P) => string;
|
||||
export type ParamData = Partial<Record<string, string | string[]>>;
|
||||
export type PathFunction<P extends ParamData> = (data?: P) => string;
|
||||
/**
|
||||
* A match result contains data about the path match.
|
||||
*/
|
||||
export interface MatchResult<P extends ParamData> {
|
||||
path: string;
|
||||
params: P;
|
||||
}
|
||||
/**
|
||||
* A match is either `false` (no match) or a match result.
|
||||
*/
|
||||
export type Match<P extends ParamData> = false | MatchResult<P>;
|
||||
/**
|
||||
* The match function takes a string and returns whether it matched the path.
|
||||
*/
|
||||
export type MatchFunction<P extends ParamData> = (path: string) => Match<P>;
|
||||
/**
|
||||
* Supported path types.
|
||||
*/
|
||||
export type Path = string | TokenData;
|
||||
/**
|
||||
* Transform a path into a match function.
|
||||
*/
|
||||
export declare function match<P extends ParamData>(path: Path | Path[], options?: MatchOptions & ParseOptions): MatchFunction<P>;
|
||||
export declare function pathToRegexp(path: Path | Path[], options?: PathToRegexpOptions & ParseOptions): {
|
||||
regexp: RegExp;
|
||||
keys: Keys;
|
||||
};
|
||||
/**
|
||||
* Stringify token data into a path string.
|
||||
*/
|
||||
export declare function stringify(data: TokenData): string;
|
||||
409
datav/node_modules/path-to-regexp/dist/index.js
generated
vendored
Normal file
409
datav/node_modules/path-to-regexp/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,409 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PathError = exports.TokenData = void 0;
|
||||
exports.parse = parse;
|
||||
exports.compile = compile;
|
||||
exports.match = match;
|
||||
exports.pathToRegexp = pathToRegexp;
|
||||
exports.stringify = stringify;
|
||||
const DEFAULT_DELIMITER = "/";
|
||||
const NOOP_VALUE = (value) => value;
|
||||
const ID_START = /^[$_\p{ID_Start}]$/u;
|
||||
const ID_CONTINUE = /^[$\u200c\u200d\p{ID_Continue}]$/u;
|
||||
const SIMPLE_TOKENS = {
|
||||
// Groups.
|
||||
"{": "{",
|
||||
"}": "}",
|
||||
// Reserved.
|
||||
"(": "(",
|
||||
")": ")",
|
||||
"[": "[",
|
||||
"]": "]",
|
||||
"+": "+",
|
||||
"?": "?",
|
||||
"!": "!",
|
||||
};
|
||||
/**
|
||||
* Escape text for stringify to path.
|
||||
*/
|
||||
function escapeText(str) {
|
||||
return str.replace(/[{}()\[\]+?!:*\\]/g, "\\$&");
|
||||
}
|
||||
/**
|
||||
* Escape a regular expression string.
|
||||
*/
|
||||
function escape(str) {
|
||||
return str.replace(/[.+*?^${}()[\]|/\\]/g, "\\$&");
|
||||
}
|
||||
/**
|
||||
* Tokenized path instance.
|
||||
*/
|
||||
class TokenData {
|
||||
constructor(tokens, originalPath) {
|
||||
this.tokens = tokens;
|
||||
this.originalPath = originalPath;
|
||||
}
|
||||
}
|
||||
exports.TokenData = TokenData;
|
||||
/**
|
||||
* ParseError is thrown when there is an error processing the path.
|
||||
*/
|
||||
class PathError extends TypeError {
|
||||
constructor(message, originalPath) {
|
||||
let text = message;
|
||||
if (originalPath)
|
||||
text += `: ${originalPath}`;
|
||||
text += `; visit https://git.new/pathToRegexpError for info`;
|
||||
super(text);
|
||||
this.originalPath = originalPath;
|
||||
}
|
||||
}
|
||||
exports.PathError = PathError;
|
||||
/**
|
||||
* Parse a string for the raw tokens.
|
||||
*/
|
||||
function parse(str, options = {}) {
|
||||
const { encodePath = NOOP_VALUE } = options;
|
||||
const chars = [...str];
|
||||
const tokens = [];
|
||||
let index = 0;
|
||||
let pos = 0;
|
||||
function name() {
|
||||
let value = "";
|
||||
if (ID_START.test(chars[index])) {
|
||||
do {
|
||||
value += chars[index++];
|
||||
} while (ID_CONTINUE.test(chars[index]));
|
||||
}
|
||||
else if (chars[index] === '"') {
|
||||
let quoteStart = index;
|
||||
while (index++ < chars.length) {
|
||||
if (chars[index] === '"') {
|
||||
index++;
|
||||
quoteStart = 0;
|
||||
break;
|
||||
}
|
||||
// Increment over escape characters.
|
||||
if (chars[index] === "\\")
|
||||
index++;
|
||||
value += chars[index];
|
||||
}
|
||||
if (quoteStart) {
|
||||
throw new PathError(`Unterminated quote at index ${quoteStart}`, str);
|
||||
}
|
||||
}
|
||||
if (!value) {
|
||||
throw new PathError(`Missing parameter name at index ${index}`, str);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
while (index < chars.length) {
|
||||
const value = chars[index];
|
||||
const type = SIMPLE_TOKENS[value];
|
||||
if (type) {
|
||||
tokens.push({ type, index: index++, value });
|
||||
}
|
||||
else if (value === "\\") {
|
||||
tokens.push({ type: "escape", index: index++, value: chars[index++] });
|
||||
}
|
||||
else if (value === ":") {
|
||||
tokens.push({ type: "param", index: index++, value: name() });
|
||||
}
|
||||
else if (value === "*") {
|
||||
tokens.push({ type: "wildcard", index: index++, value: name() });
|
||||
}
|
||||
else {
|
||||
tokens.push({ type: "char", index: index++, value });
|
||||
}
|
||||
}
|
||||
tokens.push({ type: "end", index, value: "" });
|
||||
function consumeUntil(endType) {
|
||||
const output = [];
|
||||
while (true) {
|
||||
const token = tokens[pos++];
|
||||
if (token.type === endType)
|
||||
break;
|
||||
if (token.type === "char" || token.type === "escape") {
|
||||
let path = token.value;
|
||||
let cur = tokens[pos];
|
||||
while (cur.type === "char" || cur.type === "escape") {
|
||||
path += cur.value;
|
||||
cur = tokens[++pos];
|
||||
}
|
||||
output.push({
|
||||
type: "text",
|
||||
value: encodePath(path),
|
||||
});
|
||||
continue;
|
||||
}
|
||||
if (token.type === "param" || token.type === "wildcard") {
|
||||
output.push({
|
||||
type: token.type,
|
||||
name: token.value,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
if (token.type === "{") {
|
||||
output.push({
|
||||
type: "group",
|
||||
tokens: consumeUntil("}"),
|
||||
});
|
||||
continue;
|
||||
}
|
||||
throw new PathError(`Unexpected ${token.type} at index ${token.index}, expected ${endType}`, str);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
return new TokenData(consumeUntil("end"), str);
|
||||
}
|
||||
/**
|
||||
* Compile a string to a template function for the path.
|
||||
*/
|
||||
function compile(path, options = {}) {
|
||||
const { encode = encodeURIComponent, delimiter = DEFAULT_DELIMITER } = options;
|
||||
const data = typeof path === "object" ? path : parse(path, options);
|
||||
const fn = tokensToFunction(data.tokens, delimiter, encode);
|
||||
return function path(params = {}) {
|
||||
const [path, ...missing] = fn(params);
|
||||
if (missing.length) {
|
||||
throw new TypeError(`Missing parameters: ${missing.join(", ")}`);
|
||||
}
|
||||
return path;
|
||||
};
|
||||
}
|
||||
function tokensToFunction(tokens, delimiter, encode) {
|
||||
const encoders = tokens.map((token) => tokenToFunction(token, delimiter, encode));
|
||||
return (data) => {
|
||||
const result = [""];
|
||||
for (const encoder of encoders) {
|
||||
const [value, ...extras] = encoder(data);
|
||||
result[0] += value;
|
||||
result.push(...extras);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Convert a single token into a path building function.
|
||||
*/
|
||||
function tokenToFunction(token, delimiter, encode) {
|
||||
if (token.type === "text")
|
||||
return () => [token.value];
|
||||
if (token.type === "group") {
|
||||
const fn = tokensToFunction(token.tokens, delimiter, encode);
|
||||
return (data) => {
|
||||
const [value, ...missing] = fn(data);
|
||||
if (!missing.length)
|
||||
return [value];
|
||||
return [""];
|
||||
};
|
||||
}
|
||||
const encodeValue = encode || NOOP_VALUE;
|
||||
if (token.type === "wildcard" && encode !== false) {
|
||||
return (data) => {
|
||||
const value = data[token.name];
|
||||
if (value == null)
|
||||
return ["", token.name];
|
||||
if (!Array.isArray(value) || value.length === 0) {
|
||||
throw new TypeError(`Expected "${token.name}" to be a non-empty array`);
|
||||
}
|
||||
return [
|
||||
value
|
||||
.map((value, index) => {
|
||||
if (typeof value !== "string") {
|
||||
throw new TypeError(`Expected "${token.name}/${index}" to be a string`);
|
||||
}
|
||||
return encodeValue(value);
|
||||
})
|
||||
.join(delimiter),
|
||||
];
|
||||
};
|
||||
}
|
||||
return (data) => {
|
||||
const value = data[token.name];
|
||||
if (value == null)
|
||||
return ["", token.name];
|
||||
if (typeof value !== "string") {
|
||||
throw new TypeError(`Expected "${token.name}" to be a string`);
|
||||
}
|
||||
return [encodeValue(value)];
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Transform a path into a match function.
|
||||
*/
|
||||
function match(path, options = {}) {
|
||||
const { decode = decodeURIComponent, delimiter = DEFAULT_DELIMITER } = options;
|
||||
const { regexp, keys } = pathToRegexp(path, options);
|
||||
const decoders = keys.map((key) => {
|
||||
if (decode === false)
|
||||
return NOOP_VALUE;
|
||||
if (key.type === "param")
|
||||
return decode;
|
||||
return (value) => value.split(delimiter).map(decode);
|
||||
});
|
||||
return function match(input) {
|
||||
const m = regexp.exec(input);
|
||||
if (!m)
|
||||
return false;
|
||||
const path = m[0];
|
||||
const params = Object.create(null);
|
||||
for (let i = 1; i < m.length; i++) {
|
||||
if (m[i] === undefined)
|
||||
continue;
|
||||
const key = keys[i - 1];
|
||||
const decoder = decoders[i - 1];
|
||||
params[key.name] = decoder(m[i]);
|
||||
}
|
||||
return { path, params };
|
||||
};
|
||||
}
|
||||
function pathToRegexp(path, options = {}) {
|
||||
const { delimiter = DEFAULT_DELIMITER, end = true, sensitive = false, trailing = true, } = options;
|
||||
const keys = [];
|
||||
const flags = sensitive ? "" : "i";
|
||||
const sources = [];
|
||||
for (const input of pathsToArray(path, [])) {
|
||||
const data = typeof input === "object" ? input : parse(input, options);
|
||||
for (const tokens of flatten(data.tokens, 0, [])) {
|
||||
sources.push(toRegExpSource(tokens, delimiter, keys, data.originalPath));
|
||||
}
|
||||
}
|
||||
let pattern = `^(?:${sources.join("|")})`;
|
||||
if (trailing)
|
||||
pattern += `(?:${escape(delimiter)}$)?`;
|
||||
pattern += end ? "$" : `(?=${escape(delimiter)}|$)`;
|
||||
const regexp = new RegExp(pattern, flags);
|
||||
return { regexp, keys };
|
||||
}
|
||||
/**
|
||||
* Convert a path or array of paths into a flat array.
|
||||
*/
|
||||
function pathsToArray(paths, init) {
|
||||
if (Array.isArray(paths)) {
|
||||
for (const p of paths)
|
||||
pathsToArray(p, init);
|
||||
}
|
||||
else {
|
||||
init.push(paths);
|
||||
}
|
||||
return init;
|
||||
}
|
||||
/**
|
||||
* Generate a flat list of sequence tokens from the given tokens.
|
||||
*/
|
||||
function* flatten(tokens, index, init) {
|
||||
if (index === tokens.length) {
|
||||
return yield init;
|
||||
}
|
||||
const token = tokens[index];
|
||||
if (token.type === "group") {
|
||||
for (const seq of flatten(token.tokens, 0, init.slice())) {
|
||||
yield* flatten(tokens, index + 1, seq);
|
||||
}
|
||||
}
|
||||
else {
|
||||
init.push(token);
|
||||
}
|
||||
yield* flatten(tokens, index + 1, init);
|
||||
}
|
||||
/**
|
||||
* Transform a flat sequence of tokens into a regular expression.
|
||||
*/
|
||||
function toRegExpSource(tokens, delimiter, keys, originalPath) {
|
||||
let result = "";
|
||||
let backtrack = "";
|
||||
let isSafeSegmentParam = true;
|
||||
for (const token of tokens) {
|
||||
if (token.type === "text") {
|
||||
result += escape(token.value);
|
||||
backtrack += token.value;
|
||||
isSafeSegmentParam || (isSafeSegmentParam = token.value.includes(delimiter));
|
||||
continue;
|
||||
}
|
||||
if (token.type === "param" || token.type === "wildcard") {
|
||||
if (!isSafeSegmentParam && !backtrack) {
|
||||
throw new PathError(`Missing text before "${token.name}" ${token.type}`, originalPath);
|
||||
}
|
||||
if (token.type === "param") {
|
||||
result += `(${negate(delimiter, isSafeSegmentParam ? "" : backtrack)}+)`;
|
||||
}
|
||||
else {
|
||||
result += `([\\s\\S]+)`;
|
||||
}
|
||||
keys.push(token);
|
||||
backtrack = "";
|
||||
isSafeSegmentParam = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Block backtracking on previous text and ignore delimiter string.
|
||||
*/
|
||||
function negate(delimiter, backtrack) {
|
||||
if (backtrack.length < 2) {
|
||||
if (delimiter.length < 2)
|
||||
return `[^${escape(delimiter + backtrack)}]`;
|
||||
return `(?:(?!${escape(delimiter)})[^${escape(backtrack)}])`;
|
||||
}
|
||||
if (delimiter.length < 2) {
|
||||
return `(?:(?!${escape(backtrack)})[^${escape(delimiter)}])`;
|
||||
}
|
||||
return `(?:(?!${escape(backtrack)}|${escape(delimiter)})[\\s\\S])`;
|
||||
}
|
||||
/**
|
||||
* Stringify an array of tokens into a path string.
|
||||
*/
|
||||
function stringifyTokens(tokens) {
|
||||
let value = "";
|
||||
let i = 0;
|
||||
function name(value) {
|
||||
const isSafe = isNameSafe(value) && isNextNameSafe(tokens[i]);
|
||||
return isSafe ? value : JSON.stringify(value);
|
||||
}
|
||||
while (i < tokens.length) {
|
||||
const token = tokens[i++];
|
||||
if (token.type === "text") {
|
||||
value += escapeText(token.value);
|
||||
continue;
|
||||
}
|
||||
if (token.type === "group") {
|
||||
value += `{${stringifyTokens(token.tokens)}}`;
|
||||
continue;
|
||||
}
|
||||
if (token.type === "param") {
|
||||
value += `:${name(token.name)}`;
|
||||
continue;
|
||||
}
|
||||
if (token.type === "wildcard") {
|
||||
value += `*${name(token.name)}`;
|
||||
continue;
|
||||
}
|
||||
throw new TypeError(`Unknown token type: ${token.type}`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
/**
|
||||
* Stringify token data into a path string.
|
||||
*/
|
||||
function stringify(data) {
|
||||
return stringifyTokens(data.tokens);
|
||||
}
|
||||
/**
|
||||
* Validate the parameter name contains valid ID characters.
|
||||
*/
|
||||
function isNameSafe(name) {
|
||||
const [first, ...rest] = name;
|
||||
return ID_START.test(first) && rest.every((char) => ID_CONTINUE.test(char));
|
||||
}
|
||||
/**
|
||||
* Validate the next token does not interfere with the current param name.
|
||||
*/
|
||||
function isNextNameSafe(token) {
|
||||
if (token && token.type === "text")
|
||||
return !ID_CONTINUE.test(token.value[0]);
|
||||
return true;
|
||||
}
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
datav/node_modules/path-to-regexp/dist/index.js.map
generated
vendored
Normal file
1
datav/node_modules/path-to-regexp/dist/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
64
datav/node_modules/path-to-regexp/package.json
generated
vendored
Normal file
64
datav/node_modules/path-to-regexp/package.json
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
{
|
||||
"name": "path-to-regexp",
|
||||
"version": "8.3.0",
|
||||
"description": "Express style path to RegExp utility",
|
||||
"keywords": [
|
||||
"express",
|
||||
"regexp",
|
||||
"route",
|
||||
"routing"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/pillarjs/path-to-regexp.git"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/express"
|
||||
},
|
||||
"license": "MIT",
|
||||
"exports": "./dist/index.js",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"files": [
|
||||
"dist/"
|
||||
],
|
||||
"scripts": {
|
||||
"bench": "vitest bench",
|
||||
"build": "ts-scripts build",
|
||||
"format": "ts-scripts format",
|
||||
"lint": "ts-scripts lint",
|
||||
"prepare": "ts-scripts install && npm run build",
|
||||
"size": "size-limit",
|
||||
"specs": "ts-scripts specs",
|
||||
"test": "ts-scripts test && npm run size"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@borderless/ts-scripts": "^0.15.0",
|
||||
"@size-limit/preset-small-lib": "^11.1.2",
|
||||
"@types/node": "^22.7.2",
|
||||
"@types/semver": "^7.3.1",
|
||||
"@vitest/coverage-v8": "^3.0.5",
|
||||
"recheck": "^4.4.5",
|
||||
"size-limit": "^11.1.2",
|
||||
"typescript": "^5.7.3",
|
||||
"vitest": "^3.0.5"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"size-limit": [
|
||||
{
|
||||
"path": "dist/index.js",
|
||||
"limit": "2 kB"
|
||||
}
|
||||
],
|
||||
"ts-scripts": {
|
||||
"dist": [
|
||||
"dist"
|
||||
],
|
||||
"project": [
|
||||
"tsconfig.build.json"
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user