fix: Switch to Tailwind v3 - v4 incompatible with Astro
This commit is contained in:
21
node_modules/path-to-regexp/LICENSE
generated
vendored
Normal file
21
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.
|
||||
261
node_modules/path-to-regexp/Readme.md
generated
vendored
Normal file
261
node_modules/path-to-regexp/Readme.md
generated
vendored
Normal file
@@ -0,0 +1,261 @@
|
||||
# Path-to-RegExp
|
||||
|
||||
> Turn a path string such as `/user/:name` into a regular expression.
|
||||
|
||||
[![NPM version][npm-image]][npm-url]
|
||||
[![Build status][travis-image]][travis-url]
|
||||
[![Test coverage][coveralls-image]][coveralls-url]
|
||||
[![Dependency Status][david-image]][david-url]
|
||||
[![License][license-image]][license-url]
|
||||
[![Downloads][downloads-image]][downloads-url]
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
npm install path-to-regexp --save
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```javascript
|
||||
const pathToRegexp = require('path-to-regexp')
|
||||
|
||||
// pathToRegexp(path, keys?, options?)
|
||||
// pathToRegexp.match(path)
|
||||
// pathToRegexp.parse(path)
|
||||
// pathToRegexp.compile(path)
|
||||
```
|
||||
|
||||
- **path** A string, array of strings, or a regular expression.
|
||||
- **keys** An array to populate with keys found in the path.
|
||||
- **options**
|
||||
- **sensitive** When `true` the regexp will be case sensitive. (default: `false`)
|
||||
- **strict** When `true` the regexp allows an optional trailing delimiter to match. (default: `false`)
|
||||
- **end** When `true` the regexp will match to the end of the string. (default: `true`)
|
||||
- **start** When `true` the regexp will match from the beginning of the string. (default: `true`)
|
||||
- **delimiter** The default delimiter for segments. (default: `'/'`)
|
||||
- **endsWith** Optional character, or list of characters, to treat as "end" characters.
|
||||
- **whitelist** List of characters to consider delimiters when parsing. (default: `undefined`, any character)
|
||||
|
||||
```javascript
|
||||
const keys = []
|
||||
const regexp = pathToRegexp('/foo/:bar', keys)
|
||||
// regexp = /^\/foo\/([^\/]+?)\/?$/i
|
||||
// keys = [{ name: 'bar', prefix: '/', delimiter: '/', optional: false, repeat: false, pattern: '[^\\/]+?' }]
|
||||
```
|
||||
|
||||
**Please note:** The `RegExp` returned by `path-to-regexp` is intended for ordered data (e.g. pathnames, hostnames). It can not handle arbitrarily ordered data (e.g. query strings, URL fragments, JSON, etc).
|
||||
|
||||
### Parameters
|
||||
|
||||
The path argument is used to define parameters and populate the list of keys.
|
||||
|
||||
#### Named Parameters
|
||||
|
||||
Named parameters are defined by prefixing a colon to the parameter name (`:foo`). By default, the parameter will match until the next prefix (e.g. `[^/]+`).
|
||||
|
||||
```js
|
||||
const regexp = pathToRegexp('/:foo/:bar')
|
||||
// keys = [{ name: 'foo', prefix: '/', ... }, { name: 'bar', prefix: '/', ... }]
|
||||
|
||||
regexp.exec('/test/route')
|
||||
//=> [ '/test/route', 'test', 'route', index: 0, input: '/test/route', groups: undefined ]
|
||||
```
|
||||
|
||||
**Please note:** Parameter names must use "word characters" (`[A-Za-z0-9_]`).
|
||||
|
||||
#### Parameter Modifiers
|
||||
|
||||
##### Optional
|
||||
|
||||
Parameters can be suffixed with a question mark (`?`) to make the parameter optional.
|
||||
|
||||
```js
|
||||
const regexp = pathToRegexp('/:foo/:bar?')
|
||||
// keys = [{ name: 'foo', ... }, { name: 'bar', delimiter: '/', optional: true, repeat: false }]
|
||||
|
||||
regexp.exec('/test')
|
||||
//=> [ '/test', 'test', undefined, index: 0, input: '/test', groups: undefined ]
|
||||
|
||||
regexp.exec('/test/route')
|
||||
//=> [ '/test/route', 'test', 'route', index: 0, input: '/test/route', groups: undefined ]
|
||||
```
|
||||
|
||||
**Tip:** The prefix is also optional, escape the prefix `\/` to make it required.
|
||||
|
||||
##### Zero or more
|
||||
|
||||
Parameters can be suffixed with an asterisk (`*`) to denote a zero or more parameter matches. The prefix is used for each match.
|
||||
|
||||
```js
|
||||
const regexp = pathToRegexp('/:foo*')
|
||||
// keys = [{ name: 'foo', delimiter: '/', optional: true, repeat: true }]
|
||||
|
||||
regexp.exec('/')
|
||||
//=> [ '/', undefined, index: 0, input: '/', groups: undefined ]
|
||||
|
||||
regexp.exec('/bar/baz')
|
||||
//=> [ '/bar/baz', 'bar/baz', index: 0, input: '/bar/baz', groups: undefined ]
|
||||
```
|
||||
|
||||
##### One or more
|
||||
|
||||
Parameters can be suffixed with a plus sign (`+`) to denote a one or more parameter matches. The prefix is used for each match.
|
||||
|
||||
```js
|
||||
const regexp = pathToRegexp('/:foo+')
|
||||
// keys = [{ name: 'foo', delimiter: '/', optional: false, repeat: true }]
|
||||
|
||||
regexp.exec('/')
|
||||
//=> null
|
||||
|
||||
regexp.exec('/bar/baz')
|
||||
//=> [ '/bar/baz','bar/baz', index: 0, input: '/bar/baz', groups: undefined ]
|
||||
```
|
||||
|
||||
#### Unnamed Parameters
|
||||
|
||||
It is possible to write an unnamed parameter that only consists of a matching group. It works the same as a named parameter, except it will be numerically indexed.
|
||||
|
||||
```js
|
||||
const regexp = pathToRegexp('/:foo/(.*)')
|
||||
// keys = [{ name: 'foo', ... }, { name: 0, ... }]
|
||||
|
||||
regexp.exec('/test/route')
|
||||
//=> [ '/test/route', 'test', 'route', index: 0, input: '/test/route', groups: undefined ]
|
||||
```
|
||||
|
||||
#### Custom Matching Parameters
|
||||
|
||||
All parameters can have a custom regexp, which overrides the default match (`[^/]+`). For example, you can match digits or names in a path:
|
||||
|
||||
```js
|
||||
const regexpNumbers = pathToRegexp('/icon-:foo(\\d+).png')
|
||||
// keys = [{ name: 'foo', ... }]
|
||||
|
||||
regexpNumbers.exec('/icon-123.png')
|
||||
//=> ['/icon-123.png', '123']
|
||||
|
||||
regexpNumbers.exec('/icon-abc.png')
|
||||
//=> null
|
||||
|
||||
const regexpWord = pathToRegexp('/(user|u)')
|
||||
// keys = [{ name: 0, ... }]
|
||||
|
||||
regexpWord.exec('/u')
|
||||
//=> ['/u', 'u']
|
||||
|
||||
regexpWord.exec('/users')
|
||||
//=> null
|
||||
```
|
||||
|
||||
**Tip:** Backslashes need to be escaped with another backslash in JavaScript strings.
|
||||
|
||||
### Match
|
||||
|
||||
The `match` function will return a function for transforming paths into parameters:
|
||||
|
||||
```js
|
||||
const match = pathToRegexp.match('/user/:id')
|
||||
|
||||
match('/user/123') //=> { path: '/user/123', index: 0, params: { id: '123' } }
|
||||
match('/invalid') //=> false
|
||||
```
|
||||
|
||||
### Parse
|
||||
|
||||
The `parse` function will return a list of strings and keys from a path string:
|
||||
|
||||
```js
|
||||
const tokens = pathToRegexp.parse('/route/:foo/(.*)')
|
||||
|
||||
console.log(tokens[0])
|
||||
//=> "/route"
|
||||
|
||||
console.log(tokens[1])
|
||||
//=> { name: 'foo', prefix: '/', delimiter: '/', optional: false, repeat: false, pattern: '[^\\/]+?' }
|
||||
|
||||
console.log(tokens[2])
|
||||
//=> { name: 0, prefix: '/', delimiter: '/', optional: false, repeat: false, pattern: '.*' }
|
||||
```
|
||||
|
||||
**Note:** This method only works with strings.
|
||||
|
||||
### Compile ("Reverse" Path-To-RegExp)
|
||||
|
||||
The `compile` function will return a function for transforming parameters into a valid path:
|
||||
|
||||
```js
|
||||
const toPath = pathToRegexp.compile('/user/:id')
|
||||
|
||||
toPath({ id: 123 }) //=> "/user/123"
|
||||
toPath({ id: 'café' }) //=> "/user/caf%C3%A9"
|
||||
toPath({ id: '/' }) //=> "/user/%2F"
|
||||
|
||||
toPath({ id: ':/' }) //=> "/user/%3A%2F"
|
||||
toPath({ id: ':/' }, { encode: (value, token) => value, validate: false }) //=> "/user/:/"
|
||||
|
||||
const toPathRepeated = pathToRegexp.compile('/:segment+')
|
||||
|
||||
toPathRepeated({ segment: 'foo' }) //=> "/foo"
|
||||
toPathRepeated({ segment: ['a', 'b', 'c'] }) //=> "/a/b/c"
|
||||
|
||||
const toPathRegexp = pathToRegexp.compile('/user/:id(\\d+)')
|
||||
|
||||
toPathRegexp({ id: 123 }) //=> "/user/123"
|
||||
toPathRegexp({ id: '123' }) //=> "/user/123"
|
||||
toPathRegexp({ id: 'abc' }) //=> Throws `TypeError`.
|
||||
toPathRegexp({ id: 'abc' }, { validate: false }) //=> "/user/abc"
|
||||
```
|
||||
|
||||
**Note:** The generated function will throw on invalid input. It will do all necessary checks to ensure the generated path is valid. This method only works with strings.
|
||||
|
||||
### Working with Tokens
|
||||
|
||||
Path-To-RegExp exposes the two functions used internally that accept an array of tokens.
|
||||
|
||||
* `pathToRegexp.tokensToRegExp(tokens, keys?, options?)` Transform an array of tokens into a matching regular expression.
|
||||
* `pathToRegexp.tokensToFunction(tokens)` Transform an array of tokens into a path generator function.
|
||||
|
||||
#### Token Information
|
||||
|
||||
* `name` The name of the token (`string` for named or `number` for index)
|
||||
* `prefix` The prefix character for the segment (e.g. `/`)
|
||||
* `delimiter` The delimiter for the segment (same as prefix or default delimiter)
|
||||
* `optional` Indicates the token is optional (`boolean`)
|
||||
* `repeat` Indicates the token is repeated (`boolean`)
|
||||
* `pattern` The RegExp used to match this token (`string`)
|
||||
|
||||
## Compatibility with Express <= 4.x
|
||||
|
||||
Path-To-RegExp breaks compatibility with Express <= `4.x`:
|
||||
|
||||
* RegExp special characters can only be used in a parameter
|
||||
* Express.js 4.x used all `RegExp` special characters regardless of position - this considered a bug
|
||||
* Parameters have suffixes that augment meaning - `*`, `+` and `?`. E.g. `/:user*`
|
||||
* No wildcard asterisk (`*`) - use parameters instead (`(.*)`)
|
||||
|
||||
## TypeScript
|
||||
|
||||
Includes a [`.d.ts`](index.d.ts) file for TypeScript users.
|
||||
|
||||
## Live Demo
|
||||
|
||||
You can see a live demo of this library in use at [express-route-tester](http://forbeslindesay.github.com/express-route-tester/).
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
[npm-image]: https://img.shields.io/npm/v/path-to-regexp.svg?style=flat
|
||||
[npm-url]: https://npmjs.org/package/path-to-regexp
|
||||
[travis-image]: https://img.shields.io/travis/pillarjs/path-to-regexp.svg?style=flat
|
||||
[travis-url]: https://travis-ci.org/pillarjs/path-to-regexp
|
||||
[coveralls-image]: https://img.shields.io/coveralls/pillarjs/path-to-regexp.svg?style=flat
|
||||
[coveralls-url]: https://coveralls.io/r/pillarjs/path-to-regexp?branch=master
|
||||
[david-image]: http://img.shields.io/david/pillarjs/path-to-regexp.svg?style=flat
|
||||
[david-url]: https://david-dm.org/pillarjs/path-to-regexp
|
||||
[license-image]: http://img.shields.io/npm/l/path-to-regexp.svg?style=flat
|
||||
[license-url]: LICENSE.md
|
||||
[downloads-image]: http://img.shields.io/npm/dm/path-to-regexp.svg?style=flat
|
||||
[downloads-url]: https://npmjs.org/package/path-to-regexp
|
||||
120
node_modules/path-to-regexp/index.d.ts
generated
vendored
Normal file
120
node_modules/path-to-regexp/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
declare function pathToRegexp (path: pathToRegexp.Path, keys?: pathToRegexp.Key[], options?: pathToRegexp.RegExpOptions & pathToRegexp.ParseOptions): RegExp;
|
||||
|
||||
declare namespace pathToRegexp {
|
||||
export interface RegExpOptions {
|
||||
/**
|
||||
* When `true` the regexp will be case sensitive. (default: `false`)
|
||||
*/
|
||||
sensitive?: boolean;
|
||||
/**
|
||||
* When `true` the regexp allows an optional trailing delimiter to match. (default: `false`)
|
||||
*/
|
||||
strict?: boolean;
|
||||
/**
|
||||
* When `true` the regexp will match to the end of the string. (default: `true`)
|
||||
*/
|
||||
end?: boolean;
|
||||
/**
|
||||
* When `true` the regexp will match from the beginning of the string. (default: `true`)
|
||||
*/
|
||||
start?: boolean;
|
||||
/**
|
||||
* Sets the final character for non-ending optimistic matches. (default: `/`)
|
||||
*/
|
||||
delimiter?: string;
|
||||
/**
|
||||
* List of characters that can also be "end" characters.
|
||||
*/
|
||||
endsWith?: string | string[];
|
||||
/**
|
||||
* List of characters to consider delimiters when parsing. (default: `undefined`, any character)
|
||||
*/
|
||||
whitelist?: string | string[];
|
||||
}
|
||||
|
||||
export interface ParseOptions {
|
||||
/**
|
||||
* Set the default delimiter for repeat parameters. (default: `'/'`)
|
||||
*/
|
||||
delimiter?: string;
|
||||
}
|
||||
|
||||
export interface TokensToFunctionOptions {
|
||||
/**
|
||||
* When `true` the regexp will be case sensitive. (default: `false`)
|
||||
*/
|
||||
sensitive?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an Express-style path into an array of tokens.
|
||||
*/
|
||||
export function parse (path: string, options?: ParseOptions): Token[];
|
||||
|
||||
/**
|
||||
* Create path match function from `path-to-regexp` spec.
|
||||
*/
|
||||
export function match <P extends object = object> (path: string, options?: ParseOptions): MatchFunction<P>;
|
||||
|
||||
/**
|
||||
* Create a path match function from `path-to-regexp` output.
|
||||
*/
|
||||
export function regexpToFunction <P extends object = object> (re: RegExp, keys: Key[]): MatchFunction<P>;
|
||||
|
||||
/**
|
||||
* Transforming an Express-style path into a valid path.
|
||||
*/
|
||||
export function compile <P extends object = object> (path: string, options?: ParseOptions & TokensToFunctionOptions): PathFunction<P>;
|
||||
|
||||
/**
|
||||
* Transform an array of tokens into a path generator function.
|
||||
*/
|
||||
export function tokensToFunction <P extends object = object> (tokens: Token[], options?: TokensToFunctionOptions): PathFunction<P>;
|
||||
|
||||
/**
|
||||
* Transform an array of tokens into a matching regular expression.
|
||||
*/
|
||||
export function tokensToRegExp (tokens: Token[], keys?: Key[], options?: RegExpOptions): RegExp;
|
||||
|
||||
export interface Key {
|
||||
name: string | number;
|
||||
prefix: string;
|
||||
delimiter: string;
|
||||
optional: boolean;
|
||||
repeat: boolean;
|
||||
pattern: string;
|
||||
}
|
||||
|
||||
interface PathFunctionOptions {
|
||||
/**
|
||||
* Function for encoding input strings for output.
|
||||
*/
|
||||
encode?: (value: string, token: Key) => string;
|
||||
/**
|
||||
* When `false` the function can produce an invalid (unmatched) path. (default: `true`)
|
||||
*/
|
||||
validate?: boolean;
|
||||
}
|
||||
|
||||
interface MatchFunctionOptions {
|
||||
/**
|
||||
* Function for decoding strings for params.
|
||||
*/
|
||||
decode?: (value: string, token: Key) => string;
|
||||
}
|
||||
|
||||
interface MatchResult <P extends object = object> {
|
||||
path: string;
|
||||
index: number;
|
||||
params: P;
|
||||
}
|
||||
|
||||
type Match <P extends object = object> = false | MatchResult<P>;
|
||||
|
||||
export type Token = string | Key;
|
||||
export type Path = string | RegExp | Array<string | RegExp>;
|
||||
export type PathFunction <P extends object = object> = (data?: P, options?: PathFunctionOptions) => string;
|
||||
export type MatchFunction <P extends object = object> = (path: string, options?: MatchFunctionOptions) => Match<P>;
|
||||
}
|
||||
|
||||
export = pathToRegexp;
|
||||
421
node_modules/path-to-regexp/index.js
generated
vendored
Normal file
421
node_modules/path-to-regexp/index.js
generated
vendored
Normal file
@@ -0,0 +1,421 @@
|
||||
/**
|
||||
* Expose `pathToRegexp`.
|
||||
*/
|
||||
module.exports = pathToRegexp
|
||||
module.exports.match = match
|
||||
module.exports.regexpToFunction = regexpToFunction
|
||||
module.exports.parse = parse
|
||||
module.exports.compile = compile
|
||||
module.exports.tokensToFunction = tokensToFunction
|
||||
module.exports.tokensToRegExp = tokensToRegExp
|
||||
|
||||
/**
|
||||
* Default configs.
|
||||
*/
|
||||
var DEFAULT_DELIMITER = '/'
|
||||
|
||||
/**
|
||||
* The main path matching regexp utility.
|
||||
*
|
||||
* @type {RegExp}
|
||||
*/
|
||||
var PATH_REGEXP = new RegExp([
|
||||
// Match escaped characters that would otherwise appear in future matches.
|
||||
// This allows the user to escape special characters that won't transform.
|
||||
'(\\\\.)',
|
||||
// Match Express-style parameters and un-named parameters with a prefix
|
||||
// and optional suffixes. Matches appear as:
|
||||
//
|
||||
// ":test(\\d+)?" => ["test", "\d+", undefined, "?"]
|
||||
// "(\\d+)" => [undefined, undefined, "\d+", undefined]
|
||||
'(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?'
|
||||
].join('|'), 'g')
|
||||
|
||||
/**
|
||||
* Parse a string for the raw tokens.
|
||||
*
|
||||
* @param {string} str
|
||||
* @param {Object=} options
|
||||
* @return {!Array}
|
||||
*/
|
||||
function parse (str, options) {
|
||||
var tokens = []
|
||||
var key = 0
|
||||
var index = 0
|
||||
var path = ''
|
||||
var defaultDelimiter = (options && options.delimiter) || DEFAULT_DELIMITER
|
||||
var whitelist = (options && options.whitelist) || undefined
|
||||
var pathEscaped = false
|
||||
var res
|
||||
|
||||
while ((res = PATH_REGEXP.exec(str)) !== null) {
|
||||
var m = res[0]
|
||||
var escaped = res[1]
|
||||
var offset = res.index
|
||||
path += str.slice(index, offset)
|
||||
index = offset + m.length
|
||||
|
||||
// Ignore already escaped sequences.
|
||||
if (escaped) {
|
||||
path += escaped[1]
|
||||
pathEscaped = true
|
||||
continue
|
||||
}
|
||||
|
||||
var prev = ''
|
||||
var name = res[2]
|
||||
var capture = res[3]
|
||||
var group = res[4]
|
||||
var modifier = res[5]
|
||||
|
||||
if (!pathEscaped && path.length) {
|
||||
var k = path.length - 1
|
||||
var c = path[k]
|
||||
var matches = whitelist ? whitelist.indexOf(c) > -1 : true
|
||||
|
||||
if (matches) {
|
||||
prev = c
|
||||
path = path.slice(0, k)
|
||||
}
|
||||
}
|
||||
|
||||
// Push the current path onto the tokens.
|
||||
if (path) {
|
||||
tokens.push(path)
|
||||
path = ''
|
||||
pathEscaped = false
|
||||
}
|
||||
|
||||
var repeat = modifier === '+' || modifier === '*'
|
||||
var optional = modifier === '?' || modifier === '*'
|
||||
var pattern = capture || group
|
||||
var delimiter = prev || defaultDelimiter
|
||||
var prevText = prev || (typeof tokens[tokens.length - 1] === 'string' ? tokens[tokens.length - 1] : '')
|
||||
|
||||
tokens.push({
|
||||
name: name || key++,
|
||||
prefix: prev,
|
||||
delimiter: delimiter,
|
||||
optional: optional,
|
||||
repeat: repeat,
|
||||
pattern: pattern
|
||||
? escapeGroup(pattern)
|
||||
: restrictBacktrack(delimiter, defaultDelimiter, prevText)
|
||||
})
|
||||
}
|
||||
|
||||
// Push any remaining characters.
|
||||
if (path || index < str.length) {
|
||||
tokens.push(path + str.substr(index))
|
||||
}
|
||||
|
||||
return tokens
|
||||
}
|
||||
|
||||
function restrictBacktrack (delimiter, defaultDelimiter, prevText) {
|
||||
var charGroup = '[^' + escapeString(delimiter === defaultDelimiter ? delimiter : (delimiter + defaultDelimiter)) + ']'
|
||||
|
||||
if (!prevText || prevText.indexOf(delimiter) > -1 || prevText.indexOf(defaultDelimiter) > -1) {
|
||||
return charGroup + '+?'
|
||||
}
|
||||
|
||||
return escapeString(prevText) + '|(?:(?!' + escapeString(prevText) + ')' + charGroup + ')+?'
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a string to a template function for the path.
|
||||
*
|
||||
* @param {string} str
|
||||
* @param {Object=} options
|
||||
* @return {!function(Object=, Object=)}
|
||||
*/
|
||||
function compile (str, options) {
|
||||
return tokensToFunction(parse(str, options), options)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create path match function from `path-to-regexp` spec.
|
||||
*/
|
||||
function match (str, options) {
|
||||
var keys = []
|
||||
var re = pathToRegexp(str, keys, options)
|
||||
return regexpToFunction(re, keys)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a path match function from `path-to-regexp` output.
|
||||
*/
|
||||
function regexpToFunction (re, keys) {
|
||||
return function (pathname, options) {
|
||||
var m = re.exec(pathname)
|
||||
if (!m) return false
|
||||
|
||||
var path = m[0]
|
||||
var index = m.index
|
||||
var params = {}
|
||||
var decode = (options && options.decode) || decodeURIComponent
|
||||
|
||||
for (var i = 1; i < m.length; i++) {
|
||||
if (m[i] === undefined) continue
|
||||
|
||||
var key = keys[i - 1]
|
||||
|
||||
if (key.repeat) {
|
||||
params[key.name] = m[i].split(key.delimiter).map(function (value) {
|
||||
return decode(value, key)
|
||||
})
|
||||
} else {
|
||||
params[key.name] = decode(m[i], key)
|
||||
}
|
||||
}
|
||||
|
||||
return { path: path, index: index, params: params }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose a method for transforming tokens into the path function.
|
||||
*/
|
||||
function tokensToFunction (tokens, options) {
|
||||
// Compile all the tokens into regexps.
|
||||
var matches = new Array(tokens.length)
|
||||
|
||||
// Compile all the patterns before compilation.
|
||||
for (var i = 0; i < tokens.length; i++) {
|
||||
if (typeof tokens[i] === 'object') {
|
||||
matches[i] = new RegExp('^(?:' + tokens[i].pattern + ')$', flags(options))
|
||||
}
|
||||
}
|
||||
|
||||
return function (data, options) {
|
||||
var path = ''
|
||||
var encode = (options && options.encode) || encodeURIComponent
|
||||
var validate = options ? options.validate !== false : true
|
||||
|
||||
for (var i = 0; i < tokens.length; i++) {
|
||||
var token = tokens[i]
|
||||
|
||||
if (typeof token === 'string') {
|
||||
path += token
|
||||
continue
|
||||
}
|
||||
|
||||
var value = data ? data[token.name] : undefined
|
||||
var segment
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
if (!token.repeat) {
|
||||
throw new TypeError('Expected "' + token.name + '" to not repeat, but got array')
|
||||
}
|
||||
|
||||
if (value.length === 0) {
|
||||
if (token.optional) continue
|
||||
|
||||
throw new TypeError('Expected "' + token.name + '" to not be empty')
|
||||
}
|
||||
|
||||
for (var j = 0; j < value.length; j++) {
|
||||
segment = encode(value[j], token)
|
||||
|
||||
if (validate && !matches[i].test(segment)) {
|
||||
throw new TypeError('Expected all "' + token.name + '" to match "' + token.pattern + '"')
|
||||
}
|
||||
|
||||
path += (j === 0 ? token.prefix : token.delimiter) + segment
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
||||
segment = encode(String(value), token)
|
||||
|
||||
if (validate && !matches[i].test(segment)) {
|
||||
throw new TypeError('Expected "' + token.name + '" to match "' + token.pattern + '", but got "' + segment + '"')
|
||||
}
|
||||
|
||||
path += token.prefix + segment
|
||||
continue
|
||||
}
|
||||
|
||||
if (token.optional) continue
|
||||
|
||||
throw new TypeError('Expected "' + token.name + '" to be ' + (token.repeat ? 'an array' : 'a string'))
|
||||
}
|
||||
|
||||
return path
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape a regular expression string.
|
||||
*
|
||||
* @param {string} str
|
||||
* @return {string}
|
||||
*/
|
||||
function escapeString (str) {
|
||||
return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, '\\$1')
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape the capturing group by escaping special characters and meaning.
|
||||
*
|
||||
* @param {string} group
|
||||
* @return {string}
|
||||
*/
|
||||
function escapeGroup (group) {
|
||||
return group.replace(/([=!:$/()])/g, '\\$1')
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the flags for a regexp from the options.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @return {string}
|
||||
*/
|
||||
function flags (options) {
|
||||
return options && options.sensitive ? '' : 'i'
|
||||
}
|
||||
|
||||
/**
|
||||
* Pull out keys from a regexp.
|
||||
*
|
||||
* @param {!RegExp} path
|
||||
* @param {Array=} keys
|
||||
* @return {!RegExp}
|
||||
*/
|
||||
function regexpToRegexp (path, keys) {
|
||||
if (!keys) return path
|
||||
|
||||
// Use a negative lookahead to match only capturing groups.
|
||||
var groups = path.source.match(/\((?!\?)/g)
|
||||
|
||||
if (groups) {
|
||||
for (var i = 0; i < groups.length; i++) {
|
||||
keys.push({
|
||||
name: i,
|
||||
prefix: null,
|
||||
delimiter: null,
|
||||
optional: false,
|
||||
repeat: false,
|
||||
pattern: null
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return path
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform an array into a regexp.
|
||||
*
|
||||
* @param {!Array} path
|
||||
* @param {Array=} keys
|
||||
* @param {Object=} options
|
||||
* @return {!RegExp}
|
||||
*/
|
||||
function arrayToRegexp (path, keys, options) {
|
||||
var parts = []
|
||||
|
||||
for (var i = 0; i < path.length; i++) {
|
||||
parts.push(pathToRegexp(path[i], keys, options).source)
|
||||
}
|
||||
|
||||
return new RegExp('(?:' + parts.join('|') + ')', flags(options))
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a path regexp from string input.
|
||||
*
|
||||
* @param {string} path
|
||||
* @param {Array=} keys
|
||||
* @param {Object=} options
|
||||
* @return {!RegExp}
|
||||
*/
|
||||
function stringToRegexp (path, keys, options) {
|
||||
return tokensToRegExp(parse(path, options), keys, options)
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose a function for taking tokens and returning a RegExp.
|
||||
*
|
||||
* @param {!Array} tokens
|
||||
* @param {Array=} keys
|
||||
* @param {Object=} options
|
||||
* @return {!RegExp}
|
||||
*/
|
||||
function tokensToRegExp (tokens, keys, options) {
|
||||
options = options || {}
|
||||
|
||||
var strict = options.strict
|
||||
var start = options.start !== false
|
||||
var end = options.end !== false
|
||||
var delimiter = options.delimiter || DEFAULT_DELIMITER
|
||||
var endsWith = [].concat(options.endsWith || []).map(escapeString).concat('$').join('|')
|
||||
var route = start ? '^' : ''
|
||||
|
||||
// Iterate over the tokens and create our regexp string.
|
||||
for (var i = 0; i < tokens.length; i++) {
|
||||
var token = tokens[i]
|
||||
|
||||
if (typeof token === 'string') {
|
||||
route += escapeString(token)
|
||||
} else {
|
||||
var capture = token.repeat
|
||||
? '(?:' + token.pattern + ')(?:' + escapeString(token.delimiter) + '(?:' + token.pattern + '))*'
|
||||
: token.pattern
|
||||
|
||||
if (keys) keys.push(token)
|
||||
|
||||
if (token.optional) {
|
||||
if (!token.prefix) {
|
||||
route += '(' + capture + ')?'
|
||||
} else {
|
||||
route += '(?:' + escapeString(token.prefix) + '(' + capture + '))?'
|
||||
}
|
||||
} else {
|
||||
route += escapeString(token.prefix) + '(' + capture + ')'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (end) {
|
||||
if (!strict) route += '(?:' + escapeString(delimiter) + ')?'
|
||||
|
||||
route += endsWith === '$' ? '$' : '(?=' + endsWith + ')'
|
||||
} else {
|
||||
var endToken = tokens[tokens.length - 1]
|
||||
var isEndDelimited = typeof endToken === 'string'
|
||||
? endToken[endToken.length - 1] === delimiter
|
||||
: endToken === undefined
|
||||
|
||||
if (!strict) route += '(?:' + escapeString(delimiter) + '(?=' + endsWith + '))?'
|
||||
if (!isEndDelimited) route += '(?=' + escapeString(delimiter) + '|' + endsWith + ')'
|
||||
}
|
||||
|
||||
return new RegExp(route, flags(options))
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize the given path string, returning a regular expression.
|
||||
*
|
||||
* An empty array can be passed in for the keys, which will hold the
|
||||
* placeholder key descriptions. For example, using `/user/:id`, `keys` will
|
||||
* contain `[{ name: 'id', delimiter: '/', optional: false, repeat: false }]`.
|
||||
*
|
||||
* @param {(string|RegExp|Array)} path
|
||||
* @param {Array=} keys
|
||||
* @param {Object=} options
|
||||
* @return {!RegExp}
|
||||
*/
|
||||
function pathToRegexp (path, keys, options) {
|
||||
if (path instanceof RegExp) {
|
||||
return regexpToRegexp(path, keys)
|
||||
}
|
||||
|
||||
if (Array.isArray(path)) {
|
||||
return arrayToRegexp(/** @type {!Array} */ (path), keys, options)
|
||||
}
|
||||
|
||||
return stringToRegexp(/** @type {string} */ (path), keys, options)
|
||||
}
|
||||
46
node_modules/path-to-regexp/package.json
generated
vendored
Normal file
46
node_modules/path-to-regexp/package.json
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"name": "path-to-regexp",
|
||||
"description": "Express style path to RegExp utility",
|
||||
"version": "3.3.0",
|
||||
"main": "index.js",
|
||||
"typings": "index.d.ts",
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts",
|
||||
"LICENSE"
|
||||
],
|
||||
"scripts": {
|
||||
"lint": "standard",
|
||||
"test-spec": "mocha --require ts-node/register -R spec --bail test.ts",
|
||||
"test-cov": "nyc --reporter=lcov mocha -- --require ts-node/register -R spec test.ts",
|
||||
"coverage": "nyc report --reporter=text-lcov",
|
||||
"test": "npm run lint && npm run test-cov"
|
||||
},
|
||||
"keywords": [
|
||||
"express",
|
||||
"regexp",
|
||||
"route",
|
||||
"routing"
|
||||
],
|
||||
"component": {
|
||||
"scripts": {
|
||||
"path-to-regexp": "index.js"
|
||||
}
|
||||
},
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/pillarjs/path-to-regexp.git"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chai": "^4.0.4",
|
||||
"@types/mocha": "^5.2.5",
|
||||
"@types/node": "^12.7.3",
|
||||
"chai": "^4.1.1",
|
||||
"mocha": "^6.2.0",
|
||||
"nyc": "^14.1.1",
|
||||
"standard": "^14.1.0",
|
||||
"ts-node": "^8.3.0",
|
||||
"typescript": "^3.7.2"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user