# parameller

> Easily parse, edit and add url query paramaters with JS, has TypeScript support

Latest version **1.2.1** (published 2018-06-04) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 35/100 (D)** — status: abandoned.

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

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2018-06-04 |
| First published | 2018-04-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Samuel Woodbridge |
| Maintainers | wscandy |

## Links

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

## Recent versions

- 1.2.1 (latest) — 2018-06-04
- 1.2.0 — 2018-05-14
- 1.1.0 — 2018-05-02
- 1.0.3 — 2018-05-02
- 1.0.2 — 2018-04-26
- 1.0.1 — 2018-04-26
- 1.0.0 — 2018-04-26

## README

# Parameller

[![CircleCI](https://circleci.com/gh/propcom/parameller.svg?style=shield)](https://circleci.com/gh/propcom/parameller) ![License](https://img.shields.io/npm/l/parameller.svg) ![Downloads](https://img.shields.io/npm/dw/parameller.svg) [![NPM](https://img.shields.io/npm/v/parameller.svg)](https://www.npmjs.com/package/parameller) ![Size](https://img.shields.io/bundlephobia/minzip/parameller.svg)

Parameller makes parsing url query strings in JS simple.

## Installation

Parameller is easy to install, simply run:

    yarn add parameller

or

    npm install parameller

### Usage

Simply import the functions you wish to use in your project as follows:

    import { getParam, getParams, removeParam, setParam, setParams, toQueryString, pushParam, pushParams, popParams } from "parameller";

### Types

    type Params = { [s: string]: string }

### Methods

#### toQueryString(params: { [s: string]: string }, base: string = ""): string

    const obj = {
        "test": "example",
        "name": "Samuel"
    }

    toQueryString(obj)

Output: `test=example&name=Samuel`

If the base property is set then it will prepend the base onto the query string.

#### getParam(param: string, callback?: (v: string) => void): string | undefined

Example url: `http://test.com/?test=hello&example=wow`

    getParam("test") // returns "hello"
    getParam("example") // returns "wow"
    getParam("something") // returns undefined

`getParam()` takes an optional callback that is only called if the parameter returns a value.

    getParam("test", value => {
        console.log(value) // logs "Hello"
    })

#### getParams(string: string = window.location.search): Params

Example url: `http://test.com/?test=hello&example=wow`

    getParams() // returns { test: "hello", example: "wow" }

### Replace State

The following methods will replace the currently url state, history will not be preserved.

#### setParam(param: string, value: string): Params

Example url: `http://test.com/?test=hello&example=wow`

    setParam("test", "goodbye")

Output: `http://test.com/?test=goodbye&example=wow`

#### setParams(params: Params): Params

Example url: `http://test.com/?test=hello&example=wow`

    setParams({ test: "goodbye" })

Output: `http://test.com/?test=goodbye`

#### removeParam(param: string): Params

Example url: `http://test.com/?test=hello&example=wow`

    removeParam("test")

Output: `http://test.com/?example=wow`

### Push State

The following methods will push the state onto the browser history stack, useful if you want to maintain back/forwards functionality.

#### pushParam(param: string, value: string): Params

Example url: `http://test.com/?test=hello&example=wow`

    pushParam("test", "goodbye")

Output: `http://test.com/?test=goodbye&example=wow`

#### pushParams(params: Params): Params

Example url: `http://test.com/?test=hello&example=wow`

    pushParams({ test: "goodbye" })

Output: `http://test.com/?test=goodbye`

#### popParam(param: string): Params

Example url: `http://test.com/?test=hello&example=wow`

    popParam("test")

Output: `http://test.com/?example=wow`

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