1.0.1 • Published 7 months ago

@willdevv12/simplestore v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
7 months ago

Simplestore

Easily save JSON data into the local machine through a series of simple functions, similar to how Multer does it with uploaded files

Works without a DB! Feel free to use as a sloppy alternative

Core functions

FunctionParam1Param2Param3
saveData()dir (string)data (text/json)customID (string, optional)
loadData()dir (string)id (string)
updateData()dir (string)id (string)data (text/json)
removeEntry()dir (string)id (string)

Documentation

saveData(dir, data, customID)

Save data to the local machine in the form of a .json file

const {saveData} = require("@willdevv12/simplestore")

// note how no ./ is needed
// Simplestore will look for local folders based on where the process is running
const path = "savePath"

const data = {
    "title": "Hello world",
    "subtext": "This data is saved in a .json file"
}

// The last param isn't needed, but can be specified if you so choose
// If not specified, the file will be saved with a random string as its name
saveData(path, data, "myID")
// console.log(saveData(path, data)) will return the generated id if needed

loadData(dir, id)

Load saved values from the local machine

const {loadData} = require("@willdevv12/simplestore")

// Be sure to specify the ID of the file before 
const path = "savePath"
const id = "myID"

const data = loadData(path, id)

// You are free to play around with the data from here
console.log(data.title)
console.log(data.subtext)

updateData(dir, id, data)

Update the content of a locally saved file

const {loadData,updateData} = require("@willdevv12/simplestore")

const path = "savePath"
const id = "myID"

var data = loadData(path, id)

// Once loaded, the data can be manipulated like so
data.subtext = "A new subtext string"

// Updates the local entry with new changes
updateData(path, id, data)

removeEntry(dir, id)

Completely deletes the local file specified by id

const {removeEntry} = require("@willdevv12/simplestore")

// Specify which file you'll be deleting
const path = "savePath"
const id = "myID"

// After this function completes, the file will be permanently deleted and
// its values inaccessible
removeEntry(path, id)
1.0.1

7 months ago

1.0.0

7 months ago