# @profiscience/knockout-contrib-querystring

> Querystring Abstraction for KnockoutJS

Latest version **0.0.1-alpha.12** (published 2018-05-23) · WTFPL license · 0 weekly downloads

## Install

```sh
npm install @profiscience/knockout-contrib-querystring
pnpm add @profiscience/knockout-contrib-querystring
yarn add @profiscience/knockout-contrib-querystring
bun add @profiscience/knockout-contrib-querystring
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1-alpha.12 |
| Published | 2018-05-23 |
| First published | 2017-11-09 |
| Weekly downloads | 0 |
| License | WTFPL |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 70.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 41 |
| Author | Casey Webb |
| Maintainers | barsh, caseywebb |
| Keywords | knockout, knockoutjs, params, query, querystring |

## Links

- npm: https://www.npmjs.com/package/@profiscience/knockout-contrib-querystring
- Repository: https://github.com/Profiscience/knockout-contrib
- Homepage: https://github.com/Profiscience/knockout-contrib/tree/master/packages/querystring
- Issues: https://github.com/Profiscience/knockout-contrib/issues
- npm.io page: https://npm.io/package/@profiscience/knockout-contrib-querystring

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 0.0.1-alpha.12 (latest) — 2018-05-23
- 0.0.1-alpha.11 — 2018-05-08
- 0.0.1-alpha.10 — 2018-04-05
- 0.0.1-alpha.9 — 2018-02-14
- 0.0.1-alpha.8 — 2018-02-02
- 0.0.1-alpha.7 — 2018-01-29
- 0.0.1-alpha.6 — 2018-01-29
- 0.0.1-alpha.5 — 2018-01-22
- 0.0.1-alpha.4 — 2018-01-09
- 0.0.1-alpha.3 — 2017-12-18
- 0.0.1-alpha.2 — 2017-11-12
- 0.0.1-alpha.0 — 2017-11-09

## README

# @profiscience/knockout-contrib-querystring

[![Version][npm-version-shield]][npm]
[![Dependency Status][david-dm-shield]][david-dm]
[![Peer Dependency Status][david-dm-peer-shield]][david-dm-peer]
[![Dev Dependency Status][david-dm-dev-shield]][david-dm-dev]
[![Downloads][npm-stats-shield]][npm-stats]

Easy-peasy Querystrings for Knockout

## Installation
```bash
$ yarn add @profiscience/knockout-contrib-querystring
```
_or_
```bash
$ npm install @profiscience/knockout-contrib-querystring
```

Typing are included, but have the caveat that query params that are **observable arrays**
will only be typed as **observables**. This is due to a limitation with mapped types in TypeScript.

## Basic Usage
```javascript
import Query from '@profiscience/knockout-contrib-querystring'

const query = Query.create({ sort: 'alpha' })

query.sort() // alpha
```

## API

### Query.create([config = {}, name])
Create a new query instance passing a configuration object and optionally a name to group
the query with. This allows you to create multiple query objects with the same params,
and they will not interfere with each other. It also allows you to link queries if they
are given the same group name.

The configuration object contains key/value pairs of querystring param names and
their config, respectively. A querystring param config may be an object that
contains any combination of three props, `default`, `initial`, and `coerce`, or
a value which will be used as the default and initial value. The `coerce` function
allows you to transform a value before it is fully set.

```javascript
const query = Query.create({
  // query param named foo
  foo: {
    default: 'foo',
    initial: 'bar',
    coerce: (v) => v === 'baz' ? 'qux' : v
  },

  bar: 'bar'
})
```

In this case, the foo param will be set to "bar" initially — if not already in
the querystring — but call to `query.clear()` will then set it to "foo". The `coerce`
function disallows setting the param to "baz", and attempting to will cause it
to be set to "qux" instead.

__NOTE:__ Params that are equal to their default will _not_ be displayed in the
querystring. Less === More.

### Query.fromQS([group])
Returns JS object containing current query from URL — for group if any.

### Query.setParser({ parse, stringify })
By default, this lib is dumb, and it **does not** use valid querystrings. Instead,
it uses `JSON.stringify` and `encodeURIComponent`, and vice versa. This function allows
you to define a custom parser.

e.g.

```javascript
import Query from 'ko-querystring'
import rison from 'rison' // https://github.com/Nanonid/rison

Query.setParser({
  parse: rison.decode_object,
  stringify: rison.encode_object
})
```

### query[param]
Query params are created via super-cool ES6 proxies, so you don't need to explicitly
define all the query params you will use. Simply access them, and they are there.

Params will be initialized from the querystring if available, and their default
value or undefined if not.

### query[param].clear()
Resets param to its default or undefined.

### query[param].isDefault
Observable value that is true if the param is its default value, otherwise false.

### query.set(default || { default, initial, coerce })
Change the default values for a query.

### query.clear()
Reset all the query params to their defined defaults, or undefined.

### query.toJS()
Returns unwrapped query object.

### query.toString()
Returns stringified query.

### query.asObservable()
Return observable query object.
i.e. ko.observable({ foo: 'foo' }) instead of { foo: ko.observable('foo') }

### query.dispose()
Disposes the query object and cleans the querystring. Don't forget to clean up after 'yo self.

## MOAR!

Check the test file or the source. This lib is small enough to understand inside
and out.

[david-dm]: https://david-dm.org/Profiscience/knockout-contrib?path=packages/querystring
[david-dm-shield]: https://david-dm.org/Profiscience/knockout-contrib/status.svg?path=packages/querystring

[david-dm-peer]: https://david-dm.org/Profiscience/knockout-contrib?path=packages/querystring&type=peer
[david-dm-peer-shield]: https://david-dm.org/Profiscience/knockout-contrib/peer-status.svg?path=packages/querystring

[david-dm-dev]: https://david-dm.org/Profiscience/knockout-contrib?path=packages/querystring&type=dev
[david-dm-dev-shield]: https://david-dm.org/Profiscience/knockout-contrib/dev-status.svg?path=packages/querystring

[npm]: https://www.npmjs.com/package/@profiscience/knockout-contrib-querystring
[npm-version-shield]: https://img.shields.io/npm/v/@profiscience/knockout-contrib-querystring.svg

[npm-stats]: http://npm-stat.com/charts.html?package=@profiscience/knockout-contrib-querystring&author=&from=&to=
[npm-stats-shield]: https://img.shields.io/npm/dt/@profiscience/knockout-contrib-querystring.svg?maxAge=2592000

[gitter]: https://gitter.im/Profiscience/ko-component-querystring
[gitter-shield]: https://img.shields.io/gitter/room/profiscience/ko-component-querystring.svg

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