New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

jsonfile-storage

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonfile-storage

Package with a simple API for storing json files to a local directory.

latest
Source
npmnpm
Version
0.0.16
Version published
Maintainers
1
Created
Source

JSON File Storage

Package with a simple API for storing json files to a local directory.

Coverage Status Build Status

Getting Started

npm i jsonfile-storage

var JSONFileStorage = require('jsonfile-storage');

// directory must exist before creating storage instance
var storage = new JSONFileStorage('./data');

// put stuff into the storage
storage.put({ "key" : "stuff" }).then(result => {
    console.log(result);
    // outputs: { key: 'stuff', id: '137280bc-8afe-4ba2-9625-8c1d20b13c58' }
    // the id is generated automatically if it does not exist
    
    // remove item from the storage
    storage.remove(result.id).then(() => {
        // file was removed from storage
        console.log(storage.getFiles());
        // outputs: []
    })
})

API

JSONFileStorage

Kind: global class

new JSONFileStorage(directoryPath)

Creates a new instance of JSONFileStorage

Throws:

  • Error if directoryPath is not a string or an empty string
ParamTypeDescription
directoryPathstringThe path of the folder where the data will be saved/retrieved

jsonFileStorage.get(id) ⇒ Promise.<any>

Get a single item from the directory with the id

Kind: instance method of JSONFileStorage
Returns: Promise.<any> - a promise that resolves into the file that matches the id. The promise is rejected if the file is not found with the id. Or if there is an error parsing the JSON.

ParamTypeDescription
idstringid of the item to get

jsonFileStorage.getBulk() ⇒ Promise.<Array.<any>>

Gets all the items from the directory and their content

Kind: instance method of JSONFileStorage

jsonFileStorage.put(item, [updateListing]) ⇒ Promise.<any>

Puts a single item in the directory

Kind: instance method of JSONFileStorage
Returns: Promise.<any> - promise that resolves into the file that was put

ParamTypeDefaultDescription
itemanyitem to be put in to the directory
[updateListing]booleantrueshould the files property be updated. Default is true

jsonFileStorage.putBulk(items) ⇒ Promise.<Array.<any>>

Puts items in the directory in bulk

Kind: instance method of JSONFileStorage
Returns: Promise.<Array.<any>> - items putted to the directory
Throws:

  • Error if items is not an array
ParamTypeDescription
itemsArray.<any>items to be put to the directory

jsonFileStorage.remove(id, [updateListing])

removes the specified file from the directory

Kind: instance method of JSONFileStorage

ParamTypeDefaultDescription
idstringid of the file
[updateListing]booleantrueshould the file listing be updated. Default is true

jsonFileStorage.removeBulk(ids) ⇒ Promise.<void>

Deletes files in bulk

Kind: instance method of JSONFileStorage

ParamTypeDescription
idsArray.<string>Array of ids for the files to be deleted

jsonFileStorage.getFiles() ⇒ Array.<string>

Get the json files inside the directory

Kind: instance method of JSONFileStorage
Returns: Array.<string> - files in the directory

jsonFileStorage.changeDirectory(directoryPath)

Changes the directory used within this class

Kind: instance method of JSONFileStorage

ParamTypeDescription
directoryPathstringpath where to change to

Keywords

javscript

FAQs

Package last updated on 19 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts