bags

The Bags have simple methods to manager localStorage API + JSON API

Usage no npm install needed!

<script type="module">
  import bags from 'https://cdn.skypack.dev/bags';
</script>

README

Bags

WIP - The Bags have simple methods to manager localStorage API + JSON API

Standard - JavaScript Style Guide licenses - MIT

Documentation

Browser Support

Chrome Firefox Opera Safari IE
4+ ✔ 3.5+ ✔ 10,50+ ✔ 4+ ✔ 8+ ✔

Installation

$ npm install bags --save

How to use

ES6

import Bags from 'bags';

const store = Bags.create();

CommonJS

const Bags = require('bags');

const store = Bags.create();

UMD in Browser

<!-- to import non-minified version -->
<script src="bags.umd.js"></script>

<!-- to import minified version -->
<script src="bags.umd.min.js"></script>

After that the library will be available as bags. Follow an example:


const bag = Bags.create();

Methods

Follow the methods that the library provides.

Bags.create()

Create is a static method that create a storage instance

Arguments

Don't have arguments

Example

const bag = Bags.create();

bag.add(key, value)

Create a new entry with any value (unless the function value)

Arguments

Argument Type Options
key string 'Any string you want as a key'
value any 'any value'

Example

bag.add('object', {});
bag.add('array', []);

bag.fetch(key)

Fetch a value stored given a correspondent key

Return null if key not exists

Arguments

Argument Type Options
key string 'Any string you want as a key'

Example

bag.fetch('object'); // {}
bag.fetch('array'); // []

bag.has(key)

Verify if value related with given key exists

Return a boolean true | false

Arguments

Argument Type Options
key string 'Any string you want as a key'

Example

bag.has('object'); // true
bag.has('number'); // false

bag.remove(key)

Remove the given key and the related value

Return true if occurs correctly

Arguments

Argument Type Options
key string 'Any string you want as a key'

Example

bag.has('object'); // true
bag.remove('object');
bag.has('object'); // false

bag.clear()

Clear all the store instance

Return true if occurs correctly

Arguments

Don't have arguments

Example

bag.has('object'); // true
bag.remove('object');
bag.has('object'); // false

Maintainers


Daniel Simão

Contributors

This project exists thanks to all the people who contribute.

You're free to contribute to this project by submitting issues and/or pull requests. This project is test-driven, so keep in mind that every change and new feature should be covered by tests.

This repository uses standard style guide

License

MIT © Daniel Simão da Silva