Several popular npm package

cookie operations

JS interface operations cookie native browser is very difficult to use.

Js thus producing a handy package.

https://www.npmjs.com/package/js-cookie

A simple, lightweight JavaScript API for handling cookies

 

Basic Usage

Basic Usage

Create a cookie, valid across the entire site:

Cookies.set('name''value');

Create a cookie that expires 7 days from now, valid across the entire site:

Cookies.set('name''value'{ expires});

Create an expiring cookie, valid to the path of the current page:

Cookies.set('name''value'{ expires7, path'});

Read cookie:

Cookies.get('name')// => 'value'
Cookies.get('nothing')// => undefined

Read all visible cookies:

Cookies.get()// => { name: 'value' }

 

 

The client persistence approach

https://www.npmjs.com/package/store2

Local store data to the browser, including local and session storage.

A feature-filled and friendly way to take advantage of localStorage and sessionStorage (JSON, namespacing, extensions, etc).

Download: store2.min.js or store2.js
NPM : npm install store2
NuGet :Install-Package store2

Basic Usage

The main store function can handle set, get, transact, setAll, getAll, each, and clear actions directly. Respectively, these are called like so:

store(key, data);                 // sets stringified data under key
store(key);                       // gets and parses data stored under key
store(key, fn[, alt]);            // run transaction function on/with data stored under key
store({key: data, key2: data2});  // sets all key/data pairs in the object
store();                          // gets all stored key/data pairs as an object
store((keydata)=>});          // calls function for each key/data in storage, return false to exit
store(false);                     // clears all items from storage

Parameters in [brackets] are optional. There are also more explicit and versatile functions available:

store.set(key, data[, overwrite])// === store(key, data);
store.setAll(data[, overwrite]);   // === store({key: data, key2: data});
store.get(key[, alt]);             // === store(key);
store . getAll ( [fillObj ] ) ;           // === store ();
store.transact(key, fn[, alt]);    // === store(key, fn[, alt]);
store.clear();                     // === store(false);
store.has(key);                    // returns true or false
store.remove(key[, alt]);          // removes key and its data, then returns the data or alt, if none
store.each(fn[, fill]);            // === store(fn); optional call arg will be 3rd fn arg (e.g. for gathering values)
store.add(key, data);              // concats, merges, or adds new value into existing one
store.keys([fillList]);            // returns array of keys
store.size();                      // number of keys, not length of data
store.clearAll();    

 

No service mock test

The server need not set up, unlike json-server.

Simplified simulation test method.

Principle, by the method js, ajax server takeover request method json directly from the local data.

Mock.js is a simulation data generator to help the front-end to develop and prototype separate from the back-end progress and reduce some monotony particularly while writing automated tests.

The official site: http://mockjs.com

Features

  • Generate simulated data according to the data template
  • Provide request/response mocking for ajax requests
  • Generate simulated data according to HTML-based templates

This library is loosely inspired by Elijah Manor's post Mocking Introduction, mennovanslooten/mockJSON, appendto/jquery-mockjax and victorquinn/chancejs.

 

Guess you like

Origin www.cnblogs.com/lightsong/p/12578069.html