Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dat-ecosystem-archive/dat-json
manage dat.json file via toiletdb [ DEPRECATED - More info on active projects and modules at https://dat-ecosystem.org/ ]
https://github.com/dat-ecosystem-archive/dat-json
dat
Last synced: 10 days ago
JSON representation
manage dat.json file via toiletdb [ DEPRECATED - More info on active projects and modules at https://dat-ecosystem.org/ ]
- Host: GitHub
- URL: https://github.com/dat-ecosystem-archive/dat-json
- Owner: dat-ecosystem-archive
- License: mit
- Archived: true
- Created: 2017-04-20T18:49:49.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-01-06T16:48:50.000Z (almost 3 years ago)
- Last Synced: 2024-06-11T20:31:01.484Z (5 months ago)
- Topics: dat
- Language: JavaScript
- Homepage:
- Size: 32.2 KB
- Stars: 10
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-dat - dat-json - read and write `dat.json` files, uses `toiletdb` (Dat Core Modules / CLI Utilities)
README
[![deprecated](http://badges.github.io/stability-badges/dist/deprecated.svg)](https://dat-ecosystem.org/)
More info on active projects and modules at [dat-ecosystem.org](https://dat-ecosystem.org/)
---
# dat-json
read & write dat.json files. Uses toiletdb under the hood.
[![npm][npm-image]][npm-url]
[![travis][travis-image]][travis-url]
[![standard][standard-image]][standard-url]## Install
```
npm install dat-json
```## Usage
```js
var DatJSON = require('dat-json')var datjson = DatJSON(archive)
await datjson.create({title: 'a dat', description: 'exciting'})
console.log(await datjson.read())
```Write to a `dat.json` on the file system also:
```js
var DatJSON = require('dat-json')var datjson = DatJSON(archive, {file: path.join(dat.path, 'dat.json')})
await datjson.create({title: 'a dat', description: 'exciting'})
```**TODO: replace file option with hyperdrive indexing**
## API
### `var datjson = DatJSON(archive, [opts])`
create a new datJson db
Options:
* `opts.file` - dat.json file path, updates will be written to file system and archive
#### `await datjson.create([data])`
Create a new `dat.json` file in the archive with the default keys (`url`, `title`, `description`). Pass in any additional data to add on initial create.
#### `await datjson.write(key, val)` or `await datjson.write(data)`
Write a single `key` and `value` or an object, `data`, to the `dat.json` file. Use `file` option above to also update the file on the file system.
#### `await datjson.delete(key)`
Delete a `key` from the `dat.json` file.
#### `await datjson.read()`
Read the current `dat.json`.
## License
[MIT](LICENSE.md)
[npm-image]: https://img.shields.io/npm/v/dat-json.svg?style=flat-square
[npm-url]: https://www.npmjs.com/package/dat-json
[travis-image]: https://img.shields.io/travis/datproject/dat-json.svg?style=flat-square
[travis-url]: https://travis-ci.org/datproject/dat-json
[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square
[standard-url]: http://npm.im/standard