1.0.8 • Published 5 years ago

tz-storage v1.0.8

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

tz-storage

简体中文

A light-weight localStorage tool.

  • No dependency
  • Supports any type of data
  • Supports UMD
  • JSON support
  • expiration support
  • ~3kb before gzipped

Install

npm

$ npm install tz-storage --save

browser

<script src="tz-storage.min.js"></script>

Usage

Check compatibility:

storage.isSupported // return true or false

Set a storage namespace, it turns key to 'namespace.key':

storage.namespace = 'mystorage'

Set a default value in advance:

storage.defaultValue = 'nothing'

Set options by config:

storage.config({
  namespace: 'space',
  defaultValue: 'empty'
})

Set

Set a storage with any types:

storage.set('key', {active: true, label: 'helloword'})
storage.set('key', [1, 2, 3, 4])
storage.set('key', 'hello')

Set a expire time, it returns default value when expired:

storage.set('key', 'value', new Date().getTime() + 8640000)

Get

Replace with a custom value when the value is empty.

storage.get('key', { defaultValue: 'empty' })

Get with specified type(only worked in string, number and boolean)

storage.get('key', { type: 'number' })

Remove

storage.remove('key')
1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.1

5 years ago