# get-url-parts

> Get the parts of the current URL

Latest version **1.1.1** (published 2020-01-06) · ISC license · 0 weekly downloads

## Install

```sh
npm install get-url-parts
pnpm add get-url-parts
yarn add get-url-parts
bun add get-url-parts
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2020-01-06 |
| First published | 2020-01-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Babak Gholamzadeh |
| Maintainers | babak.gh |
| Keywords | URL, parse, path, protocol, port, href, hash, host, query, anchor |

## Links

- npm: https://www.npmjs.com/package/get-url-parts
- Repository: https://github.com/Babak-Gholamzadeh/get-url-parts
- Homepage: https://github.com/Babak-Gholamzadeh/get-url-parts#readme
- Issues: https://github.com/Babak-Gholamzadeh/get-url-parts/issues
- npm.io page: https://npm.io/package/get-url-parts

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 1.1.1 (latest) — 2020-01-06
- 1.1.0 — 2020-01-06
- 1.0.3 — 2020-01-05
- 1.0.2 — 2020-01-03
- 1.0.1 — 2020-01-03
- 1.0.0 — 2020-01-03

## README

# get-url-parts
Get all parts of the current URL (Parse URL)

### Installation
```
npm i get-url-parts
```

### Example
```javascript
// Import the getURL Object which contains all the methods
import getURL from 'get-url-parts';

// For instance, the current URL in the browser is
// https://www.example.com:3000/search?key-1=value-1&key-2=value-2#section-3

// Returns the whole current URL (string)
// output: 'https://www.example.com:3000/search?key-1=value-1&key-2=value-2#section-3'
getURL.href();

// Returns the origin of the current URL (string)
// output: 'https://www.example.com:3000'
getURL.origin();

// Returns just the hostname without port (string)
// output: 'www.example.com'
getURL.host();

// Returns the port of the current URL (string)
// output: '3000'
getURL.port();

// Returns the protocol of the current URL (string)
// output: 'https:'
getURL.protocol();

// Returns the hash part of the current URL (string)
// output: '#section-3'
getURL.anchor();

// Returns the path of the current URL (string)
// output: '/search'
getURL.path();

// Returns the query string of the current URL (object)
// output: { "key-1": "value-1", "key-2": "value-2" }
getURL.query();

```

All the methods get the current URL from the address bar in browser, unless you give them your own (string) URL as their argument.

### Example
```javascript
// Put your own URL in a variable
const url = 'https://www.example.com:3000/search?key-1=value-1&key-2=value-2#section-3';
// Pass url to the methods as their argument
// and the output would be the same as the example above
getURL.host(url);
getURL.anchor(url);
getURL.query(url);
.
.
.
```

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