# url-operator

> The library constrains URLs by types of the function parameters: - A `URL` parameter only accepts an absolute URL. - A `string` parameter accepts either an absolute URL or a relative URL.

Latest version **0.3.5** (published 2026-05-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install url-operator
pnpm add url-operator
yarn add url-operator
bun add url-operator
```

## Health

**Score 60/100 (C)** — status: active.

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

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.3.5 |
| Published | 2026-05-24 |
| First published | 2022-10-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=16 |
| Dependencies | 1 |
| Unpacked size | 21.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | BlackGlory |
| Maintainers | black_glory |

## Links

- npm: https://www.npmjs.com/package/url-operator
- Repository: https://github.com/BlackGlory/url-operator
- Homepage: https://github.com/BlackGlory/url-operator#readme
- Issues: https://github.com/BlackGlory/url-operator/issues
- npm.io page: https://npm.io/package/url-operator

## Dependencies (1)

- [@blackglory/prelude](https://npm.io/package/@blackglory/prelude.md) ^0.3.1

## Recent versions

- 0.3.5 (latest) — 2026-05-24
- 0.3.4 — 2026-05-11
- 0.3.3 — 2026-05-08
- 0.3.2 — 2026-02-14
- 0.3.1 — 2023-06-11
- 0.3.0 — 2023-02-21
- 0.2.1 — 2023-02-21
- 0.2.0 — 2023-02-21
- 0.1.1 — 2023-01-21
- 0.1.0 — 2022-10-24

## README

# url-operator
The library constrains URLs by types of the function parameters:
- A `URL` parameter only accepts an absolute URL.
- A `string` parameter accepts either an absolute URL or a relative URL.

## Install
```sh
npm install --save url-operator
# or
yarn add url-operator
```

## API
### setProtocol
```ts
function setProtocol(url: URL, protocol: string): URL
```

### setUsername
```ts
function setUsername(url: URL, username: string): URL
```

### setPassword
```ts
function setPassword(url: URL, password: string): URL
```

### setHost
```ts
function setHost(url: URL, host: string): URL
```

### setHostname
```ts
function setHostname(url: URL, hostname: string): URL
```

### setPort
```ts
function setPort(url: URL, port: number): URL
```

### setPathname
```ts
function setPathname(url: URL, pathname: string): URL
```

### appendPathname
```ts
function appendPathname(url: URL, pathname: string): URL
```

### setSearch
```ts
function setSearch(url: URL, search: string): URL
```

### setSearchParam
```ts
function setSearchParam(url: URL, name: string, value: string | number): URL
```

### setSearchParams
```ts
function setSearchParams(
  url: URL
, searchParams: Record<string, string | number | undefined>
): URL
```

### appendSearchParam
```ts
function appendSearchParam(url: URL, name: string, value: string | number): URL
```

### setHash
```ts
function setHash(url: URL, hash: string): URL
```

### encode
```ts
function encode(url: string): string
```

### decode
```ts
function decode(url: string): string
```

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