Skip to content

Commit

Permalink
Merge pull request #26 from Wisembly/0.4.0
Browse files Browse the repository at this point in the history
0.4.0
  • Loading branch information
Mathieu Ghaleb committed Jan 30, 2015
2 parents 78182e0 + 11c92ab commit 88237d0
Show file tree
Hide file tree
Showing 10 changed files with 389 additions and 313 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Basil changelog

## 4.0.0

- Updated README
- Added `keys()` and `keysMap()` methods (#24)
- fixed cookie/localStorage security error if cookies disabled
- [BC Break] Basil raw storage engines do not need now a basil instance
to be accessed. Use `Basil.cookie.set('foo', 'bar')` now instead of
`new Basil().cookie.set('foo', 'bar')`
43 changes: 28 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ The missing Javascript smart persistence layer.
Unified localstorage, cookie and session storage JavaScript API.


## Philosophy

Basil aims to ease the frontend storage management for developpers. It strive
to be bulletproof and handle for you disabled cookies, full localStorage,
unwanted native storage exceptions..

When you'll try to store something, basil will automaticall seek through all
the available storages and find the best suited one to store your value. It
also handle for you the storage of complex javascript objects using json.


## Basic Usage

```javascript
Expand All @@ -19,10 +30,9 @@ basil.remove('foo'); // remove 'foo' value

// advanced methods
basil.check('local'); // boolean. Test if localStorage is available
basil.reset(); // reset all stored values under namespace for current storage
basil.reset(); // reset all stored values under namespace
```


## Advanced Usage

### Storages
Expand All @@ -34,34 +44,41 @@ basil = new window.Basil(options);
// set 'bar' value under 'foo' key in localStorage
basil.set('foo', 'bar', { 'storages': ['local'] });

// set 'bar' value under 'foo' key in localStorage AND cookie
basil.set('foo', 'bar', { 'storages': ['local', 'cookie'] });
// set 'bar' value under 'foo' key.
// try first to store it into cookies and if not possible into localStorage
basil.set('foo', 'quux', { 'storages': ['cookie', 'local'] });

// set 'xyz' value under 'abc' key in memory
basil.set('abc', 'xyz', { 'storages': ['memory'] });

// set value without JSON encoding
basil.set('foo', '{ "bar": "baz" }', { raw: true }); // will save { "bar": "baz" } as string

// retrieve keys
basil.keys(); // returns ['foo', 'abc']
basic.keys({ 'storages': ['memory'] }); // returns ['abc']

// retrive keys map
// retrieve keys map
basil.keysMap(); // returns { 'foo': ['local', 'cookie'], 'abc': ['memory'] }
basic.keysMap({ 'storages': ['memory'] }); // returns { 'abc': ['memory'] }
```

### Native storages
```
// Access native storages
// With basil API, but without namespace nor JSON parsing for values
// cookies
basil.cookie.get(key);
basil.cookie.set(key, value, { 'expireDays': days, 'domain': 'mydomain.com' });
Basil.cookie.get(key);
Basil.cookie.set(key, value, { 'expireDays': days, 'domain': 'mydomain.com' });
// localStorage
basil.localStorage.get(key);
basil.localStorage.set(key, value);
Basil.localStorage.get(key);
Basil.localStorage.set(key, value);
// sessionStorage
basil.sessionStorage.get(key);
basil.sessionStorage.set(key, value);
Basil.sessionStorage.get(key);
Basil.sessionStorage.set(key, value);
```

### Namespaces
Expand Down Expand Up @@ -111,10 +128,6 @@ options = {
// default: `['local', 'cookie', 'session', 'memory']`
storages: ['cookie', 'local']

// storage. Specify the default storage to use
// default: detect best available storage among the supported ones
storage: 'cookie'

// expireDays. Default number of days before cookies expiration
// default: 365
expireDays: 31
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "basil.js",
"version": "0.3.4",
"version": "0.4.0",
"homepage": "https://github.com/Wisembly/basil.js",
"authors": [
"Mathieu Ghaleb <mathieu@wisembly.com>"
Expand Down

0 comments on commit 88237d0

Please sign in to comment.