@layered/superurl is a JavaScript library that can clean and extract info from URLs.
- Removes tracking parameters
- Adds protocol if missing, upgrades to https if domain requires it
- Extracts infos (handle, IDs, usernames) from URLs without network requests
npm i @layered/superurl
const { sanitizeUrl, urlInfo } = require('@layered/superurl')
const cleanUrl = sanitizeUrl('example.com/path?utc_campaign=upgrade')
// returns https://example.com/path
const infos = sanitizeUrl('http://twitter.com/elonmusk')
// returns
{
originalUrl: 'http://mobile.twitter.com/elonmusk',
url: 'https://twitter.com/elonmusk',
hostname: 'twitter.com',
domain: 'twitter.com',
subdomain: '',
handle: 'elonmusk',
providerId: null,
}
sanitizeUrl(url, options)
- Sanitize/clean URLurlInfo(url, options)
- Extract data from URL
Sanitize/clean URL
sanitizeUrl(url: string | URL, options): string
url
- URL to sanitize, can be string or URL. Ex: 'google.com'options
- Object of options to use, all optional:allowedProtocols[]
- What protocols are allowed for URL. Default:['http:', 'https:']
Extract data from URL, without network requests.
urlInfo(url: string | URL, options): string
url
- URL to check, can be string or URL. Ex: 'twitter.com/twitter'options
- Object of options to use, all optional:allowedProtocols[]
- What protocols are allowed for URL. Default:['http:', 'https:']
Please report any issues here on GitHub. Any contributions are welcome
Copyright (c) Andrei Igna, Layered