1.1.0 • Published 2 years ago

url-save v1.1.0

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

URL-Save

English|简体中文

Introduce

url-save is a storage object that implemented Storage API.You can use it by two ways. One is using a single object, like below example.

import urlStorage from 'url-save'
urlStorage.setItem('greetings', 'hello world')
urlStorage.setItem('name', 'Jerry')

Debounce is used by default,so you don't worry about performance problems no matter how many set frequently. Another is created a storage object instance. When it was created, it will access location object and set up data according own mode. In usually scene, "query" is initial mode.You can change it by set mode property (single instance also support) and call "initData" method to retrieval data.

import { UrlStorage } from 'url-save'
const urlStorage = new UrlStorage()
urlStorage.setItem('greetings', 'hello world')
urlStorage.mode = 'hash'
urlStorage.setItem('name', 'Jerry')
// location will be "?greetings=hello world#name=Jerry"

The diff of two ways, single object means you access same object in any place, get or set a value forever in the same object.But if you create a new UrlStorage instance, you may make a mistake by setting a value in one Object and getting a value in another object.

import { UrlStorage } from 'url-save'
const urlStorage1 = new UrlStorage()
urlStorage1.setItem('greetings', 'hello world')
const urlStorage2 = new UrlStorage()
urlStorage2.getItem('greetings') // may be undefined,because urlStorage2 set up data before urlStorage1 set data on location

you can use a easily way to set or get a value because of proxy.

import urlStorage, { UrlStorage } from 'url-save'
urlStorage.name = 'Luck'

const urlStorage1 = new UrlStorage()
urlStorage1.age = 18

Also, it can support complex object as well as primary value, it will be stringify using JSON.stringify API.

Installation

npm install url-save
yarn add url-save
pnpm install url-save