https://github.com/dinubs/magmarath
A simple storage system for Javascript
https://github.com/dinubs/magmarath
javascript json
Last synced: about 1 month ago
JSON representation
A simple storage system for Javascript
- Host: GitHub
- URL: https://github.com/dinubs/magmarath
- Owner: dinubs
- License: mit
- Created: 2020-07-14T02:31:00.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T11:25:53.000Z (over 3 years ago)
- Last Synced: 2025-09-15T11:16:37.431Z (10 months ago)
- Topics: javascript, json
- Language: JavaScript
- Homepage: https://npmjs.com/package/magmarath
- Size: 620 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Magmarath
Magmarath is a simple storage system for Javascript. It helps ensure that values put into the store is formatted correctly and is a valid value. Helpful for simple maintaining an external storage (through local storage, JSON file, query string etc).
## Feature
* Central storage location allows you to access all state through one location
* Item validation allows you to ensure that only a set of values will be present in an item
* Display formatting allows you to turn a complex object into a string so it can be saved
* Type formatting allows you to ensure that a value will always be an expected type
* Easily turn your store into JSON and populate it from JSON
## Example
```js
const { Store, Item } = require('magmarath');
const store = new Store();
const item = new Item('country', {
defaultValue: 'US',
options: ['US', 'UK', 'CA'],
displayFormatter: (v) => v.toLowerCase(),
typeFormatter: (v) => v.toUpperCase(),
});
store.addItem(item);
store.fromJson({ country: 'UK' });
item.value === 'UK' // true
item.update('AU');
item.value === 'AU'; // false
store.toJson() // { country: 'us' }
```
## Installation
`npm i --save magmarath`