1.1.9 • Published 7 years ago

awesome-domstorage v1.1.9

Weekly downloads
50
License
-
Repository
github
Last release
7 years ago

awesome-domstorage

awesome-domstorage provides an abstraction for two web storages built in modern web browsers: LocalStorage and SessionStorage

LocalStorageService (SessionStorageService) provides an abstraction for Web storage (Dom storage) of a web browser. The difference between the two storage services is the web storage (built-in) handled.

Multi-Layer Structuring of Key-Value Pairs

Knowing that Web Storage is of only a single layer structure, this service helps nested structuring of key-value pairs by filling dashes in-between.

e.g. You might want to have a structure like the following,

   {'key1': {
      'foo': 'false',
      'bar': 'true'
    },
    'messenger': {
      ...
    }
    ...
   }

In this case, 'foo' of 'key1' becomes 'key1-foo' with value 'false'.

Casting

Note that Web Storage can only have STRING value NOT BOOLEAN. However, 'false' (string) becomes false (boolean) by calling stringToBoolean(). 'null'(string) becomes null (null) as well.

Protected Namespace

setPrefix() to set prefix for each key in order to avoid potential conflicts. e.g. Using the aforementioned example, 'key1-foo' is prefixed with 'myApp' 'myApp-key1-foo' = false ...

Emergency Storage of Its Own

In case where the Web Storage cannot be used, this service generates its own temporary storage object to store the configuration. Temporary storage expires every time the web page is refreshed, though.

Expiration time

setWithExpiration() and getWithExpiration() provides expiration time.

setWithExpiration('key', 'value', 30 /* seconds */, null /* valueAfterExpiration */)
getWithExpiration('key') // is 'value' before 30 seconds
getWithExpiration('key') // is null after 30 seconds

Install

https://www.npmjs.com/package/awesome-domstorage

npm install awesome-domstorage

Usage

import { LocalStorage, SessionStorage} from 'awesome-domstorage'

const NAME = 'your-app'
LocalStorage.init({foo: 'bar'}, NAME)
LocalStorage.set(['container', 'star'], 'shining')

var starIs = LocalStorage.get(['container', 'star'])
1.1.9

7 years ago

1.1.8

7 years ago

1.1.7

7 years ago

1.1.6

7 years ago

1.1.5

8 years ago

1.1.4

8 years ago

1.1.3

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago