[
  {
    "path": ".editorconfig",
    "content": "root = true\n\n[*]\nindent_style = tab\nend_of_line = lf\ncharset = utf-8\ntrim_trailing_whitespace = true\ninsert_final_newline = true\n\n[*.yml]\nindent_style = space\nindent_size = 2\n"
  },
  {
    "path": ".gitattributes",
    "content": "* text=auto eol=lf\n"
  },
  {
    "path": ".gitignore",
    "content": "node_modules\nyarn.lock\n"
  },
  {
    "path": ".npmrc",
    "content": "package-lock=false\n"
  },
  {
    "path": ".travis.yml",
    "content": "language: node_js\nnode_js:\n  - '10'\n  - '8'\n"
  },
  {
    "path": "index.d.ts",
    "content": "declare namespace urlRegex {\n\tinterface Options {\n\t\t/**\n\t\tOnly match an exact string. Useful with `RegExp#test` to check if a string is a URL.\n\n\t\t@default false\n\t\t*/\n\t\treadonly exact?: boolean;\n\n\t\t/**\n\t\tForce URLs to start with a valid protocol or `www`. If set to `false` it'll match the TLD against a list of valid [TLDs](https://github.com/stephenmathieson/node-tlds).\n\n\t\t@default true\n\t\t*/\n\t\treadonly strict?: boolean;\n\t}\n}\n\n/**\nRegular expression for matching URLs.\n\n@example\n```\nimport urlRegex = require('url-regex');\n\nurlRegex().test('http://github.com foo bar');\n//=> true\n\nurlRegex().test('www.github.com foo bar');\n//=> true\n\nurlRegex({exact: true}).test('http://github.com foo bar');\n//=> false\n\nurlRegex({exact: true}).test('http://github.com');\n//=> true\n\nurlRegex({strict: false}).test('github.com foo bar');\n//=> true\n\nurlRegex({exact: true, strict: false}).test('github.com');\n//=> true\n\n'foo http://github.com bar //google.com'.match(urlRegex());\n//=> ['http://github.com', '//google.com']\n```\n*/\ndeclare function urlRegex(options?: urlRegex.Options): RegExp;\n\nexport = urlRegex;\n"
  },
  {
    "path": "index.js",
    "content": "'use strict';\nconst ipRegex = require('ip-regex');\nconst tlds = require('tlds');\n\nmodule.exports = options => {\n\toptions = {\n\t\tstrict: true,\n\t\t...options\n\t};\n\n\tconst protocol = `(?:(?:[a-z]+:)?//)${options.strict ? '' : '?'}`;\n\tconst auth = '(?:\\\\S+(?::\\\\S*)?@)?';\n\tconst ip = ipRegex.v4().source;\n\tconst host = '(?:(?:[a-z\\\\u00a1-\\\\uffff0-9][-_]*)*[a-z\\\\u00a1-\\\\uffff0-9]+)';\n\tconst domain = '(?:\\\\.(?:[a-z\\\\u00a1-\\\\uffff0-9]-*)*[a-z\\\\u00a1-\\\\uffff0-9]+)*';\n\tconst tld = `(?:\\\\.${options.strict ? '(?:[a-z\\\\u00a1-\\\\uffff]{2,})' : `(?:${tlds.sort((a, b) => b.length - a.length).join('|')})`})\\\\.?`;\n\tconst port = '(?::\\\\d{2,5})?';\n\tconst path = '(?:[/?#][^\\\\s\"]*)?';\n\tconst regex = `(?:${protocol}|www\\\\.)${auth}(?:localhost|${ip}|${host}${domain}${tld})${port}${path}`;\n\n\treturn options.exact ? new RegExp(`(?:^${regex}$)`, 'i') : new RegExp(regex, 'ig');\n};\n"
  },
  {
    "path": "index.test-d.ts",
    "content": "import {expectType} from 'tsd';\nimport urlRegex = require('.');\n\nexpectType<RegExp>(urlRegex());\nexpectType<RegExp>(urlRegex({exact: true}));\nexpectType<RegExp>(urlRegex({strict: false}));\n"
  },
  {
    "path": "license",
    "content": "The MIT License (MIT)\n\nCopyright (c) Kevin Mårtensson <kevinmartensson@gmail.com> and Diego Perini\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n"
  },
  {
    "path": "package.json",
    "content": "{\n\t\"name\": \"url-regex\",\n\t\"version\": \"5.0.0\",\n\t\"description\": \"Regular expression for matching URLs\",\n\t\"license\": \"MIT\",\n\t\"repository\": \"kevva/url-regex\",\n\t\"author\": {\n\t\t\"name\": \"Kevin Mårtensson\",\n\t\t\"email\": \"kevinmartensson@gmail.com\",\n\t\t\"url\": \"https://github.com/kevva\"\n\t},\n\t\"engines\": {\n\t\t\"node\": \">=8\"\n\t},\n\t\"scripts\": {\n\t\t\"test\": \"xo && ava && tsd\"\n\t},\n\t\"files\": [\n\t\t\"index.js\",\n\t\t\"index.d.ts\"\n\t],\n\t\"keywords\": [\n\t\t\"regex\",\n\t\t\"string\",\n\t\t\"url\"\n\t],\n\t\"dependencies\": {\n\t\t\"ip-regex\": \"^4.1.0\",\n\t\t\"tlds\": \"^1.203.0\"\n\t},\n\t\"devDependencies\": {\n\t\t\"ava\": \"^1.4.1\",\n\t\t\"tsd\": \"^0.7.2\",\n\t\t\"xo\": \"^0.24.0\"\n\t}\n}\n"
  },
  {
    "path": "readme.md",
    "content": "# url-regex [![Build Status](http://img.shields.io/travis/kevva/url-regex.svg?style=flat)](https://travis-ci.org/kevva/url-regex)\n\n> Regular expression for matching URLs\n\nBased on this [gist](https://gist.github.com/dperini/729294) by Diego Perini.\n\n\n## Install\n\n```\n$ npm install url-regex\n```\n\n\n## Usage\n\n```js\nconst urlRegex = require('url-regex');\n\nurlRegex().test('http://github.com foo bar');\n//=> true\n\nurlRegex().test('www.github.com foo bar');\n//=> true\n\nurlRegex({exact: true}).test('http://github.com foo bar');\n//=> false\n\nurlRegex({exact: true}).test('http://github.com');\n//=> true\n\nurlRegex({strict: false}).test('github.com foo bar');\n//=> true\n\nurlRegex({exact: true, strict: false}).test('github.com');\n//=> true\n\n'foo http://github.com bar //google.com'.match(urlRegex());\n//=> ['http://github.com', '//google.com']\n```\n\n\n## API\n\n### urlRegex([options])\n\nReturns a `RegExp` for matching URLs.\n\n#### options\n\n##### exact\n\nType: `boolean`<br>\nDefault: `false`\n\nOnly match an exact string. Useful with `RegExp#test` to check if a string is a URL.\n\n##### strict\n\nType: `boolean`<br>\nDefault: `true`\n\nForce URLs to start with a valid protocol or `www`. If set to `false` it'll match the TLD against a list of valid [TLDs](https://github.com/stephenmathieson/node-tlds).\n\n\n## Related\n\n- [get-urls](https://github.com/sindresorhus/get-urls) - Get all URLs in text\n- [linkify-urls](https://github.com/sindresorhus/linkify-urls) - Linkify URLs in text\n\n\n## License\n\nMIT © [Kevin Mårtensson](https://github.com/kevva) and [Diego Perini](https://github.com/dperini)\n"
  },
  {
    "path": "test.js",
    "content": "import test from 'ava';\nimport urlRegex from '.';\n\ntest('match exact URLs', t => {\n\tconst fixtures = [\n\t\t'http://foo.com/blah_blah',\n\t\t'http://foo.com/blah_blah/',\n\t\t'http://foo.com/blah_blah_(wikipedia)',\n\t\t'http://foo.com/blah_blah_(wikipedia)_(again)',\n\t\t'http://www.example.com/wpstyle/?p=364',\n\t\t'https://www.example.com/foo/?bar=baz&inga=42&quux',\n\t\t'http://a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.com',\n\t\t'http://a_b.z.com',\n\t\t'http://mw1.google.com/mw-earth-vectordb/kml-samples/gp/seattle/gigapxl/$[level]/r$[y]_c$[x].jpg',\n\t\t'http://user:pass@example.com:123/one/two.three?q1=a1&q2=a2#body',\n\t\t'http://www.microsoft.xn--comindex-g03d.html.irongeek.com',\n\t\t'http://✪df.ws/123',\n\t\t'http://localhost/',\n\t\t'http://userid:password@example.com:8080',\n\t\t'http://userid:password@example.com:8080/',\n\t\t'http://userid@example.com',\n\t\t'http://userid@example.com/',\n\t\t'http://userid@example.com:8080',\n\t\t'http://userid@example.com:8080/',\n\t\t'http://userid:password@example.com',\n\t\t'http://userid:password@example.com/',\n\t\t'http://142.42.1.1/',\n\t\t'http://142.42.1.1:8080/',\n\t\t'http://➡.ws/䨹',\n\t\t'http://⌘.ws',\n\t\t'http://⌘.ws/',\n\t\t'http://foo.com/blah_(wikipedia)#cite-1',\n\t\t'http://foo.com/blah_(wikipedia)_blah#cite-1',\n\t\t'http://foo.com/unicode_(✪)_in_parens',\n\t\t'http://foo.com/(something)?after=parens',\n\t\t'http://☺.damowmow.com/',\n\t\t'http://code.google.com/events/#&product=browser',\n\t\t'http://j.mp',\n\t\t'ftp://foo.bar/baz',\n\t\t'http://foo.bar/?q=Test%20URL-encoded%20stuff',\n\t\t'http://مثال.إختبار',\n\t\t'http://例子.测试',\n\t\t'http://उदाहरण.परीक्षा',\n\t\t'http://-.~_!$&\\'()*+\\';=:%40:80%2f::::::@example.com',\n\t\t'http://1337.net',\n\t\t'http://a.b-c.de',\n\t\t'http://223.255.255.254',\n\t\t'http://example.com?foo=bar',\n\t\t'http://example.com#foo',\n\t\t'ws://localhost:8080',\n\t\t'ws://foo.ws',\n\t\t'ws://a.b-c.de',\n\t\t'ws://223.255.255.254',\n\t\t'ws://userid:password@example.com',\n\t\t'ws://➡.ws/䨹',\n\t\t'//localhost:8080',\n\t\t'//foo.ws',\n\t\t'//a.b-c.de',\n\t\t'//223.255.255.254',\n\t\t'//userid:password@example.com',\n\t\t'//➡.ws/䨹',\n\t\t'www.google.com/unicorn',\n\t\t'http://example.com.'\n\t];\n\n\tfor (const x of fixtures) {\n\t\tt.true(urlRegex({exact: true}).test(x));\n\t}\n});\n\ntest('match URLs in text', t => {\n\tconst fixture = `\n\t\tLorem ipsum //dolor.sit\n\t\t<a href=\"http://example.com\">example.com</a>\n\t\t<a href=\"http://example.com/with-path\">with path</a>\n\t\t[and another](https://another.example.com) and\n\t\tFoo //bar.net/?q=Query with spaces\n\t`;\n\n\tt.deepEqual([\n\t\t'//dolor.sit',\n\t\t'http://example.com',\n\t\t'http://example.com/with-path',\n\t\t'https://another.example.com',\n\t\t'//bar.net/?q=Query'\n\t], fixture.match(urlRegex()));\n});\n\ntest('do not match URLs', t => {\n\tconst fixtures = [\n\t\t'http://',\n\t\t'http://.',\n\t\t'http://..',\n\t\t'http://../',\n\t\t'http://?',\n\t\t'http://??',\n\t\t'http://??/',\n\t\t'http://#',\n\t\t'http://##',\n\t\t'http://##/',\n\t\t'http://foo.bar?q=Spaces should be encoded',\n\t\t'//',\n\t\t'//a',\n\t\t'///a',\n\t\t'///',\n\t\t'http:///a',\n\t\t'foo.com',\n\t\t'rdar://1234',\n\t\t'h://test',\n\t\t'http:// shouldfail.com',\n\t\t':// should fail',\n\t\t'http://foo.bar/foo(bar)baz quux',\n\t\t'http://-error-.invalid/',\n\t\t'http://-a.b.co',\n\t\t'http://a.b-.co',\n\t\t'http://123.123.123',\n\t\t'http://3628126748',\n\t\t'http://.www.foo.bar/',\n\t\t'http://.www.foo.bar./',\n\t\t'http://go/ogle.com',\n\t\t'http://foo.bar/ /',\n\t\t'http://a.b_z.com',\n\t\t'http://ab_.z.com',\n\t\t'http://google\\\\.com',\n\t\t'http://www(google.com',\n\t\t'http://www.example.xn--overly-long-punycode-test-string-test-tests-123-test-test123/',\n\t\t'http://www=google.com',\n\t\t'https://www.g.com/error\\n/bleh/bleh',\n\t\t'rdar://1234',\n\t\t'/foo.bar/',\n\t\t'///www.foo.bar./'\n\t];\n\n\tfor (const x of fixtures) {\n\t\tt.false(urlRegex({exact: true}).test(x));\n\t}\n});\n\ntest('match using list of TLDs', t => {\n\tconst fixtures = [\n\t\t'foo.com/blah_blah',\n\t\t'foo.com/blah_blah/',\n\t\t'foo.com/blah_blah_(wikipedia)',\n\t\t'foo.com/blah_blah_(wikipedia)_(again)',\n\t\t'www.example.com/wpstyle/?p=364',\n\t\t'www.example.com/foo/?bar=baz&inga=42&quux',\n\t\t'a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.com',\n\t\t'mw1.google.com/mw-earth-vectordb/kml-samples/gp/seattle/gigapxl/$[level]/r$[y]_c$[x].jpg',\n\t\t'user:pass@example.com:123/one/two.three?q1=a1&q2=a2#body',\n\t\t'www.microsoft.xn--comindex-g03d.html.irongeek.com',\n\t\t'✪df.ws/123',\n\t\t'localhost/',\n\t\t'userid:password@example.com:8080',\n\t\t'userid:password@example.com:8080/',\n\t\t'userid@example.com',\n\t\t'userid@example.com/',\n\t\t'userid@example.com:8080',\n\t\t'userid@example.com:8080/',\n\t\t'userid:password@example.com',\n\t\t'userid:password@example.com/',\n\t\t'142.42.1.1/',\n\t\t'142.42.1.1:8080/',\n\t\t'➡.ws/䨹',\n\t\t'⌘.ws',\n\t\t'⌘.ws/',\n\t\t'foo.com/blah_(wikipedia)#cite-1',\n\t\t'foo.com/blah_(wikipedia)_blah#cite-1',\n\t\t'foo.com/unicode_(✪)_in_parens',\n\t\t'foo.com/(something)?after=parens',\n\t\t'☺.damowmow.com/',\n\t\t'code.google.com/events/#&product=browser',\n\t\t'j.mp',\n\t\t'foo.bar/baz',\n\t\t'foo.bar/?q=Test%20URL-encoded%20stuff',\n\t\t'-.~_!$&\\'()*+\\';=:%40:80%2f::::::@example.com',\n\t\t'1337.net',\n\t\t'a.b-c.de',\n\t\t'223.255.255.254',\n\t\t'example.com?foo=bar',\n\t\t'example.com#foo',\n\t\t'localhost:8080',\n\t\t'foo.ws',\n\t\t'a.b-c.de',\n\t\t'223.255.255.254',\n\t\t'userid:password@example.com',\n\t\t'➡.ws/䨹',\n\t\t'//localhost:8080',\n\t\t'//foo.ws',\n\t\t'//a.b-c.de',\n\t\t'//223.255.255.254',\n\t\t'//userid:password@example.com',\n\t\t'//➡.ws/䨹',\n\t\t'www.google.com/unicorn',\n\t\t'example.com.'\n\t];\n\n\tfor (const x of fixtures) {\n\t\tt.true(urlRegex({exact: true, strict: false}).test(x));\n\t}\n});\n"
  }
]