1.0.3 • Published 6 years ago

happy-url-regex v1.0.3

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

happy-url-regex

A regular expression for matching URLs.

npm.io

A fork of url-regex by Kevin Mårtensson, which is based on a gist by Diego Perini.

Why fork?

Because of a niche, client-side use case.

Webpack uglification would complain when using the original url-regex package as it contains ES6 arrow functions and template strings. I have opted to fork the repository and use babel rather than transpiling url-regex during webpack build.

Install

$ npm install --save happy-url-regex

or

$ yarn add happy-url-regex

Usage

import happyUrlRegex from 'happy-url-regex'

happyUrlRegex().test('http://github.com foo bar')
// true

happyUrlRegex().test('www.github.com foo bar')
// true

happyUrlRegex({ exact: true }).test('http://github.com foo bar')
// false

happyUrlRegex({ exact: true }).test('http://github.com')
// true

happyUrlRegex({ strict: false }).test('github.com foo bar')
// true

happyUrlRegex({ exact: true, strict: false }).test('github.com')
// true

'foo http://github.com bar //google.com'.match(happyUrlRegex())
// ['http://github.com', '//google.com']

API

happyUrlRegex(options)

Returns a regex for matching URLs.

options

exact

Type: boolean Default: false

Only match an exact string. Useful with RegExp#test to check if a string is a URL.

strict

Type: boolean Default: true

Force URLs to start with a valid protocol or www. If set to false it'll match the TLD against a list of valid TLDs.

Related

License

MIT © Kevin Mårtensson and Diego Perini

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago