# urltron

> Stringify and parse json from url query parameters

Latest version **0.1.13** (published 2021-06-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install urltron
pnpm add urltron
yarn add urltron
bun add urltron
```

## Health

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

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

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.13 |
| Published | 2021-06-04 |
| First published | 2021-05-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 18 |
| Author | nojvek |
| Maintainers | nojvek |
| Keywords | json, stringify, parse, url, query, parameters |

## Links

- npm: https://www.npmjs.com/package/urltron
- Repository: https://github.com/recurrency/urltron
- Homepage: https://github.com/recurrency/urltron#readme
- Issues: https://github.com/recurrency/urltron/issues
- npm.io page: https://npm.io/package/urltron

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.1.13 (latest) — 2021-06-04
- 0.0.1 (beta) — 2021-05-25
- 0.1.12 — 2021-06-02
- 0.1.10 — 2021-06-01
- 0.1.9 — 2021-06-01
- 0.1.8 — 2021-05-27
- 0.1.7 — 2021-05-27
- 0.1.6 — 2021-05-27
- 0.1.5 — 2021-05-27
- 0.1.4 — 2021-05-26
- 0.1.2 — 2021-05-26
- 0.1.1 — 2021-05-26
- 0.1.0 — 2021-05-26

## README

[![CI](https://github.com/recurrency/urltron/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/nojvek/urltron/actions/workflows/ci.yml)
[![npm total downloads](https://img.shields.io/npm/dt/urltron.svg?maxAge=2592000)](https://www.npmjs.com/package/urltron)
[![licence](https://img.shields.io/npm/l/urltron.svg?maxAge=2592000)](https://github.com/nojvek/urltron)
[![npm version](https://img.shields.io/npm/v/urltron.svg)](https://www.npmjs.com/package/urltron)

# urltron

Stringify and parse json for url.

Works wonderfully for SPA apps that want to store state in url. Read via `location.search` and `location.hash`. Navigate with `<a href="...">`, `history.pushState` and `location.assign`. Can be used with `react-router`'s `<Link to={...}` and `useLocation/useHistory` hooks.

## Why use urltron?

- 0 dependencies
- Tiny (~1kb)
- Fast
- Looks like good ol' query params
- Written in Typescript. Comes with typings when installed.
- Works on all browsers and Node.js

## Usage

Same api as built-in `JSON.stringify` and `JSON.parse`.

```ts
import urltron from 'urltron';
urltron.stringify({limit: 10, offset: 20, query: 'hello'});
urltron.parse('limit=10&offset=20&query=hello');
```

## Design

- A flat object looks exactly like query paramters e.g `?k1=v&k2=v`.
- Supports all valid json types (null, boolean, number, string, object and array).
- Readable and intuitive output. Objects as `(a=1&b=2&c=3)` and arrays in `@(a,b,c)`
- Shorter and readable output compared to `encodeURIComponent(JSON.stringify(val))`

## Examples

| urltron                             | json                                                                 |
| ----------------------------------- | -------------------------------------------------------------------- |
| `hello=world+tour&limit=2&sort`     | `{"hello":"world tour","limit":2,"sort":true}`                       |
| `query=`                            | `{"query":""}`                                                       |
| `num=1.23`                          | `{"num":1.23}`                                                       |
| `yep=t`                             | `{"yep":true}`                                                       |
| `nah=f`                             | `{"nah":false}`                                                      |
| `nada=n`                            | `{"nada":null}`                                                      |
| `nStr=~n`                           | `{"nStr":"n"}`                                                       |
| `numStr=~123`                       | `{"numStr":"123"}`                                                   |
| `arr=@(1,2,3)`                      | `{"arr":[1,2,3]}`                                                    |
| `jraphql=(id&name&books=(id&name))` | `{"jraphql":{"id":true,"name":true,"books":{"id":true,"name":true}}` |
| `@(@(1,2,3),@(4,5,6),@(7,8,9),0)`   | `[[1,2,3],[4,5,6],[7,8,9],0]`                                        |
| `@(~,hello,t,f,n,1,(a=(b=c)))`      | `["","hello",true,false,null,1,{"a":{"b":"c"}}]`                     |

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