1.0.0 • Published 4 years ago

dweb-json v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

dweb-json

read & write dweb.json files. Uses toiletdb under the hood.

npm travis standard

Install

npm install dweb-json

Usage

var DatJSON = require('dweb-json')

var datjson = DatJSON(archive)

datjson.create({title: 'a dweb', description: 'exciting'}, function (err) {
  if (err) throw err
})

datjson.read(function (err, data) {
  console.log(data)
})

Write to a dweb.json on the file system also:

var DatJSON = require('dweb-json')

var datjson = DatJSON(archive, {file: path.join(dweb.path, 'dweb.json')})

datjson.create({title: 'a dweb', description: 'exciting'}, function (err) {
  if (err) throw err
})

TODO: replace file option with dwebfs indexing

API

var datjson = DatJSON(archive, [opts])

create a new datJson db

Options:

  • opts.file - dweb.json file path, updates will be written to file system and archive

datjson.create([data], cb)

Create a new dweb.json file in the archive with the default keys (url, title, description). Pass in any additional data to add on initial create.

datjson.write(key, val, cb) or datjson.write(data, cb)

Write a single key and value or an object, data, to the dweb.json file. Use file option above to also update the file on the file system.

datjson.delete(key, cb)

Delete a key from the dweb.json file.

datjson.read(cb)

Read the current dweb.json.

License

MIT