# @synonymdev/slashtags-url

> Encodes and decodes Slashtags URLs

Latest version **1.0.1** (published 2023-11-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install @synonymdev/slashtags-url
pnpm add @synonymdev/slashtags-url
yarn add @synonymdev/slashtags-url
bun add @synonymdev/slashtags-url
```

## 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-11-16 |
| First published | 2021-09-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 7.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | rbndg, jayvdb, nzh |

## Links

- npm: https://www.npmjs.com/package/@synonymdev/slashtags-url
- Repository: https://github.com/slashtags/url
- Homepage: https://github.com/slashtags/url/tree/master/#readme
- Issues: https://github.com/slashtags/url/issues
- npm.io page: https://npm.io/package/@synonymdev/slashtags-url

## Dependencies (2)

- [b4a](https://npm.io/package/b4a.md) ^1.6.0
- [z32](https://npm.io/package/z32.md) ^1.0.0

## Recent versions

- 1.0.1 (latest) — 2023-11-16
- 1.0.0 — 2023-09-08
- 1.0.0-alpha.4 — 2023-08-29
- 1.0.0-alpha.3 — 2023-05-01
- 1.0.0-wip.1 — 2023-04-17
- 1.0.0-alpha.2 — 2022-09-21
- 1.0.0-alpha.1 — 2022-08-30
- 1.0.0-alpha.0 — 2022-08-12
- 0.2.1 — 2021-10-25
- 0.2.0 — 2021-10-05
- 0.1.1 — 2021-09-17
- 0.1.0 — 2021-09-17
- 0.0.3-alpha.6 — 2021-09-16
- 0.0.3-alpha.5 — 2021-09-15
- 0.0.3-alpha.3 — 2021-09-14
- … 2 more at https://npm.io/package/@synonymdev/slashtags-url/versions

## README

# slashtags-url

Encodes and decodes Slashtags URLs

## Installation

```
npm install @synonymdev/slashtags-url
```

## Usage

```js
import { format, parse, encode } from '@synonymdev/slashtags-url';

const url = format(key, {
  path: '/dir/file.json',
  query: { foo: 'bar' },
  fragment: { encryptionKey: '42' },
});
// url: slash://<z-base32 key>/dir/file.json?foo=bar#encryptionKey=42

const parsed = parse(url);
// {
//   protocol: 'slash:',
//   key: key,
//   path: '/dir/file.json',
//   query: { foo: 'bar' },
//   fragment: '#encryptionKey=42',
//   privateQuery: { encryptionKey: '42' }
// }

const id = encode(parsed.key);
// z-base32 key>
```

## API

#### const id = SlashURL.encode(key)

Encodes a 32-bytes key in z-base32.

#### const url = SlashURL.format(key, [opts])

Creates a URL from a 32-bytes key:

`key` must be a Buffer or an ArrayBuffer.
`opts` includes:

- `protocol` custom protocol, defaults to `slash:`
- `path` a string representing the path, defaults to `/`.
- `query` a query string or a key-value object to format as the query part of the url.
- `fragment` a fragment string or a key-value object to format as a private query in the fragment.

#### const url = SlashURL.parse(url)

Parses a url to return the following:

- `key` Uint8Array of the key parsed from the host part of the url.
- `id` z-base32 encoding of the key, useful as identifier wherever a URL is not suitable (file names).
- `protocol` the protocol part of the url.
- `path` the path part of the url.
- `query` the query parsed as a key value object.
- `fragment` string of the fragment part.
- `privateQuery`: parsed private query from the fragment part of the url.

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