urlex

1.0.0 • Public • Published

urlex

A lightweight package to identify and extract URLs from text.

Unicode support

Usage

Returns an array of all URLs found in the input text.

import urlex from 'urlex'

const text = 'Visit http://example.com/home for details.'
const response = urlex(text)
console.log(response)
// [ 'http://example.com/home' ]

To get the parts of the URL, use the needParts option.

import urlex from 'urlex'

const text = 'Visit http://example.com/home for details.'
const response = urlex(text, { needParts: true })
console.log(response)
// [
//   {
//     url: 'http://example.com',
//     protocol: 'http://',
//     auth: '',
//     ip: '',
//     subdomain: '',
//     domain: 'example.com',
//     tld: 'com',
//     port: '',
//     path: '/home',
//   }
// ]

To match the url without protocol, use the withProtocol option.

import urlex from 'urlex'

const text = 'Visit example.com/home for details.'
const response = urlex(text, { withProtocol: false })
console.log(response)
// [ 'example.com/home' ]

To match other protocols, use the webOnly option.

import urlex from 'urlex'

const text = 'Send mail to smtp://test.com/home for details.'
const response = urlex(text, { webOnly: false })
console.log(response)
// [ 'smtp://test.com/home' ]

Credits

Readme

Keywords

Package Sidebar

Install

npm i urlex

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

149 kB

Total Files

7

Last publish

Collaborators

  • shubhamsaw