diff --git a/package.json b/package.json index c6a1170..4a2acd4 100644 --- a/package.json +++ b/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", diff --git a/src/regex.js b/src/regex.js index b67a54c..6bd39c4 100644 --- a/src/regex.js +++ b/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}*)?)?`; diff --git a/test/matches.json b/test/matches.json index 5e02d2e..1a27acd 100644 --- a/test/matches.json +++ b/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/"