@analytics/url-utils
TypeScript icon, indicating that this package has built-in type declarations

0.2.3 • Public • Published

URL Utilities

A tiny utility library for working with URLs in 2.53kb.

This library will work with analytics or as a standalone package.

See live demo.

Why this package?

This package makes it a little easy to work with URLs

How to install

Install @analytics/url-utils from npm.

npm install @analytics/url-utils

API

Below is the api for @analytics/url-utils.

parseUrl

Parse a url parts

import { parseUrl } from '@analytics/url-utils'

parseUrl('https://www.cool.com/my-path/here?hello=true#my-hash=cool')
/*
{
  protocol: 'https',
  hostname: 'www.cool.com',
  port: '',
  path: '/my-path/here',
  query: 'hello=true',
  hash: 'my-hash=cool'
}
*/

getHost

Get host domain of url

import { getHost } from '@analytics/url-utils'

getHost('https://subdomain.my-site.com/')
// subdomain.my-site.com

getDomain

Get domain of url

import { getDomain } from '@analytics/url-utils'

getDomain('https://subdomain.my-site.com/')
// my-site.com

getSubDomain

Get sub-domain of url

import { getSubDomain } from '@analytics/url-utils'

getSubDomain('https://subdomain.my-site.com/')
// subdomain

trimTld

Trim TLD from domain name

import { trimTld } from '@analytics/url-utils'

trimTld('my-site.com')
// my-site

Alternative libs

  • If in node.js context, you can also use the native url module

Package Sidebar

Install

npm i @analytics/url-utils

Weekly Downloads

2,550

Version

0.2.3

License

MIT

Unpacked Size

268 kB

Total Files

22

Last publish

Collaborators

  • davidwells