diff --git a/index.js b/index.js index a77d263..cb3160b 100644 --- a/index.js +++ b/index.js @@ -2,21 +2,20 @@ const ipRegex = require('ip-regex'); const tlds = require('tlds'); -module.exports = options => { - options = { - strict: true, - ...options - }; +module.exports = function (options) { + options = Object.assign({strict: true}, options); - const protocol = `(?:(?:[a-z]+:)?//)${options.strict ? '' : '?'}`; - const auth = '(?:\\S+(?::\\S*)?@)?'; - const ip = ipRegex.v4().source; - const host = '(?:(?:[a-z\\u00a1-\\uffff0-9][-_]*)*[a-z\\u00a1-\\uffff0-9]+)'; - const domain = '(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*'; - const tld = `(?:\\.${options.strict ? '(?:[a-z\\u00a1-\\uffff]{2,})' : `(?:${tlds.sort((a, b) => b.length - a.length).join('|')})`})\\.?`; - const port = '(?::\\d{2,5})?'; - const path = '(?:[/?#][^\\s"]*)?'; - const regex = `(?:${protocol}|www\\.)${auth}(?:localhost|${ip}|${host}${domain}${tld})${port}${path}`; + var protocol = `(?:(?:[a-z]+:)?//)${options.strict ? '' : '?'}`; + var auth = '(?:\\S+(?::\\S*)?@)?'; + var ip = ipRegex.v4().source; + var host = '(?:(?:[a-z\\u00a1-\\uffff0-9][-_]*)*[a-z\\u00a1-\\uffff0-9]+)'; + var domain = '(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*'; + var tld = `(?:\\.${options.strict ? '(?:[a-z\\u00a1-\\uffff]{2,})' : `(?:${tlds.sort(function (a, b) { + return b.length - a.length; + }).join('|')})`})\\.?`; + var port = '(?::\\d{2,5})?'; + var path = '(?:[/?#][^\\s"]*)?'; + var regex = `(?:${protocol}|www\\.)${auth}(?:localhost|${ip}|${host}${domain}${tld})${port}${path}`; return options.exact ? new RegExp(`(?:^${regex}$)`, 'i') : new RegExp(regex, 'ig'); }; diff --git a/package.json b/package.json index 4854ba7..4bd1b12 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,12 @@ { - "name": "url-regex", + "name": "@tactivos/url-regex", "version": "5.0.0", "description": "Regular expression for matching URLs", "license": "MIT", - "repository": "kevva/url-regex", + "repository": { + "type": "git", + "url": "git://github.com/tactivos/url-regex.git" + }, "author": { "name": "Kevin MÃ¥rtensson", "email": "kevinmartensson@gmail.com", @@ -32,5 +35,12 @@ "ava": "^1.4.1", "tsd": "^0.7.2", "xo": "^0.24.0" + }, + "xo": { + "rules": { + "prefer-object-spread": 0, + "prefer-arrow-callback": 0, + "no-var": 0 + } } } diff --git a/readme.md b/readme.md index 6b343a1..c7e2913 100644 --- a/readme.md +++ b/readme.md @@ -2,6 +2,11 @@ > Regular expression for matching URLs +## Source + +Forked from [url-regex](https://github.com/kevva/url-regex) so we can improve the compability with IE11 or other browsers. +Needed for consuming it from surface hubs or windows app. + Based on this [gist](https://gist.github.com/dperini/729294) by Diego Perini.