Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sindresorhus/get-urls
Get all urls in a string
https://github.com/sindresorhus/get-urls
Last synced: 1 day ago
JSON representation
Get all urls in a string
- Host: GitHub
- URL: https://github.com/sindresorhus/get-urls
- Owner: sindresorhus
- License: mit
- Created: 2014-02-14T19:45:05.000Z (almost 11 years ago)
- Default Branch: main
- Last Pushed: 2023-08-15T18:21:19.000Z (over 1 year ago)
- Last Synced: 2024-12-13T15:17:38.324Z (8 days ago)
- Language: JavaScript
- Size: 60.5 KB
- Stars: 365
- Watchers: 9
- Forks: 47
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- Funding: .github/funding.yml
- License: license
- Security: .github/security.md
Awesome Lists containing this project
- awesome-starred-test - sindresorhus/get-urls - Get all urls in a string (JavaScript)
README
# get-urls
> Get all URLs in a string
The URLs will be [normalized](https://github.com/sindresorhus/normalize-url).
*Do not use this for any kind of security-related validation.*
Please note the [known limitation](https://github.com/niftylettuce/url-regex-safe#limitations). You can work around this by setting `requireSchemeOrWww` to `true`.
## Install
```sh
npm install get-urls
```## Usage
```js
import getUrls from 'get-urls';const text = 'Lorem ipsum dolor sit amet, //sindresorhus.com consectetuer adipiscing http://yeoman.io elit.';
getUrls(text);
//=> Set {'http://sindresorhus.com', 'http://yeoman.io'}
```## API
### getUrls(text, options?)
Returns a `Set` of URLs.
### text
Type: `string`
### options
Type: `object`
All the `normalize-url` [options](https://github.com/sindresorhus/normalize-url#options) in addition to:
#### extractFromQueryString
Type: `boolean`\
Default: `false`Extract URLs that appear as query parameters in the found URLs.
#### exclude
Type: `string[]`\
Default: `[]`Exclude URLs that match URLs in the given array.
#### requireSchemeOrWww
Type: `boolean`\
Default: `false`Require URLs to have a scheme or leading `www.` to be considered an URL. When `false`, matches against a list of valid TLDs, so it will match URLs like `unicorn.education`.
Does not affect URLs in query parameters if using the `extractFromQueryString` option.
## Related
- [get-urls-cli](https://github.com/sindresorhus/get-urls-cli) - CLI for this module
- [linkify-urls](https://github.com/sindresorhus/linkify-urls) - Linkify URLs in text