titoBouzout / storage

A simple class to automate storage.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Storage

A simple class to automate storage.

Usage

import storage from '@titodp/storage'

// saving to storage

storage.uh = 'YES' // look at storage!

storage.objectToo = { uh: 'YES', wow: '😁' } // look at storage!

// deleting from storage

delete storage.uh

// fancy example

// start with default values
let mySettings = {
	uh: 'YES',
	wow: '😁',
}

// load any setting that has been saved previously
// and put it on mySettings
mySettings = storage.on(mySettings, 'optional key prefix')

// first time you run this code should show 😁 (the default)
// if you reload it, it should show πŸ₯³ as we saved a new value on the next example
console.log(mySettings.wow)

// change the value and save it to storage
mySettings.wow = 'πŸ₯³'

// reset with mySettings.reset()

Install

npm install @titodp/storage

How it works?

It sets a proxy trap, serializes when you set and unserializes when you get.

Author

URL

About

A simple class to automate storage.


Languages

Language:JavaScript 94.8%Language:Batchfile 5.2%