Comparing version
25
index.js
'use strict'; | ||
var tlds = require('./tlds.json').join('|'); | ||
/** | ||
@@ -10,3 +12,24 @@ * Regular expression for matching URLs | ||
module.exports = function () { | ||
return /(?:^|\s)(["'])?(?:(?:(?:(?:https?|ftp|\w):)?\/\/)|(?:www.))(?:\S+(?::\S*)?@)?(?:(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/\S*)?\1/ig; | ||
var auth = '(?:\\S+(?::\\S*)?@)?'; | ||
var domain = '(?:\\.(?:xn--[a-z0-9\\-]{1,59}|(?:[a-z\\u00a1-\\uffff0-9]+-?){0,62}[a-z\\u00a1-\\uffff0-9]{1,63}))*'; | ||
var host = '(?:xn--[a-z0-9\\-]{1,59}|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?){0,62}[a-z\\u00a1-\\uffff0-9]{1,63}))'; | ||
var path = '(?:/[^\\s]*)?'; | ||
var port = '(?::\\d{2,5})?'; | ||
var protocol = '(?:(?:(?:https?|ftp):)?\/\/)?'; | ||
var tld = '(?:\\.(?:xn--[a-z0-9\\-]{1,59}|' + tlds + '+))'; | ||
var ips = [ | ||
'(?!10(?:\\.\\d{1,3}){3})', | ||
'(?!127(?:\\.\\d{1,3}){3})', | ||
'(?!169\\.254(?:\\.\\d{1,3}){2})', | ||
'(?!192\\.168(?:\\.\\d{1,3}){2})', | ||
'(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})', | ||
'(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])', | ||
'(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}', | ||
'(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))' | ||
].join(''); | ||
return new RegExp([ | ||
'(?:^|\\s)(["\'])?' + protocol + auth + '(?:' + ips + '|', | ||
'(?:localhost)|' + host + domain + tld + ')' + port + path + '\\1' | ||
].join(''), 'ig'); | ||
}; |
{ | ||
"name": "url-regex", | ||
"version": "1.0.4", | ||
"version": "2.0.0", | ||
"description": "Regular expression for matching URLs", | ||
@@ -16,6 +16,9 @@ "license": "MIT", | ||
"scripts": { | ||
"prepublish": "node lib/index.js", | ||
"pretest": "node lib/index.js", | ||
"test": "node test.js" | ||
}, | ||
"files": [ | ||
"index.js" | ||
"index.js", | ||
"tlds.json" | ||
], | ||
@@ -27,5 +30,9 @@ "keywords": [ | ||
], | ||
"dependencies": { | ||
"ip-regex": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "0.0.4" | ||
"ava": "^0.0.4", | ||
"tlds": "^1.14.0" | ||
} | ||
} |
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
9379
450.09%5
66.67%30
200%0
-100%1
Infinity%2
100%+ Added
+ Added