# node-url-path

> Class to help joining URLs and adding query parameters.

Latest version **1.0.1** (published 2023-08-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install node-url-path
pnpm add node-url-path
yarn add node-url-path
bun add node-url-path
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2023-08-23 |
| First published | 2023-08-23 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 13.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jake Cyr |
| Maintainers | jakecyr |

## Links

- npm: https://www.npmjs.com/package/node-url-path
- npm.io page: https://npm.io/package/node-url-path

## Dependencies (1)

- [qs](https://npm.io/package/qs.md) ^6.11.2

## Recent versions

- 1.0.1 (latest) — 2023-08-23
- 1.0.0 — 2023-08-23

## README

# Node URL Path

Simple utility class to help join URLs and add query parameters to URLs similar to how Python's pathlib Path object works with file paths.

## Installation

Install the latest version using `npm` with:

```bash
npm install node-url-path
```

## Usage

Using the `URLPath` class makes working with URLs simple. You can add paths to a URL that already has query parameters added to it and add additional query parameters if needed with the call of a method.

All `URLPath` methods return a `URLPath` instance so you can chain them together.

Get the final URL from a `URLPath` instance by retrieving the public `href` property.

```typescript
import { URLPath } from 'node-url-path';

const urlPath = new URLPath('https://google.com/api/')
  .joinPath('/query')
  .addQueryParams({
    query: 'How to make URLs easier when working with Node',
    apiKey: '1234567890',
  });

console.log(urlPath.href);

// Outputs:
// https://google.com/api/query?query=How%20to%20make%20URLs%20easier%20when%20working%20with%20Node&apiKey=1234567890
```

or a more complex example:

```typescript
import { URLPath } from 'node-url-path';

const urlPath = new URLPath('https://google.com/api/?someExistingParams=1')
  .joinPath('/query')
  .addQueryParams({
    query: 'How to make URLs easier when working with Node',
    apiKey: '1234567890',
  });

console.log(urlPath.href);

// Outputs:
// https://google.com/api/query?someExistingParams=1&query=How%20to%20make%20URLs%20easier%20when%20working%20with%20Node&apiKey=1234567890
```

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