12345678910111213141516171819202122232425262728293031323334353637383940 |
- 'use strict';
- // Load Modules
- const RFC3986 = require('./rfc3986');
- // Declare internals
- const internals = {
- Uri: {
- createUriRegex: function (optionalScheme, allowRelative) {
- let scheme = RFC3986.scheme;
- // If we were passed a scheme, use it instead of the generic one
- if (optionalScheme) {
- // Have to put this in a non-capturing group to handle the OR statements
- scheme = '(?:' + optionalScheme + ')';
- }
- const withScheme = '(?:' + scheme + ':' + RFC3986.hierPart + ')';
- const prefix = allowRelative ? '(?:' + withScheme + '|' + RFC3986.relativeRef + ')' : withScheme;
- /**
- * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
- *
- * OR
- *
- * relative-ref = relative-part [ "?" query ] [ "#" fragment ]
- */
- return new RegExp('^' + prefix + '(?:\\?' + RFC3986.query + ')?' + '(?:#' + RFC3986.fragment + ')?$');
- }
- }
- };
- module.exports = internals.Uri;
|