1.2.9 • Published 9 months ago
@layered/superurl v1.2.9
🔗 @layered/superurl
@layered/superurl is a JavaScript library that can clean and extract info from URLs.
Highlights
- Removes tracking parameters
- Adds protocol if missing, upgrades to https if domain requires it
- Extracts infos (handle, IDs, usernames) from URLs without network requests
Getting Started
Installation
npm i @layered/superurl
Usage
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,
}
APIs
sanitizeUrl(url, options)
- Sanitize/clean URLurlInfo(url, options)
- Extract data from URL
Sanitize 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:']
URL info
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:']
More
Please report any issues here on GitHub. Any contributions are welcome
License
Copyright (c) Andrei Igna, Layered
1.2.8
9 months ago
1.2.9
9 months ago
1.2.7
9 months ago
1.2.6
9 months ago
1.2.5
9 months ago
1.2.4
9 months ago
1.2.3
9 months ago
1.2.2
9 months ago
1.2.0
9 months ago
1.2.1
9 months ago
1.1.12
1 year ago
1.1.11
1 year ago
1.1.1
2 years ago
1.1.0
2 years ago
1.1.9
2 years ago
1.1.8
2 years ago
1.1.7
2 years ago
1.1.6
2 years ago
1.1.5
2 years ago
1.1.4
2 years ago
1.1.3
2 years ago
1.1.2
2 years ago
1.1.10
2 years ago
1.0.4
2 years ago
1.0.3
2 years ago
1.0.2
2 years ago
1.0.1
3 years ago
1.0.0
3 years ago