mirror of
https://github.com/arnaucube/socketioMEANseed.git
synced 2026-02-07 19:56:46 +01:00
init
This commit is contained in:
2
server/node_modules/path-to-regexp/.npmignore
generated
vendored
Normal file
2
server/node_modules/path-to-regexp/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
node_modules
|
||||
coverage
|
||||
16
server/node_modules/path-to-regexp/History.md
generated
vendored
Normal file
16
server/node_modules/path-to-regexp/History.md
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
0.1.3 / 2014-07-06
|
||||
==================
|
||||
|
||||
* Better array support
|
||||
* Improved support for trailing slash in non-ending mode
|
||||
|
||||
0.1.0 / 2014-03-06
|
||||
==================
|
||||
|
||||
* add options.end
|
||||
|
||||
0.0.2 / 2013-02-10
|
||||
==================
|
||||
|
||||
* Update to match current express
|
||||
* add .license property to component.json
|
||||
33
server/node_modules/path-to-regexp/Readme.md
generated
vendored
Normal file
33
server/node_modules/path-to-regexp/Readme.md
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
# Path-to-RegExp
|
||||
|
||||
Turn an Express-style path string such as `/user/:name` into a regular expression.
|
||||
|
||||
## Usage
|
||||
|
||||
```javascript
|
||||
var pathToRegexp = require('path-to-regexp');
|
||||
```
|
||||
### pathToRegexp(path, keys, options)
|
||||
|
||||
- **path** A string in the express format, an array of such strings, or a regular expression
|
||||
- **keys** An array to be populated with the keys present in the url. Once the function completes, this will be an array of strings.
|
||||
- **options**
|
||||
- **options.sensitive** Defaults to false, set this to true to make routes case sensitive
|
||||
- **options.strict** Defaults to false, set this to true to make the trailing slash matter.
|
||||
- **options.end** Defaults to true, set this to false to only match the prefix of the URL.
|
||||
|
||||
```javascript
|
||||
var keys = [];
|
||||
var exp = pathToRegexp('/foo/:bar', keys);
|
||||
//keys = ['bar']
|
||||
//exp = /^\/foo\/(?:([^\/]+?))\/?$/i
|
||||
```
|
||||
|
||||
## 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
|
||||
15
server/node_modules/path-to-regexp/component.json
generated
vendored
Normal file
15
server/node_modules/path-to-regexp/component.json
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "path-to-regexp",
|
||||
"description": "Express style path to RegExp utility",
|
||||
"version": "0.1.3",
|
||||
"keywords": [
|
||||
"express",
|
||||
"regexp",
|
||||
"route",
|
||||
"routing"
|
||||
],
|
||||
"scripts": [
|
||||
"index.js"
|
||||
],
|
||||
"license": "MIT"
|
||||
}
|
||||
70
server/node_modules/path-to-regexp/index.js
generated
vendored
Normal file
70
server/node_modules/path-to-regexp/index.js
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* Expose `pathtoRegexp`.
|
||||
*/
|
||||
|
||||
module.exports = pathtoRegexp;
|
||||
|
||||
/**
|
||||
* Normalize the given path string,
|
||||
* returning a regular expression.
|
||||
*
|
||||
* An empty array should be passed,
|
||||
* which will contain the placeholder
|
||||
* key names. For example "/user/:id" will
|
||||
* then contain ["id"].
|
||||
*
|
||||
* @param {String|RegExp|Array} path
|
||||
* @param {Array} keys
|
||||
* @param {Object} options
|
||||
* @return {RegExp}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function pathtoRegexp(path, keys, options) {
|
||||
options = options || {};
|
||||
var strict = options.strict;
|
||||
var end = options.end !== false;
|
||||
var flags = options.sensitive ? '' : 'i';
|
||||
keys = keys || [];
|
||||
|
||||
if (path instanceof RegExp) {
|
||||
return path;
|
||||
}
|
||||
|
||||
if (Array.isArray(path)) {
|
||||
// Map array parts into regexps and return their source. We also pass
|
||||
// the same keys and options instance into every generation to get
|
||||
// consistent matching groups before we join the sources together.
|
||||
path = path.map(function (value) {
|
||||
return pathtoRegexp(value, keys, options).source;
|
||||
});
|
||||
|
||||
return new RegExp('(?:' + path.join('|') + ')', flags);
|
||||
}
|
||||
|
||||
path = ('^' + path + (strict ? '' : path[path.length - 1] === '/' ? '?' : '/?'))
|
||||
.replace(/\/\(/g, '/(?:')
|
||||
.replace(/([\/\.])/g, '\\$1')
|
||||
.replace(/(\\\/)?(\\\.)?:(\w+)(\(.*?\))?(\*)?(\?)?/g, function (match, slash, format, key, capture, star, optional) {
|
||||
slash = slash || '';
|
||||
format = format || '';
|
||||
capture = capture || '([^\\/' + format + ']+?)';
|
||||
optional = optional || '';
|
||||
|
||||
keys.push({ name: key, optional: !!optional });
|
||||
|
||||
return ''
|
||||
+ (optional ? '' : slash)
|
||||
+ '(?:'
|
||||
+ format + (optional ? slash : '') + capture
|
||||
+ (star ? '((?:[\\/' + format + '].+?)?)' : '')
|
||||
+ ')'
|
||||
+ optional;
|
||||
})
|
||||
.replace(/\*/g, '(.*)');
|
||||
|
||||
// If the path is non-ending, match until the end or a slash.
|
||||
path += (end ? '$' : (path[path.length - 1] === '/' ? '' : '(?=\\/|$)'));
|
||||
|
||||
return new RegExp(path, flags);
|
||||
};
|
||||
196
server/node_modules/path-to-regexp/package.json
generated
vendored
Normal file
196
server/node_modules/path-to-regexp/package.json
generated
vendored
Normal file
@@ -0,0 +1,196 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"raw": "path-to-regexp@0.1.3",
|
||||
"scope": null,
|
||||
"escapedName": "path-to-regexp",
|
||||
"name": "path-to-regexp",
|
||||
"rawSpec": "0.1.3",
|
||||
"spec": "0.1.3",
|
||||
"type": "version"
|
||||
},
|
||||
"/home/nau/MEGA/CODI/githubRepos/colspace/node_modules/express"
|
||||
]
|
||||
],
|
||||
"_from": "path-to-regexp@0.1.3",
|
||||
"_id": "path-to-regexp@0.1.3",
|
||||
"_inCache": true,
|
||||
"_location": "/path-to-regexp",
|
||||
"_npmUser": {
|
||||
"name": "blakeembrey",
|
||||
"email": "hello@blakeembrey.com"
|
||||
},
|
||||
"_npmVersion": "1.4.9",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"raw": "path-to-regexp@0.1.3",
|
||||
"scope": null,
|
||||
"escapedName": "path-to-regexp",
|
||||
"name": "path-to-regexp",
|
||||
"rawSpec": "0.1.3",
|
||||
"spec": "0.1.3",
|
||||
"type": "version"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/express"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.3.tgz",
|
||||
"_shasum": "21b9ab82274279de25b156ea08fd12ca51b8aecb",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "path-to-regexp@0.1.3",
|
||||
"_where": "/home/nau/MEGA/CODI/githubRepos/colspace/node_modules/express",
|
||||
"bugs": {
|
||||
"url": "https://github.com/component/path-to-regexp/issues"
|
||||
},
|
||||
"component": {
|
||||
"scripts": {
|
||||
"path-to-regexp": "index.js"
|
||||
}
|
||||
},
|
||||
"dependencies": {},
|
||||
"description": "Express style path to RegExp utility",
|
||||
"devDependencies": {
|
||||
"istanbul": "^0.2.6",
|
||||
"mocha": "^1.17.1"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "21b9ab82274279de25b156ea08fd12ca51b8aecb",
|
||||
"tarball": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.3.tgz"
|
||||
},
|
||||
"homepage": "https://github.com/component/path-to-regexp",
|
||||
"keywords": [
|
||||
"express",
|
||||
"regexp"
|
||||
],
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "tjholowaychuk",
|
||||
"email": "tj@vision-media.ca"
|
||||
},
|
||||
{
|
||||
"name": "jongleberry",
|
||||
"email": "jonathanrichardong@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "dominicbarnes",
|
||||
"email": "dominic@dbarnes.info"
|
||||
},
|
||||
{
|
||||
"name": "tootallnate",
|
||||
"email": "nathan@tootallnate.net"
|
||||
},
|
||||
{
|
||||
"name": "rauchg",
|
||||
"email": "rauchg@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "retrofox",
|
||||
"email": "rdsuarez@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "coreh",
|
||||
"email": "thecoreh@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "forbeslindesay",
|
||||
"email": "forbes@lindesay.co.uk"
|
||||
},
|
||||
{
|
||||
"name": "kelonye",
|
||||
"email": "kelonyemitchel@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "mattmueller",
|
||||
"email": "mattmuelle@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "yields",
|
||||
"email": "yields@icloud.com"
|
||||
},
|
||||
{
|
||||
"name": "anthonyshort",
|
||||
"email": "antshort@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "ianstormtaylor",
|
||||
"email": "ian@ianstormtaylor.com"
|
||||
},
|
||||
{
|
||||
"name": "cristiandouce",
|
||||
"email": "cristian@gravityonmars.com"
|
||||
},
|
||||
{
|
||||
"name": "swatinem",
|
||||
"email": "arpad.borsos@googlemail.com"
|
||||
},
|
||||
{
|
||||
"name": "stagas",
|
||||
"email": "gstagas@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "amasad",
|
||||
"email": "amjad.masad@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "juliangruber",
|
||||
"email": "julian@juliangruber.com"
|
||||
},
|
||||
{
|
||||
"name": "shtylman",
|
||||
"email": "shtylman@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "calvinfo",
|
||||
"email": "calvin@calv.info"
|
||||
},
|
||||
{
|
||||
"name": "blakeembrey",
|
||||
"email": "hello@blakeembrey.com"
|
||||
},
|
||||
{
|
||||
"name": "timoxley",
|
||||
"email": "secoif@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "jonathanong",
|
||||
"email": "jonathanrichardong@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "queckezz",
|
||||
"email": "fabian.eichenberger@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "nami-doc",
|
||||
"email": "vendethiel@hotmail.fr"
|
||||
},
|
||||
{
|
||||
"name": "clintwood",
|
||||
"email": "clint@anotherway.co.za"
|
||||
},
|
||||
{
|
||||
"name": "thehydroimpulse",
|
||||
"email": "dnfagnan@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "stephenmathieson",
|
||||
"email": "me@stephenmathieson.com"
|
||||
},
|
||||
{
|
||||
"name": "trevorgerhardt",
|
||||
"email": "trevorgerhardt@gmail.com"
|
||||
}
|
||||
],
|
||||
"name": "path-to-regexp",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/component/path-to-regexp.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "istanbul cover _mocha -- -R spec"
|
||||
},
|
||||
"version": "0.1.3"
|
||||
}
|
||||
616
server/node_modules/path-to-regexp/test.js
generated
vendored
Normal file
616
server/node_modules/path-to-regexp/test.js
generated
vendored
Normal file
@@ -0,0 +1,616 @@
|
||||
var pathToRegExp = require('./');
|
||||
var assert = require('assert');
|
||||
|
||||
describe('path-to-regexp', function () {
|
||||
describe('strings', function () {
|
||||
it('should match simple paths', function () {
|
||||
var params = [];
|
||||
var m = pathToRegExp('/test', params).exec('/test');
|
||||
|
||||
assert.equal(params.length, 0);
|
||||
|
||||
assert.equal(m.length, 1);
|
||||
assert.equal(m[0], '/test');
|
||||
});
|
||||
|
||||
it('should match express format params', function () {
|
||||
var params = [];
|
||||
var m = pathToRegExp('/:test', params).exec('/pathname');
|
||||
|
||||
assert.equal(params.length, 1);
|
||||
assert.equal(params[0].name, 'test');
|
||||
assert.equal(params[0].optional, false);
|
||||
|
||||
assert.equal(m.length, 2);
|
||||
assert.equal(m[0], '/pathname');
|
||||
assert.equal(m[1], 'pathname');
|
||||
});
|
||||
|
||||
it('should do strict matches', function () {
|
||||
var params = [];
|
||||
var re = pathToRegExp('/:test', params, { strict: true });
|
||||
var m;
|
||||
|
||||
assert.equal(params.length, 1);
|
||||
assert.equal(params[0].name, 'test');
|
||||
assert.equal(params[0].optional, false);
|
||||
|
||||
m = re.exec('/route');
|
||||
|
||||
assert.equal(m.length, 2);
|
||||
assert.equal(m[0], '/route');
|
||||
assert.equal(m[1], 'route');
|
||||
|
||||
m = re.exec('/route/');
|
||||
|
||||
assert.ok(!m);
|
||||
});
|
||||
|
||||
it('should do strict matches with trailing slashes', function () {
|
||||
var params = [];
|
||||
var re = pathToRegExp('/:test/', params, { strict: true });
|
||||
var m;
|
||||
|
||||
assert.equal(params.length, 1);
|
||||
assert.equal(params[0].name, 'test');
|
||||
assert.equal(params[0].optional, false);
|
||||
|
||||
m = re.exec('/route');
|
||||
|
||||
assert.ok(!m);
|
||||
|
||||
m = re.exec('/route/');
|
||||
|
||||
assert.equal(m.length, 2);
|
||||
assert.equal(m[0], '/route/');
|
||||
assert.equal(m[1], 'route');
|
||||
|
||||
m = re.exec('/route//');
|
||||
|
||||
assert.ok(!m);
|
||||
});
|
||||
|
||||
it('should allow optional express format params', function () {
|
||||
var params = [];
|
||||
var re = pathToRegExp('/:test?', params);
|
||||
var m;
|
||||
|
||||
assert.equal(params.length, 1);
|
||||
assert.equal(params[0].name, 'test');
|
||||
assert.equal(params[0].optional, true);
|
||||
|
||||
m = re.exec('/route');
|
||||
|
||||
assert.equal(m.length, 2);
|
||||
assert.equal(m[0], '/route');
|
||||
assert.equal(m[1], 'route');
|
||||
|
||||
m = re.exec('/');
|
||||
|
||||
assert.equal(m.length, 2);
|
||||
assert.equal(m[0], '/');
|
||||
assert.equal(m[1], undefined);
|
||||
});
|
||||
|
||||
it('should allow express format param regexps', function () {
|
||||
var params = [];
|
||||
var m = pathToRegExp('/:page(\\d+)', params).exec('/56');
|
||||
|
||||
assert.equal(params.length, 1);
|
||||
assert.equal(params[0].name, 'page');
|
||||
assert.equal(params[0].optional, false);
|
||||
|
||||
assert.equal(m.length, 2);
|
||||
assert.equal(m[0], '/56');
|
||||
assert.equal(m[1], '56');
|
||||
});
|
||||
|
||||
it('should match without a prefixed slash', function () {
|
||||
var params = [];
|
||||
var m = pathToRegExp(':test', params).exec('string');
|
||||
|
||||
assert.equal(params.length, 1);
|
||||
assert.equal(params[0].name, 'test');
|
||||
assert.equal(params[0].optional, false);
|
||||
|
||||
assert.equal(m.length, 2);
|
||||
assert.equal(m[0], 'string');
|
||||
assert.equal(m[1], 'string');
|
||||
});
|
||||
|
||||
it('should not match format parts', function () {
|
||||
var params = [];
|
||||
var m = pathToRegExp('/:test.json', params).exec('/route.json');
|
||||
|
||||
assert.equal(params.length, 1);
|
||||
assert.equal(params[0].name, 'test');
|
||||
assert.equal(params[0].optional, false);
|
||||
|
||||
assert.equal(m.length, 2);
|
||||
assert.equal(m[0], '/route.json');
|
||||
assert.equal(m[1], 'route');
|
||||
});
|
||||
|
||||
it('should match format parts', function () {
|
||||
var params = [];
|
||||
var re = pathToRegExp('/:test.:format', params);
|
||||
var m;
|
||||
|
||||
assert.equal(params.length, 2);
|
||||
assert.equal(params[0].name, 'test');
|
||||
assert.equal(params[0].optional, false);
|
||||
assert.equal(params[1].name, 'format');
|
||||
assert.equal(params[1].optional, false);
|
||||
|
||||
m = re.exec('/route.json');
|
||||
|
||||
assert.equal(m.length, 3);
|
||||
assert.equal(m[0], '/route.json');
|
||||
assert.equal(m[1], 'route');
|
||||
assert.equal(m[2], 'json');
|
||||
|
||||
m = re.exec('/route');
|
||||
|
||||
assert.ok(!m);
|
||||
});
|
||||
|
||||
it('should match route parts with a trailing format', function () {
|
||||
var params = [];
|
||||
var m = pathToRegExp('/:test.json', params).exec('/route.json');
|
||||
|
||||
assert.equal(params.length, 1);
|
||||
assert.equal(params[0].name, 'test');
|
||||
assert.equal(params[0].optional, false);
|
||||
|
||||
assert.equal(m.length, 2);
|
||||
assert.equal(m[0], '/route.json');
|
||||
assert.equal(m[1], 'route');
|
||||
});
|
||||
|
||||
it('should match optional trailing routes', function () {
|
||||
var params = [];
|
||||
var m = pathToRegExp('/test*', params).exec('/test/route');
|
||||
|
||||
assert.equal(params.length, 0);
|
||||
|
||||
assert.equal(m.length, 2);
|
||||
assert.equal(m[0], '/test/route');
|
||||
assert.equal(m[1], '/route');
|
||||
});
|
||||
|
||||
it('should match optional trailing routes after a param', function () {
|
||||
var params = [];
|
||||
var re = pathToRegExp('/:test*', params);
|
||||
var m;
|
||||
|
||||
assert.equal(params.length, 1);
|
||||
assert.equal(params[0].name, 'test');
|
||||
assert.equal(params[0].optional, false);
|
||||
|
||||
m = re.exec('/test/route');
|
||||
|
||||
assert.equal(m.length, 3);
|
||||
assert.equal(m[0], '/test/route');
|
||||
assert.equal(m[1], 'test');
|
||||
assert.equal(m[2], '/route');
|
||||
|
||||
m = re.exec('/testing');
|
||||
|
||||
assert.equal(m.length, 3);
|
||||
assert.equal(m[0], '/testing');
|
||||
assert.equal(m[1], 'testing');
|
||||
assert.equal(m[2], '');
|
||||
});
|
||||
|
||||
it('should match optional trailing routes before a format', function () {
|
||||
var params = [];
|
||||
var re = pathToRegExp('/test*.json', params);
|
||||
var m;
|
||||
|
||||
assert.equal(params.length, 0);
|
||||
|
||||
m = re.exec('/test.json');
|
||||
|
||||
assert.equal(m.length, 2);
|
||||
assert.equal(m[0], '/test.json');
|
||||
assert.equal(m[1], '');
|
||||
|
||||
m = re.exec('/testing.json');
|
||||
|
||||
assert.equal(m.length, 2);
|
||||
assert.equal(m[0], '/testing.json');
|
||||
assert.equal(m[1], 'ing');
|
||||
|
||||
m = re.exec('/test/route.json');
|
||||
|
||||
assert.equal(m.length, 2);
|
||||
assert.equal(m[0], '/test/route.json');
|
||||
assert.equal(m[1], '/route');
|
||||
});
|
||||
|
||||
it('should match optional trailing routes after a param and before a format', function () {
|
||||
var params = [];
|
||||
var re = pathToRegExp('/:test*.json', params);
|
||||
var m;
|
||||
|
||||
assert.equal(params.length, 1);
|
||||
assert.equal(params[0].name, 'test');
|
||||
assert.equal(params[0].optional, false);
|
||||
|
||||
m = re.exec('/testing.json');
|
||||
|
||||
assert.equal(m.length, 3);
|
||||
assert.equal(m[0], '/testing.json');
|
||||
assert.equal(m[1], 'testing');
|
||||
assert.equal(m[2], '');
|
||||
|
||||
m = re.exec('/test/route.json');
|
||||
|
||||
assert.equal(m.length, 3);
|
||||
assert.equal(m[0], '/test/route.json');
|
||||
assert.equal(m[1], 'test');
|
||||
assert.equal(m[2], '/route');
|
||||
|
||||
m = re.exec('.json');
|
||||
|
||||
assert.ok(!m);
|
||||
});
|
||||
|
||||
it('should match optional trailing routes between a normal param and a format param', function () {
|
||||
var params = [];
|
||||
var re = pathToRegExp('/:test*.:format', params);
|
||||
var m;
|
||||
|
||||
assert.equal(params.length, 2);
|
||||
assert.equal(params[0].name, 'test');
|
||||
assert.equal(params[0].optional, false);
|
||||
assert.equal(params[1].name, 'format');
|
||||
assert.equal(params[1].optional, false);
|
||||
|
||||
m = re.exec('/testing.json');
|
||||
|
||||
assert.equal(m.length, 4);
|
||||
assert.equal(m[0], '/testing.json');
|
||||
assert.equal(m[1], 'testing');
|
||||
assert.equal(m[2], '');
|
||||
assert.equal(m[3], 'json');
|
||||
|
||||
m = re.exec('/test/route.json');
|
||||
|
||||
assert.equal(m.length, 4);
|
||||
assert.equal(m[0], '/test/route.json');
|
||||
assert.equal(m[1], 'test');
|
||||
assert.equal(m[2], '/route');
|
||||
assert.equal(m[3], 'json');
|
||||
|
||||
m = re.exec('/test');
|
||||
|
||||
assert.ok(!m);
|
||||
|
||||
m = re.exec('.json');
|
||||
|
||||
assert.ok(!m);
|
||||
});
|
||||
|
||||
it('should match optional trailing routes after a param and before an optional format param', function () {
|
||||
var params = [];
|
||||
var re = pathToRegExp('/:test*.:format?', params);
|
||||
var m;
|
||||
|
||||
assert.equal(params.length, 2);
|
||||
assert.equal(params[0].name, 'test');
|
||||
assert.equal(params[0].optional, false);
|
||||
assert.equal(params[1].name, 'format');
|
||||
assert.equal(params[1].optional, true);
|
||||
|
||||
m = re.exec('/testing.json');
|
||||
|
||||
assert.equal(m.length, 4);
|
||||
assert.equal(m[0], '/testing.json');
|
||||
assert.equal(m[1], 'testing');
|
||||
assert.equal(m[2], '');
|
||||
assert.equal(m[3], 'json');
|
||||
|
||||
m = re.exec('/test/route.json');
|
||||
|
||||
assert.equal(m.length, 4);
|
||||
assert.equal(m[0], '/test/route.json');
|
||||
assert.equal(m[1], 'test');
|
||||
assert.equal(m[2], '/route');
|
||||
assert.equal(m[3], 'json');
|
||||
|
||||
m = re.exec('/test');
|
||||
|
||||
assert.equal(m.length, 4);
|
||||
assert.equal(m[0], '/test');
|
||||
assert.equal(m[1], 'test');
|
||||
assert.equal(m[2], '');
|
||||
assert.equal(m[3], undefined);
|
||||
|
||||
m = re.exec('.json');
|
||||
|
||||
assert.ok(!m);
|
||||
});
|
||||
|
||||
it('should match optional trailing routes inside optional express param', function () {
|
||||
var params = [];
|
||||
var re = pathToRegExp('/:test*?', params);
|
||||
var m;
|
||||
|
||||
assert.equal(params.length, 1);
|
||||
assert.equal(params[0].name, 'test');
|
||||
assert.equal(params[0].optional, true);
|
||||
|
||||
m = re.exec('/test/route');
|
||||
|
||||
assert.equal(m.length, 3);
|
||||
assert.equal(m[0], '/test/route');
|
||||
assert.equal(m[1], 'test');
|
||||
assert.equal(m[2], '/route');
|
||||
|
||||
m = re.exec('/test');
|
||||
|
||||
assert.equal(m.length, 3);
|
||||
assert.equal(m[0], '/test');
|
||||
assert.equal(m[1], 'test');
|
||||
assert.equal(m[2], '');
|
||||
|
||||
m = re.exec('/');
|
||||
|
||||
assert.equal(m.length, 3);
|
||||
assert.equal(m[0], '/');
|
||||
assert.equal(m[1], undefined);
|
||||
assert.equal(m[2], undefined);
|
||||
});
|
||||
|
||||
it('should do case insensitive matches', function () {
|
||||
var m = pathToRegExp('/test').exec('/TEST');
|
||||
|
||||
assert.equal(m[0], '/TEST');
|
||||
});
|
||||
|
||||
it('should do case sensitive matches', function () {
|
||||
var re = pathToRegExp('/test', null, { sensitive: true });
|
||||
var m;
|
||||
|
||||
m = re.exec('/test');
|
||||
|
||||
assert.equal(m.length, 1);
|
||||
assert.equal(m[0], '/test');
|
||||
|
||||
m = re.exec('/TEST');
|
||||
|
||||
assert.ok(!m);
|
||||
});
|
||||
|
||||
it('should do non-ending matches', function () {
|
||||
var params = [];
|
||||
var m = pathToRegExp('/:test', params, { end: false }).exec('/test/route');
|
||||
|
||||
assert.equal(params.length, 1);
|
||||
assert.equal(params[0].name, 'test');
|
||||
assert.equal(params[0].optional, false);
|
||||
|
||||
assert.equal(m.length, 2);
|
||||
assert.equal(m[0], '/test');
|
||||
assert.equal(m[1], 'test');
|
||||
});
|
||||
|
||||
it('should match trailing slashes in non-ending non-strict mode', function () {
|
||||
var params = [];
|
||||
var re = pathToRegExp('/:test', params, { end: false });
|
||||
var m;
|
||||
|
||||
assert.equal(params.length, 1);
|
||||
assert.equal(params[0].name, 'test');
|
||||
assert.equal(params[0].optional, false);
|
||||
|
||||
m = re.exec('/test/');
|
||||
|
||||
assert.equal(m.length, 2);
|
||||
assert.equal(m[0], '/test/');
|
||||
assert.equal(m[1], 'test');
|
||||
});
|
||||
|
||||
it('should match trailing slashes in non-ending non-strict mode', function () {
|
||||
var params = [];
|
||||
var re = pathToRegExp('/route/', params, { end: false });
|
||||
var m;
|
||||
|
||||
assert.equal(params.length, 0);
|
||||
|
||||
m = re.exec('/route/');
|
||||
|
||||
assert.equal(m.length, 1);
|
||||
assert.equal(m[0], '/route/');
|
||||
|
||||
m = re.exec('/route/test');
|
||||
|
||||
assert.equal(m.length, 1);
|
||||
assert.equal(m[0], '/route');
|
||||
|
||||
m = re.exec('/route');
|
||||
|
||||
assert.equal(m.length, 1);
|
||||
assert.equal(m[0], '/route');
|
||||
|
||||
m = re.exec('/route//');
|
||||
|
||||
assert.equal(m.length, 1);
|
||||
assert.equal(m[0], '/route/');
|
||||
});
|
||||
|
||||
it('should match trailing slashing in non-ending strict mode', function () {
|
||||
var params = [];
|
||||
var re = pathToRegExp('/route/', params, { end: false, strict: true });
|
||||
|
||||
assert.equal(params.length, 0);
|
||||
|
||||
m = re.exec('/route/');
|
||||
|
||||
assert.equal(m.length, 1);
|
||||
assert.equal(m[0], '/route/');
|
||||
|
||||
m = re.exec('/route/test');
|
||||
|
||||
assert.equal(m.length, 1);
|
||||
assert.equal(m[0], '/route/');
|
||||
|
||||
m = re.exec('/route');
|
||||
|
||||
assert.ok(!m);
|
||||
|
||||
m = re.exec('/route//');
|
||||
|
||||
assert.equal(m.length, 1);
|
||||
assert.equal(m[0], '/route/');
|
||||
});
|
||||
|
||||
it('should not match trailing slashes in non-ending strict mode', function () {
|
||||
var params = [];
|
||||
var re = pathToRegExp('/route', params, { end: false, strict: true });
|
||||
|
||||
assert.equal(params.length, 0);
|
||||
|
||||
m = re.exec('/route');
|
||||
|
||||
assert.equal(m.length, 1);
|
||||
assert.equal(m[0], '/route');
|
||||
|
||||
m = re.exec('/route/');
|
||||
|
||||
assert.ok(m.length, 1);
|
||||
assert.equal(m[0], '/route');
|
||||
});
|
||||
|
||||
it('should match text after an express param', function () {
|
||||
var params = [];
|
||||
var re = pathToRegExp('/(:test)route', params);
|
||||
|
||||
assert.equal(params.length, 1);
|
||||
assert.equal(params[0].name, 'test');
|
||||
assert.equal(params[0].optional, false);
|
||||
|
||||
m = re.exec('/route');
|
||||
|
||||
assert.ok(!m);
|
||||
|
||||
m = re.exec('/testroute');
|
||||
|
||||
assert.equal(m.length, 2);
|
||||
assert.equal(m[0], '/testroute');
|
||||
assert.equal(m[1], 'test');
|
||||
|
||||
m = re.exec('testroute');
|
||||
|
||||
assert.ok(!m);
|
||||
});
|
||||
|
||||
it('should match text after an optional express param', function () {
|
||||
var params = [];
|
||||
var re = pathToRegExp('/(:test?)route', params);
|
||||
var m;
|
||||
|
||||
assert.equal(params.length, 1);
|
||||
assert.equal(params[0].name, 'test');
|
||||
assert.equal(params[0].optional, true);
|
||||
|
||||
m = re.exec('/route');
|
||||
|
||||
assert.equal(m.length, 2);
|
||||
assert.equal(m[0], '/route');
|
||||
assert.equal(m[1], undefined);
|
||||
|
||||
m = re.exec('/testroute');
|
||||
|
||||
assert.equal(m.length, 2);
|
||||
assert.equal(m[0], '/testroute');
|
||||
assert.equal(m[1], 'test');
|
||||
|
||||
m = re.exec('route');
|
||||
|
||||
assert.ok(!m);
|
||||
});
|
||||
|
||||
it('should match optional formats', function () {
|
||||
var params = [];
|
||||
var re = pathToRegExp('/:test.:format?', params);
|
||||
var m;
|
||||
|
||||
assert.equal(params.length, 2);
|
||||
assert.equal(params[0].name, 'test');
|
||||
assert.equal(params[0].optional, false);
|
||||
assert.equal(params[1].name, 'format');
|
||||
assert.equal(params[1].optional, true);
|
||||
|
||||
m = re.exec('/route');
|
||||
|
||||
assert.equal(m.length, 3);
|
||||
assert.equal(m[0], '/route');
|
||||
assert.equal(m[1], 'route');
|
||||
assert.equal(m[2], undefined);
|
||||
|
||||
m = re.exec('/route.json');
|
||||
|
||||
assert.equal(m.length, 3);
|
||||
assert.equal(m[0], '/route.json');
|
||||
assert.equal(m[1], 'route');
|
||||
assert.equal(m[2], 'json');
|
||||
});
|
||||
|
||||
it('should match full paths with format by default', function () {
|
||||
var params = [];
|
||||
var m = pathToRegExp('/:test', params).exec('/test.json');
|
||||
|
||||
assert.equal(params.length, 1);
|
||||
assert.equal(params[0].name, 'test');
|
||||
assert.equal(params[0].optional, false);
|
||||
|
||||
assert.equal(m.length, 2);
|
||||
assert.equal(m[0], '/test.json');
|
||||
assert.equal(m[1], 'test.json');
|
||||
});
|
||||
});
|
||||
|
||||
describe('regexps', function () {
|
||||
it('should return the regexp', function () {
|
||||
assert.deepEqual(pathToRegExp(/.*/), /.*/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('arrays', function () {
|
||||
it('should join arrays parts', function () {
|
||||
var re = pathToRegExp(['/test', '/route']);
|
||||
|
||||
assert.ok(re.test('/test'));
|
||||
assert.ok(re.test('/route'));
|
||||
assert.ok(!re.test('/else'));
|
||||
});
|
||||
|
||||
it('should match parts properly', function () {
|
||||
var params = [];
|
||||
var re = pathToRegExp(['/:test', '/test/:route'], params);
|
||||
var m;
|
||||
|
||||
assert.equal(params.length, 2);
|
||||
assert.equal(params[0].name, 'test');
|
||||
assert.equal(params[0].optional, false);
|
||||
assert.equal(params[1].name, 'route');
|
||||
assert.equal(params[1].optional, false);
|
||||
|
||||
m = re.exec('/route');
|
||||
|
||||
assert.equal(m.length, 3);
|
||||
assert.equal(m[0], '/route');
|
||||
assert.equal(m[1], 'route');
|
||||
assert.equal(m[2], undefined);
|
||||
|
||||
m = re.exec('/test/path');
|
||||
|
||||
assert.equal(m.length, 3);
|
||||
assert.equal(m[0], '/test/path');
|
||||
assert.equal(m[1], undefined);
|
||||
assert.equal(m[2], 'path');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user