Comparing version 1.1.0 to 2.0.0
433
index.js
@@ -1,387 +0,80 @@ | ||
(function(module) { | ||
'use strict'; | ||
/** | ||
* Basic Values (http://tools.ietf.org/html/rfc3986#page-11) | ||
* | ||
* This specification uses the Augmented Backus-Naur Form (ABNF) | ||
* notation of [RFC2234], including the following core ABNF syntax rules | ||
* defined by that specification: ALPHA (letters), CR (carriage return), | ||
* DIGIT (decimal digits), DQUOTE (double quote), HEXDIG (hexadecimal | ||
* digits), LF (line feed), and SP (space). The complete URI syntax is | ||
* collected in Appendix A. | ||
* | ||
* @type {string} | ||
*/ | ||
var rfc3986 = require('rfc-3986'); | ||
/** | ||
* Digit (http://tools.ietf.org/html/rfc2234#page-10) | ||
* | ||
* DIGIT = %x30-39 ; 0-9 | ||
* | ||
* @type {string} | ||
*/ | ||
var digit = '0-9', | ||
digitOnly = '[' + digit + ']'; | ||
// See: https://github.com/hapijs/hoek/blob/f62961d3d07aca68ab11480893e6e80a421914b4/lib/index.js#L783-L787 | ||
function escapeRegex(string) { | ||
// Escape ^$.*+-?=!:|\/()[]{}, | ||
return string.replace(/[\^\$\.\*\+\-\?\=\!\:\|\\\/\(\)\[\]\{\}\,]/g, '\\$&'); | ||
} | ||
/** | ||
* Alpha (http://tools.ietf.org/html/rfc2234#page-11) | ||
* | ||
* ALPHA = %x41-5A / %x61-7A ; A-Z / a-z | ||
* | ||
* @type {string} | ||
*/ | ||
var alpha = 'a-zA-Z'; | ||
var internals = { | ||
Uri: { | ||
createUriRegex: function (options) { | ||
options = options || {}; | ||
/** | ||
* Hexadecimal Digit (http://tools.ietf.org/html/rfc2234#page-11) | ||
* | ||
* HEXDIG = DIGIT / "A" / "B" / "C" / "D" / "E" / "F" | ||
* | ||
* @type {string} | ||
*/ | ||
var hexDigit = digit + 'A-F', | ||
hexDigitOnly = '[' + hexDigit + ']'; | ||
if (typeof options !== 'object' || Array.isArray(options)) { | ||
throw new Error('options must be an object'); | ||
} | ||
/** | ||
* Unreserved (http://tools.ietf.org/html/rfc3986#page-13) | ||
* | ||
* Characters that are allowed in a URI but do not have a reserved | ||
* purpose are called unreserved. These include uppercase and lowercase | ||
* letters, decimal digits, hyphen, period, underscore, and tilde. | ||
* | ||
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" | ||
* | ||
* @type {string} | ||
*/ | ||
var unreserved = alpha + digit + '-\\._~'; | ||
var customScheme = ''; | ||
/** | ||
* Percent Encoded (http://tools.ietf.org/html/rfc3986#page-12) | ||
* | ||
* percent-encoding mechanism is used to represent a data octet in a | ||
* component when that octet's corresponding character is outside the | ||
* allowed set or is being used as a delimiter of, or within, the | ||
* component. A percent-encoded octet is encoded as a character | ||
* triplet, consisting of the percent character "%" followed by the two | ||
* hexadecimal digits representing that octet's numeric value. For | ||
* example, "%20" is the percent-encoding for the binary octet | ||
* "00100000" (ABNF: %x20), which in US-ASCII corresponds to the space | ||
* character (SP). | ||
* | ||
* pct-encoded = "%" HEXDIG HEXDIG | ||
* | ||
* @type {string} | ||
*/ | ||
var pctEncoded = '%' + hexDigit; | ||
// If we were passed a scheme, use it instead of the generic one | ||
if (options.scheme) { | ||
if (!Array.isArray(options.scheme)) { | ||
options.scheme = [options.scheme]; | ||
} | ||
/** | ||
* Sub Delimiters (http://tools.ietf.org/html/rfc3986#page-13) | ||
* | ||
* | ||
* | ||
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" | ||
* | ||
* @type {string} | ||
*/ | ||
var subDelims = '!$&\'()*+,;='; | ||
if (options.scheme.length <= 0) { | ||
throw new Error('scheme must have at least 1 scheme specified'); | ||
} | ||
/** | ||
* PChar (http://tools.ietf.org/html/rfc3986#page-23) | ||
* | ||
* pchar = unreserved / pct-encoded / sub-delims / ":" / "@" | ||
* | ||
* @type {string} | ||
*/ | ||
var pchar = unreserved + pctEncoded + subDelims + ':@', | ||
pcharOnly = '[' + pchar + ']'; | ||
for (var i = 0; i < options.scheme.length; ++i) { | ||
var currentScheme = options.scheme[i]; | ||
/** | ||
* Alternative Rules (http://tools.ietf.org/html/rfc2234#page-6) | ||
* | ||
* ements separated by forward slash ("/") are alternatives. | ||
* | ||
* @type {string} | ||
*/ | ||
var or = '|'; | ||
if (!(currentScheme instanceof RegExp || typeof currentScheme === 'string')) { | ||
throw new Error('scheme must only contain Regular Expressions or Strings'); | ||
} | ||
/** | ||
* Rule to support zero-padded addresses. | ||
* | ||
* @type {string} | ||
*/ | ||
var zeroPad = '0?'; | ||
// Add OR separators if a value already exists | ||
customScheme = customScheme + (customScheme ? '|' : ''); | ||
/** | ||
* dec-octect (http://tools.ietf.org/html/rfc3986#page-20) | ||
* | ||
* dec-octet = DIGIT ; 0-9 | ||
* / %x31-39 DIGIT ; 10-99 | ||
* / "1" 2DIGIT ; 100-199 | ||
* / "2" %x30-34 DIGIT ; 200-249 | ||
* / "25" %x30-35 ; 250-255 | ||
* | ||
* @type {string} | ||
*/ | ||
var decOctect = '(' + zeroPad + zeroPad + digitOnly + or + zeroPad + '[1-9]' + digitOnly + or + '1' + digitOnly + digitOnly + or + '2' + '[0-4]' + digitOnly + or + '25' + '[0-5])'; | ||
// If someone wants to match HTTP or HTTPS for example then we need to support both RegExp and String so we don't escape their pattern unknowingly. | ||
if (currentScheme instanceof RegExp) { | ||
customScheme = customScheme + currentScheme.source; | ||
} else { | ||
if (!/[a-zA-Z][a-zA-Z0-9+-\.]*/.test(currentScheme)) { | ||
throw new Error('scheme at position ' + i + ' must be a valid scheme'); | ||
} | ||
customScheme = customScheme + escapeRegex(currentScheme); | ||
} | ||
} | ||
/** | ||
* Scheme (http://tools.ietf.org/html/rfc3986#page-17) | ||
* | ||
* Scheme names consist of a sequence of characters beginning with a | ||
* letter and followed by any combination of letters, digits, plus | ||
* ("+"), period ("."), or hyphen ("-"). | ||
* | ||
* @type {string} | ||
*/ | ||
var scheme = '^[a-zA-Z][a-zA-Z0-9+\\.-]*:'; | ||
} | ||
/** | ||
* User Info (http://tools.ietf.org/html/rfc3986#page-18) | ||
* | ||
* The userinfo subcomponent may consist of a user name and, optionally, | ||
* scheme-specific information about how to gain authorization to access | ||
* the resource. The user information, if present, is followed by a | ||
* commercial at-sign ("@") that delimits it from the host. | ||
* | ||
* userinfo = *( unreserved / pct-encoded / sub-delims / ":" ) | ||
* | ||
* @type {string} | ||
*/ | ||
var userinfo = '([' + unreserved + pctEncoded + subDelims + ':]*@)?'; | ||
// Have to put this in a non-capturing group to handle the OR statements | ||
var scheme = '(?:' + (customScheme || rfc3986.scheme) + ')'; | ||
/** | ||
* IPv4address (http://tools.ietf.org/html/rfc3986#page-20) | ||
* | ||
* A host identified by an IPv4 literal address is represented in | ||
* dotted-decimal notation (a sequence of four decimal numbers in the | ||
* range 0 to 255, separated by "."), as described in [RFC1123] by | ||
* reference to [RFC0952]. Note that other forms of dotted notation may | ||
* be interpreted on some platforms, as described in Section 7.4, but | ||
* only the dotted-decimal form of four octets is allowed by this | ||
* grammar. | ||
* | ||
* IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet | ||
* | ||
* @type {string} | ||
*/ | ||
var IPv4address = '(' + decOctect + '\\.){3}' + decOctect; | ||
/** | ||
* URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] | ||
* | ||
* OR | ||
* | ||
* relative-ref = relative-part [ "?" query ] [ "#" fragment ] | ||
*/ | ||
return new RegExp('^(?:' + scheme + ':' + rfc3986.hierPart + ')(?:\\?' + rfc3986.query + ')?(?:#' + rfc3986.fragment + ')?$'); | ||
}, | ||
uriRegex: new RegExp(rfc3986.uri) | ||
} | ||
}; | ||
/** | ||
* IPv6 Address (http://tools.ietf.org/html/rfc3986#page-20) | ||
* | ||
* A 128-bit IPv6 address is divided into eight 16-bit pieces. Each | ||
* piece is represented numerically in case-insensitive hexadecimal, | ||
* using one to four hexadecimal digits (leading zeroes are permitted). | ||
* The eight encoded pieces are given most-significant first, separated | ||
* by colon characters. Optionally, the least-significant two pieces | ||
* may instead be represented in IPv4 address textual format. A | ||
* sequence of one or more consecutive zero-valued 16-bit pieces within | ||
* the address may be elided, omitting all their digits and leaving | ||
* exactly two consecutive colons in their place to mark the elision. | ||
* | ||
* IPv6address = 6( h16 ":" ) ls32 | ||
* / "::" 5( h16 ":" ) ls32 | ||
* / [ h16 ] "::" 4( h16 ":" ) ls32 | ||
* / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32 | ||
* / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32 | ||
* / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32 | ||
* / [ *4( h16 ":" ) h16 ] "::" ls32 | ||
* / [ *5( h16 ":" ) h16 ] "::" h16 | ||
* / [ *6( h16 ":" ) h16 ] "::" | ||
* | ||
* ls32 = ( h16 ":" h16 ) / IPv4address ; least-significant 32 bits of address | ||
* | ||
* h16 = 1*4HEXDIG ; 16 bits of address represented in hexadecimal | ||
* | ||
* @type {string} | ||
*/ | ||
var h16 = '(' + hexDigitOnly + '){1,4}', | ||
ls32 = '(' + h16 + ':' + h16 + '|' + IPv4address + ')', | ||
IPv6SixHex = '(' + h16 + ':){6}' + ls32, | ||
IPv6FiveHex = '::(' + h16 + ':){5}' + ls32, | ||
IPv6FourHex = h16 + '::(' + h16 + ':){4}' + ls32, | ||
IPv6ThreeeHex = '(' + h16 + ':){0,1}' + h16 + '::(' + h16 + ':){3}' + ls32, | ||
IPv6TwoHex = '(' + h16 + ':){0,2}' + h16 + '::(' + h16 + ':){2}' + ls32, | ||
IPv6OneHex = '(' + h16 + ':){0,3}' + h16 + '::' + h16 + ':' + ls32, | ||
IPv6NoneHex = '(' + h16 + ':){0,4}' + h16 + '::' + ls32, | ||
IPv6NoneHex2 = '(' + h16 + ':){0,5}' + h16 + '::' + h16, | ||
IPv6NoneHex3 = '(' + h16 + ':){0,6}' + h16 + '::', | ||
IPv6address = '(' + IPv6SixHex + or + IPv6FiveHex + or + IPv6FourHex + or + IPv6ThreeeHex + or + IPv6TwoHex + or + IPv6OneHex + or + IPv6NoneHex + or + IPv6NoneHex2 + or + IPv6NoneHex3 + ')'; | ||
internals.Uri.isValid = function (val) { | ||
return internals.Uri.uriRegex.test(val); | ||
}; | ||
/** | ||
* IP Future Versions (http://tools.ietf.org/html/rfc3986#page-19) | ||
* | ||
* IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" ) | ||
* | ||
* @type {string} | ||
*/ | ||
var IPvFuture = '(v' + hexDigitOnly +'+\\.[' + unreserved + subDelims + ':]+)'; | ||
module.exports = { | ||
createUriRegex: internals.Uri.createUriRegex, | ||
/** | ||
* IP Literal (http://tools.ietf.org/html/rfc3986#page-19) | ||
* | ||
* A host identified by an Internet Protocol literal address, version 6 | ||
* [RFC3513] or later, is distinguished by enclosing the IP literal | ||
* within square brackets ("[" and "]"). This is the only place where | ||
* square bracket characters are allowed in the URI syntax. In | ||
* anticipation of future, as-yet-undefined IP literal address formats, | ||
* an implementation may use an optional version flag to indicate such a | ||
* format explicitly rather than rely on heuristic determination. | ||
* | ||
* IP-literal = "[" ( IPv6address / IPvFuture ) "]" | ||
* | ||
* @type {string} | ||
*/ | ||
var IPLiteral = '\\[(' + IPv6address + or + IPvFuture + ')\\]'; | ||
/** | ||
* Registered Name (http://tools.ietf.org/html/rfc3986#page-21) | ||
* | ||
* A registered name consists of a sequence of domain labels separated | ||
* by ".", each domain label starting and ending with an alphanumeric | ||
* character and possibly also containing "-" characters. The rightmost | ||
* domain label of a fully qualified domain name in DNS may be followed | ||
* by a single "." and should be if it is necessary to distinguish between | ||
* the complete domain name and some local domain. | ||
* | ||
* reg-name = *( unreserved / pct-encoded / sub-delims ) | ||
* | ||
* @type {string} | ||
*/ | ||
var regName = '[' + unreserved + pctEncoded + subDelims + ']{0,255}'; | ||
/** | ||
* Host (http://tools.ietf.org/html/rfc3986#page-18) | ||
* | ||
* The host subcomponent of authority is identified by an IP literal | ||
* encapsulated within square brackets, an IPv4 address in dotted- | ||
* decimal form, or a registered name. | ||
* | ||
* host = IP-literal / IPv4address / reg-name | ||
* | ||
* @type {string} | ||
*/ | ||
var host = '(' + IPLiteral + or + IPv4address + or + regName + ')'; | ||
/** | ||
* Port (http://tools.ietf.org/html/rfc3986#page-22) | ||
* | ||
* The port subcomponent of authority is designated by an optional port | ||
* number in decimal following the host and delimited from it by a | ||
* single colon (":") character. | ||
* | ||
* port = *DIGIT | ||
* | ||
* URI producers and normalizers should omit the port component and its | ||
* ":" delimiter if port is empty or if its value would be the same as | ||
* that of the scheme's default. | ||
* | ||
* @type {string} | ||
*/ | ||
var port = '(:' + digitOnly + '*)?'; | ||
/** | ||
* Authority (http://tools.ietf.org/html/rfc3986#page-17) | ||
* | ||
* The authority component is preceded by a double slash ("//") and is | ||
* terminated by the next slash ("/"), question mark ("?"), or number | ||
* sign ("#") character, or by the end of the URI. | ||
* | ||
* authority = [ userinfo "@" ] host [ ":" port ] | ||
* | ||
* URI producers and normalizers should omit the ":" delimiter that | ||
* separates host from port if the port component is empty. Some | ||
* schemes do not allow the userinfo and/or port subcomponents. | ||
* | ||
* If a URI contains an authority component, then the path component | ||
* must either be empty or begin with a slash ("/") character. | ||
* | ||
* @type {string} | ||
*/ | ||
var authority = '(([\\//]{2}[\\//]?)|(?=[^\/]))' + userinfo + host + port; | ||
/** | ||
* Path (http://tools.ietf.org/html/rfc3986#page-22) | ||
* | ||
* The path component contains data, usually organized in hierarchical | ||
* form, that, along with data in the non-hierarchical query component | ||
* (Section 3.4), serves to identify a resource within the scope of the | ||
* URI's scheme and naming authority (if any). The path is terminated | ||
* by the first question mark ("?") or number sign ("#") character, or | ||
* by the end of the URI. | ||
* If a URI contains an authority component, then the path component | ||
* must either be empty or begin with a slash ("/") character. | ||
* path = path-abempty ; begins with "/" or is empty | ||
* / path-absolute ; begins with "/" but not "//" | ||
* / path-noscheme ; begins with a non-colon segment | ||
* / path-rootless ; begins with a segment | ||
* / path-empty ; zero characters | ||
* path-abempty = *( "/" segment ) | ||
* path-absolute = "/" [ segment-nz *( "/" segment ) ] | ||
* path-noscheme = segment-nz-nc *( "/" segment ) | ||
* path-rootless = segment-nz *( "/" segment ) | ||
* path-empty = 0<pchar> | ||
* | ||
* segment = *pchar | ||
* segment-nz = 1*pchar | ||
* segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" ) | ||
* ; non-zero-length segment without any colon ":" | ||
* | ||
* @type {string} | ||
*/ | ||
var segment = pcharOnly + '*', | ||
segmentNz = pcharOnly + '+', | ||
segmentNzNc = '[' + unreserved + pctEncoded + subDelims + '@]+', | ||
pathAbEmpty = '(\\/' + segment + ')*', | ||
pathAbsolute = '\\/' + segmentNz + pathAbEmpty, | ||
pathNoScheme =segmentNzNc + pathAbEmpty, | ||
pathRootless = segmentNz + pathAbEmpty, | ||
path = '(\\/(' + pathAbEmpty + or + pathAbsolute + or + pathNoScheme + or + pathRootless + '))?'; | ||
/** | ||
* Query (http://tools.ietf.org/html/rfc3986#page-23) | ||
* | ||
* The query component contains non-hierarchical data that, along with | ||
* data in the path component (Section 3.3), serves to identify a | ||
* resource within the scope of the URI's scheme and naming authority | ||
* (if any). The query component is indicated by the first question | ||
* mark ("?") character and terminated by a number sign ("#") character | ||
* or by the end of the URI. | ||
* | ||
* query = *( pchar / "/" / "?" ) | ||
* | ||
* @type {string} | ||
*/ | ||
var query = '(\\?[' + pchar + '\\/\\?]*(?=#|$))?'; | ||
/** | ||
* Fragment (http://tools.ietf.org/html/rfc3986#page-24) | ||
* The fragment identifier component of a URI allows indirect | ||
* identification of a secondary resource by reference to a primary | ||
* resource and additional identifying information. The identified | ||
* secondary resource may be some portion or subset of the primary | ||
* resource, some view on representations of the primary resource, or | ||
* some other resource defined or described by those representations. A | ||
* fragment identifier component is indicated by the presence of a | ||
* number sign ("#") character and terminated by the end of the URI. | ||
* | ||
* fragment = *( pchar / "/" / "?" ) | ||
* | ||
* @type {string} | ||
*/ | ||
var fragment = '(#[' + pchar +'\\/\\?]*$)?'; | ||
var uriRegex = new RegExp(scheme + authority + path + query + fragment); | ||
function testUri(str) { | ||
return uriRegex.test(str); | ||
} | ||
module.exports = { | ||
test: testUri, | ||
regex: uriRegex | ||
}; | ||
}(module)); | ||
uriRegex: internals.Uri.uriRegex, | ||
isValid: internals.Uri.isValid | ||
}; |
{ | ||
"name": "isuri", | ||
"description": "Pure Javascript implementation for truly checking if the provided input is an URI. Based on RFC 3986.", | ||
"version": "1.1.0", | ||
"author": { | ||
"name" : "David Pate", | ||
"email" : "me@davidtpate.com", | ||
"url" : "http://davidtpate.com" | ||
}, | ||
"keywords": [ | ||
"uri", | ||
"url", | ||
"type", | ||
"checker", | ||
"validator", | ||
"validate" | ||
], | ||
"homepage": "https://github.com/DavidTPate/isuri", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/DavidTPate/isuri.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/DavidTPate/isuri/issues" | ||
}, | ||
"license": "MIT", | ||
"main": "index.js", | ||
"devDependencies": { | ||
"istanbul": "^0.x", | ||
"mocha": "^1.x", | ||
"should": "^4.x", | ||
"benchmark": "^1.x", | ||
"beautify-benchmark": "^0.x" | ||
}, | ||
"scripts": { | ||
"test": "mocha --check-leaks --bail --reporter spec test/", | ||
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --check-leaks --reporter dot test/", | ||
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --check-leaks --reporter spec test/" | ||
} | ||
"name": "isuri", | ||
"description": "Javascript implementation for truly checking if the provided input is a valid URI, Based on RFC 3986.", | ||
"version": "2.0.0", | ||
"author": { | ||
"name": "David Pate", | ||
"email": "me@davidtpate.com", | ||
"url": "http://davidtpate.com" | ||
}, | ||
"keywords": [ | ||
"uri", | ||
"url", | ||
"iri", | ||
"rfc3986", | ||
"3986" | ||
], | ||
"homepage": "https://github.com/DavidTPate/isuri", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/DavidTPate/isuri.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/DavidTPate/isuri/issues" | ||
}, | ||
"license": "MIT", | ||
"main": "index.js", | ||
"dependencies": { | ||
"rfc-3986": "1.0.1" | ||
}, | ||
"devDependencies": { | ||
"beautify-benchmark": "0.2.4", | ||
"benchmark": "2.1.0", | ||
"eslint": "2.5.3", | ||
"istanbul": "0.4.2", | ||
"jscs": "2.11.0", | ||
"jsinspect": "0.8.0", | ||
"mocha": "2.4.5", | ||
"webpack": "^.12.14" | ||
}, | ||
"scripts": { | ||
"cover": "istanbul cover _mocha -- --check-leaks --bail test && istanbul check-coverage --statements 100 --branches 100 --functions 100 --lines 100", | ||
"lint": "eslint . && jscs . && jsinspect .", | ||
"test": "npm run lint && npm run cover", | ||
"build": "webpack" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35661
1
8
15
79
1
+ Addedrfc-3986@1.0.1
+ Addedrfc-3986@1.0.1(transitive)