# @infracloud/jsonkvs

> Use physical JSON files as a key value store

Latest version **1.1.2** (published 2018-05-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install @infracloud/jsonkvs
pnpm add @infracloud/jsonkvs
yarn add @infracloud/jsonkvs
bun add @infracloud/jsonkvs
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2018-05-23 |
| First published | 2017-12-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 6.0.0 |
| Dependencies | 0 |
| Unpacked size | 49.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Alex Borisov - Infracloud Limited |
| Maintainers | alexborisov |
| Keywords | infracloud, json, store, kvs, key, value, patch, in-place, javascript, node |

## Links

- npm: https://www.npmjs.com/package/@infracloud/jsonkvs
- Repository: https://github.com/infracloudco/jsonkvs
- Homepage: https://github.com/infracloudco/jsonkvs#readme
- Issues: http://github.com/infracloudco/jsonkvs/issues
- npm.io page: https://npm.io/package/@infracloud/jsonkvs

## 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

- 1.1.2 (latest) — 2018-05-23
- 1.1.1 — 2018-01-19
- 1.1.0 — 2017-12-20
- 1.0.0 — 2017-12-20

## README

# jsonkvs

Use physical JSON files as a key value store

## Demo

```
const jsonkvs = require('jsonkvs')
const packageJson = jsonkvs('./myFile.json')

packageJson.set('one', 'some value')
packageJson.del('someKey')
packageJson.save() // write changes
```

## Config

| Key      | Default | Detail                                                             |
| -------- | ------- | ------------------------------------------------------------------ |
| tabSpace | '\t'    | What character to use to indent output JSON. Defaults to hard tab. |

## API

### jsonkvs(path, config)

Load a JSON file at a given `path`.

#### .get(key)

Get the value of a given `key`. If no `key` is passed will return the whole object.

#### .set(key, value | patch, replace=false)

Set the `value` of a given `key`. Can be called two ways:

* By passing the `key` as first argument and `value` as second.
* By passing an `patch` object. In this case the patch will be merged. If `replace` is set then the original file will be overridden by the patch

#### .del(key)

Unset a given keys

#### .save()

Commit changes to disk

## ToDo

* [ ] When a file is open it's contents is loaded into memory and it's not locked.
* [ ] If the file changes on the FS it's contents should be reread and memory copy updated.
* [ ] Any pending changes in memory will superseed new changes from disk.
* [ ] The above bollocks should all be configurable (you can lock a file, get/set directly from the file (via inmemory cache), conflict resolution)
* [ ] Can save to an alternative location

## Licence

(MIT 2-Clause)

Copyright (c) 2017, [Infracloud Ltd](http://infracloud.co) All rights reserved.

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