Browse Source

Add proper support for all TLDs from ICANN

pull/1/merge
Luke Childs 9 years ago
parent
commit
27a1bfe4fb
  1. 4
      package.json
  2. 4
      src/regex.js
  3. 4
      test/matches.json

4
package.json

@ -3,7 +3,9 @@
"version": "0.0.0",
"description": "Surprisingly accurate URL grabber",
"main": "dist/my-name-is-url.js",
"dependencies": {},
"dependencies": {
"tlds": "^1.110.0"
},
"devDependencies": {
"babel-cli": "^6.7.5",
"babel-plugin-add-module-exports": "^0.1.2",

4
src/regex.js

@ -1,3 +1,5 @@
import tlds from 'tlds';
// Reusables
const escapeChar = `\\`;
const notWhitespaceOrComma = `[^${escapeChar}s,]`;
@ -6,7 +8,7 @@ const WhitespaceCommaDotOrEndOfLine = `[${escapeChar}s,.]|$`;
const number = `[0-9]`;
// Sections
const hostname = `(${notWhitespaceOrComma}*${escapeChar}.(com|ninja))`;
const hostname = `(${notWhitespaceOrComma}*${escapeChar}.(${tlds.join('|')}))`;
const ip = `(${number}{1,3}${escapeChar}.){3}${number}{1,3}`;
const optionalPortNumber = `(:${number}+)?`;
const optionalSlash = `(${escapeChar}/(${notWhitespaceCommaOrDot}*)?)?`;

4
test/matches.json

@ -15,6 +15,10 @@
"description": "Url with no scheme",
"url": "url.com"
},
{
"description": "Url with gTLD",
"url": "url.website"
},
{
"description": "Url with trailing slash",
"url": "url.com/"

Loading…
Cancel
Save