2021-02-26 04:58:33 +01:00
import { merge , subexp } from "./util" ;
export function buildExps ( isIRI ) {
const ALPHA$$ = "[A-Za-z]" , CR$ = "[\\x0D]" , DIGIT$$ = "[0-9]" , DQUOTE$$ = "[\\x22]" , HEXDIG$$ = merge ( DIGIT$$ , "[A-Fa-f]" ) , //case-insensitive
LF$$ = "[\\x0A]" , SP$$ = "[\\x20]" , PCT _ENCODED$ = subexp ( subexp ( "%[EFef]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$ ) + "|" + subexp ( "%[89A-Fa-f]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$ ) + "|" + subexp ( "%" + HEXDIG$$ + HEXDIG$$ ) ) , //expanded
GEN _DELIMS$$ = "[\\:\\/\\?\\#\\[\\]\\@]" , SUB _DELIMS$$ = "[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]" , RESERVED$$ = merge ( GEN _DELIMS$$ , SUB _DELIMS$$ ) , UCSCHAR$$ = isIRI ? "[\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]" : "[]" , //subset, excludes bidi control characters
IPRIVATE$$ = isIRI ? "[\\uE000-\\uF8FF]" : "[]" , //subset
UNRESERVED$$ = merge ( ALPHA$$ , DIGIT$$ , "[\\-\\.\\_\\~]" , UCSCHAR$$ ) , SCHEME$ = subexp ( ALPHA$$ + merge ( ALPHA$$ , DIGIT$$ , "[\\+\\-\\.]" ) + "*" ) , USERINFO$ = subexp ( subexp ( PCT _ENCODED$ + "|" + merge ( UNRESERVED$$ , SUB _DELIMS$$ , "[\\:]" ) ) + "*" ) , DEC _OCTET$ = subexp ( subexp ( "25[0-5]" ) + "|" + subexp ( "2[0-4]" + DIGIT$$ ) + "|" + subexp ( "1" + DIGIT$$ + DIGIT$$ ) + "|" + subexp ( "[1-9]" + DIGIT$$ ) + "|" + DIGIT$$ ) , DEC _OCTET _RELAXED$ = subexp ( subexp ( "25[0-5]" ) + "|" + subexp ( "2[0-4]" + DIGIT$$ ) + "|" + subexp ( "1" + DIGIT$$ + DIGIT$$ ) + "|" + subexp ( "0?[1-9]" + DIGIT$$ ) + "|0?0?" + DIGIT$$ ) , //relaxed parsing rules
IPV4ADDRESS$ = subexp ( DEC _OCTET _RELAXED$ + "\\." + DEC _OCTET _RELAXED$ + "\\." + DEC _OCTET _RELAXED$ + "\\." + DEC _OCTET _RELAXED$ ) , H16$ = subexp ( HEXDIG$$ + "{1,4}" ) , LS32$ = subexp ( subexp ( H16$ + "\\:" + H16$ ) + "|" + IPV4ADDRESS$ ) , IPV6ADDRESS1$ = subexp ( subexp ( H16$ + "\\:" ) + "{6}" + LS32$ ) , // 6( h16 ":" ) ls32
IPV6ADDRESS2$ = subexp ( "\\:\\:" + subexp ( H16$ + "\\:" ) + "{5}" + LS32$ ) , // "::" 5( h16 ":" ) ls32
IPV6ADDRESS3$ = subexp ( subexp ( H16$ ) + "?\\:\\:" + subexp ( H16$ + "\\:" ) + "{4}" + LS32$ ) , //[ h16 ] "::" 4( h16 ":" ) ls32
IPV6ADDRESS4$ = subexp ( subexp ( subexp ( H16$ + "\\:" ) + "{0,1}" + H16$ ) + "?\\:\\:" + subexp ( H16$ + "\\:" ) + "{3}" + LS32$ ) , //[ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
IPV6ADDRESS5$ = subexp ( subexp ( subexp ( H16$ + "\\:" ) + "{0,2}" + H16$ ) + "?\\:\\:" + subexp ( H16$ + "\\:" ) + "{2}" + LS32$ ) , //[ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
IPV6ADDRESS6$ = subexp ( subexp ( subexp ( H16$ + "\\:" ) + "{0,3}" + H16$ ) + "?\\:\\:" + H16$ + "\\:" + LS32$ ) , //[ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
IPV6ADDRESS7$ = subexp ( subexp ( subexp ( H16$ + "\\:" ) + "{0,4}" + H16$ ) + "?\\:\\:" + LS32$ ) , //[ *4( h16 ":" ) h16 ] "::" ls32
IPV6ADDRESS8$ = subexp ( subexp ( subexp ( H16$ + "\\:" ) + "{0,5}" + H16$ ) + "?\\:\\:" + H16$ ) , //[ *5( h16 ":" ) h16 ] "::" h16
IPV6ADDRESS9$ = subexp ( subexp ( subexp ( H16$ + "\\:" ) + "{0,6}" + H16$ ) + "?\\:\\:" ) , //[ *6( h16 ":" ) h16 ] "::"
IPV6ADDRESS$ = subexp ( [ IPV6ADDRESS1$ , IPV6ADDRESS2$ , IPV6ADDRESS3$ , IPV6ADDRESS4$ , IPV6ADDRESS5$ , IPV6ADDRESS6$ , IPV6ADDRESS7$ , IPV6ADDRESS8$ , IPV6ADDRESS9$ ] . join ( "|" ) ) , ZONEID$ = subexp ( subexp ( UNRESERVED$$ + "|" + PCT _ENCODED$ ) + "+" ) , //RFC 6874
IPV6ADDRZ$ = subexp ( IPV6ADDRESS$ + "\\%25" + ZONEID$ ) , //RFC 6874
IPV6ADDRZ _RELAXED$ = subexp ( IPV6ADDRESS$ + subexp ( "\\%25|\\%(?!" + HEXDIG$$ + "{2})" ) + ZONEID$ ) , //RFC 6874, with relaxed parsing rules
IPVFUTURE$ = subexp ( "[vV]" + HEXDIG$$ + "+\\." + merge ( UNRESERVED$$ , SUB _DELIMS$$ , "[\\:]" ) + "+" ) , IP _LITERAL$ = subexp ( "\\[" + subexp ( IPV6ADDRZ _RELAXED$ + "|" + IPV6ADDRESS$ + "|" + IPVFUTURE$ ) + "\\]" ) , //RFC 6874
REG _NAME$ = subexp ( subexp ( PCT _ENCODED$ + "|" + merge ( UNRESERVED$$ , SUB _DELIMS$$ ) ) + "*" ) , HOST$ = subexp ( IP _LITERAL$ + "|" + IPV4ADDRESS$ + "(?!" + REG _NAME$ + ")" + "|" + REG _NAME$ ) , PORT$ = subexp ( DIGIT$$ + "*" ) , AUTHORITY$ = subexp ( subexp ( USERINFO$ + "@" ) + "?" + HOST$ + subexp ( "\\:" + PORT$ ) + "?" ) , PCHAR$ = subexp ( PCT _ENCODED$ + "|" + merge ( UNRESERVED$$ , SUB _DELIMS$$ , "[\\:\\@]" ) ) , SEGMENT$ = subexp ( PCHAR$ + "*" ) , SEGMENT _NZ$ = subexp ( PCHAR$ + "+" ) , SEGMENT _NZ _NC$ = subexp ( subexp ( PCT _ENCODED$ + "|" + merge ( UNRESERVED$$ , SUB _DELIMS$$ , "[\\@]" ) ) + "+" ) , PATH _ABEMPTY$ = subexp ( subexp ( "\\/" + SEGMENT$ ) + "*" ) , PATH _ABSOLUTE$ = subexp ( "\\/" + subexp ( SEGMENT _NZ$ + PATH _ABEMPTY$ ) + "?" ) , //simplified
PATH _NOSCHEME$ = subexp ( SEGMENT _NZ _NC$ + PATH _ABEMPTY$ ) , //simplified
PATH _ROOTLESS$ = subexp ( SEGMENT _NZ$ + PATH _ABEMPTY$ ) , //simplified
PATH _EMPTY$ = "(?!" + PCHAR$ + ")" , PATH$ = subexp ( PATH _ABEMPTY$ + "|" + PATH _ABSOLUTE$ + "|" + PATH _NOSCHEME$ + "|" + PATH _ROOTLESS$ + "|" + PATH _EMPTY$ ) , QUERY$ = subexp ( subexp ( PCHAR$ + "|" + merge ( "[\\/\\?]" , IPRIVATE$$ ) ) + "*" ) , FRAGMENT$ = subexp ( subexp ( PCHAR$ + "|[\\/\\?]" ) + "*" ) , HIER _PART$ = subexp ( subexp ( "\\/\\/" + AUTHORITY$ + PATH _ABEMPTY$ ) + "|" + PATH _ABSOLUTE$ + "|" + PATH _ROOTLESS$ + "|" + PATH _EMPTY$ ) , URI$ = subexp ( SCHEME$ + "\\:" + HIER _PART$ + subexp ( "\\?" + QUERY$ ) + "?" + subexp ( "\\#" + FRAGMENT$ ) + "?" ) , RELATIVE _PART$ = subexp ( subexp ( "\\/\\/" + AUTHORITY$ + PATH _ABEMPTY$ ) + "|" + PATH _ABSOLUTE$ + "|" + PATH _NOSCHEME$ + "|" + PATH _EMPTY$ ) , RELATIVE$ = subexp ( RELATIVE _PART$ + subexp ( "\\?" + QUERY$ ) + "?" + subexp ( "\\#" + FRAGMENT$ ) + "?" ) , URI _REFERENCE$ = subexp ( URI$ + "|" + RELATIVE$ ) , ABSOLUTE _URI$ = subexp ( SCHEME$ + "\\:" + HIER _PART$ + subexp ( "\\?" + QUERY$ ) + "?" ) , GENERIC _REF$ = "^(" + SCHEME$ + ")\\:" + subexp ( subexp ( "\\/\\/(" + subexp ( "(" + USERINFO$ + ")@" ) + "?(" + HOST$ + ")" + subexp ( "\\:(" + PORT$ + ")" ) + "?)" ) + "?(" + PATH _ABEMPTY$ + "|" + PATH _ABSOLUTE$ + "|" + PATH _ROOTLESS$ + "|" + PATH _EMPTY$ + ")" ) + subexp ( "\\?(" + QUERY$ + ")" ) + "?" + subexp ( "\\#(" + FRAGMENT$ + ")" ) + "?$" , RELATIVE _REF$ = "^(){0}" + subexp ( subexp ( "\\/\\/(" + subexp ( "(" + USERINFO$ + ")@" ) + "?(" + HOST$ + ")" + subexp ( "\\:(" + PORT$ + ")" ) + "?)" ) + "?(" + PATH _ABEMPTY$ + "|" + PATH _ABSOLUTE$ + "|" + PATH _NOSCHEME$ + "|" + PATH _EMPTY$ + ")" ) + subexp ( "\\?(" + QUERY$ + ")" ) + "?" + subexp ( "\\#(" + FRAGMENT$ + ")" ) + "?$" , ABSOLUTE _REF$ = "^(" + SCHEME$ + ")\\:" + subexp ( subexp ( "\\/\\/(" + subexp ( "(" + USERINFO$ + ")@" ) + "?(" + HOST$ + ")" + subexp ( "\\:(" + PORT$ + ")" ) + "?)" ) + "?(" + PATH _ABEMPTY$ + "|" + PATH _ABSOLUTE$ + "|" + PATH _ROOTLESS$ + "|" + PATH _EMPTY$ + ")" ) + subexp ( "\\?(" + QUERY$ + ")" ) + "?$" , SAMEDOC _REF$ = "^" + subexp ( "\\#(" + FRAGMENT$ + ")" ) + "?$" , AUTHORITY _REF$ = "^" + subexp ( "(" + USERINFO$ + ")@" ) + "?(" + HOST$ + ")" + subexp ( "\\:(" + PORT$ + ")" ) + "?$" ;
return {
NOT _SCHEME : new RegExp ( merge ( "[^]" , ALPHA$$ , DIGIT$$ , "[\\+\\-\\.]" ) , "g" ) ,
NOT _USERINFO : new RegExp ( merge ( "[^\\%\\:]" , UNRESERVED$$ , SUB _DELIMS$$ ) , "g" ) ,
NOT _HOST : new RegExp ( merge ( "[^\\%\\[\\]\\:]" , UNRESERVED$$ , SUB _DELIMS$$ ) , "g" ) ,
NOT _PATH : new RegExp ( merge ( "[^\\%\\/\\:\\@]" , UNRESERVED$$ , SUB _DELIMS$$ ) , "g" ) ,
NOT _PATH _NOSCHEME : new RegExp ( merge ( "[^\\%\\/\\@]" , UNRESERVED$$ , SUB _DELIMS$$ ) , "g" ) ,
NOT _QUERY : new RegExp ( merge ( "[^\\%]" , UNRESERVED$$ , SUB _DELIMS$$ , "[\\:\\@\\/\\?]" , IPRIVATE$$ ) , "g" ) ,
NOT _FRAGMENT : new RegExp ( merge ( "[^\\%]" , UNRESERVED$$ , SUB _DELIMS$$ , "[\\:\\@\\/\\?]" ) , "g" ) ,
ESCAPE : new RegExp ( merge ( "[^]" , UNRESERVED$$ , SUB _DELIMS$$ ) , "g" ) ,
UNRESERVED : new RegExp ( UNRESERVED$$ , "g" ) ,
OTHER _CHARS : new RegExp ( merge ( "[^\\%]" , UNRESERVED$$ , RESERVED$$ ) , "g" ) ,
PCT _ENCODED : new RegExp ( PCT _ENCODED$ , "g" ) ,
IPV4ADDRESS : new RegExp ( "^(" + IPV4ADDRESS$ + ")$" ) ,
IPV6ADDRESS : new RegExp ( "^\\[?(" + IPV6ADDRESS$ + ")" + subexp ( subexp ( "\\%25|\\%(?!" + HEXDIG$$ + "{2})" ) + "(" + ZONEID$ + ")" ) + "?\\]?$" ) //RFC 6874, with relaxed parsing rules
} ;
}
export default buildExps ( false ) ;
2020-08-26 01:57:08 +02:00
//# sourceMappingURL=regexps-uri.js.map