几个流行的npm包
cookie操作
浏览器原生的JS接口操作cookie非常难用。
于是产生了好用的js包。
https://www.npmjs.com/package/js-cookie
A simple, lightweight JavaScript API for handling cookies
- Works in all browsers
- Accepts any character
- Heavily tested
- No dependency
- Unobtrusive JSON support
- Supports AMD/CommonJS
- RFC 6265 compliant
- Useful Wiki
- Enable custom encoding/decoding
- ~900 bytes gzipped!
基本用法
Basic Usage
Create a cookie, valid across the entire site:
CookiesCreate a cookie that expires 7 days from now, valid across the entire site:
CookiesCreate an expiring cookie, valid to the path of the current page:
CookiesRead cookie:
CookiesCookiesRead all visible cookies:
Cookies
客户端持久化方法
https://www.npmjs.com/package/store2
存储数据到浏览器本地,包括 本地存储 和 会话存储。
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
基本用法
The main store function can handle
set
,get
,transact
,setAll
,getAll
,each
, andclear
actions directly. Respectively, these are called like so:Parameters in [brackets] are optional. There are also more explicit and versatile functions available:
storestorestorestorestorestorestorestorestorestorestorestorestore
无服务mock测试
不需要架设服务器,不同于json-server。
简化模拟测试方法。
原理是,通过js方法,接管ajax服务器请求方法,直接从本地json数据中获取。
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 templatesThis library is loosely inspired by Elijah Manor's post Mocking Introduction, mennovanslooten/mockJSON, appendto/jquery-mockjax and victorquinn/chancejs.