# @analytics/url-utils

> Url utils

Latest version **0.2.5** (published 2025-08-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install @analytics/url-utils
pnpm add @analytics/url-utils
yarn add @analytics/url-utils
bun add @analytics/url-utils
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 0.2.5 |
| Published | 2025-08-07 |
| First published | 2022-02-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 264.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2666 |
| Author | David Wells |
| Maintainers | davidwells |
| Keywords | analytics, analytics-project, analytics-util |

## Links

- npm: https://www.npmjs.com/package/@analytics/url-utils
- Repository: https://github.com/DavidWells/analytics/tree/master/packages/analytics-util-url
- Homepage: https://github.com/DavidWells/analytics/tree/master/packages/analytics-util-url#readme
- npm.io page: https://npm.io/package/@analytics/url-utils

## Dependencies (1)

- [@analytics/type-utils](https://npm.io/package/@analytics/type-utils.md) ^0.6.4

## Recent versions

- 0.2.5 (latest) — 2025-08-07
- 0.2.4 — 2025-08-06
- 0.2.3 — 2023-05-27
- 0.2.2 — 2023-05-27
- 0.2.1 — 2022-03-18
- 0.2.0 — 2022-02-16
- 0.1.1 — 2022-02-16
- 0.1.0 — 2022-02-13
- 0.0.1 — 2022-02-11

## README

<!--
title: Javascript URL utils
pageTitle: URL Utils
description: Utility library for working with URLs
-->

# URL Utilities

A tiny utility library for working with URLs in <!-- AUTO-GENERATED-CONTENT:START (pkgSize) -->`2.53kb`<!-- AUTO-GENERATED-CONTENT:END -->.

This library will work with [analytics](https://getanalytics.io) or as a standalone package.

[See live demo](https://utils-url.netlify.app/).

### Why this package?

This package makes it a little easy to work with URLs

## How to install

Install `@analytics/url-utils` from [npm](https://www.npmjs.com/package/@analytics/url-utils).

```bash
npm install @analytics/url-utils
```

## API

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

## `parseUrl`

Parse a url parts

```js
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

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

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

## `getDomain`

Get domain of url

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

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

## `getSubDomain`

Get sub-domain of url

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

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

## `trimTld`

Trim TLD from domain name

```js
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

---
_Source: https://npm.io/package/@analytics/url-utils · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
