1.2.9 • Published 10 months ago

@layered/superurl v1.2.9

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

🔗 @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

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

MIT

Copyright (c) Andrei Igna, Layered

1.2.8

10 months ago

1.2.9

10 months ago

1.2.7

10 months ago

1.2.6

10 months ago

1.2.5

10 months ago

1.2.4

10 months ago

1.2.3

10 months ago

1.2.2

10 months ago

1.2.0

10 months ago

1.2.1

10 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

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago