|
1 | 1 | # cache-simple
|
2 | 2 | A Simple Tool for Processing cookie localStorage sessionStorage
|
| 3 | + |
| 4 | +## Installation |
| 5 | +``` |
| 6 | +$ npm i -S cache-simple |
| 7 | +``` |
| 8 | +## In node.js |
| 9 | + |
| 10 | + |
| 11 | +``` |
| 12 | +import { cookie_s, localStorage_s, sessionStorage_s } from 'cache-simple'; |
| 13 | +
|
| 14 | +/** |
| 15 | + * |
| 16 | + * or |
| 17 | +import cacheSimple from 'cache-simple'; |
| 18 | +let cookie_s = cacheSimple.cookie_s, |
| 19 | + localStorage_s = cacheSimple.localStorage_s, |
| 20 | + sessionStorage_s = cacheSimple.sessionStorage_s; |
| 21 | + * |
| 22 | + * |
| 23 | + */ |
| 24 | +
|
| 25 | +// input data support String Object Array |
| 26 | +let data = "this is a test string"; |
| 27 | +// let data = { |
| 28 | +// a: '1', |
| 29 | +// b: { |
| 30 | +// c: 'c', |
| 31 | +// d: 'd' |
| 32 | +// }, |
| 33 | +// e: [1, 2, 3] |
| 34 | +// } |
| 35 | +
|
| 36 | +// let data = [ |
| 37 | +// {name: 'zhangsan',age: 18}, |
| 38 | +// {name: 'lisi',age: 19} |
| 39 | +// ] |
| 40 | +/** |
| 41 | + * Set cookie |
| 42 | + * @param {string} cookie name |
| 43 | + * @param cookie value |
| 44 | + * @param {int} Failure time (seconds) |
| 45 | + * @param {string} Scope |
| 46 | + * @param {string} Path of action |
| 47 | + * @param {bool} Encryption or not |
| 48 | + **/ |
| 49 | + //forExample: |
| 50 | + //set(sName,sValue,iExpireSec,sDomain,sPath,bSecure) //Complete params |
| 51 | + cookie_s.set('key',data,1*60*60*24*7) |
| 52 | +
|
| 53 | + /** |
| 54 | + * get cookie |
| 55 | + * @param {string} cookie name |
| 56 | + * @param {string} Default values |
| 57 | + * @return cookie value |
| 58 | + */ |
| 59 | +//forExample: |
| 60 | +cookie_s.get('key') |
| 61 | +
|
| 62 | + /** |
| 63 | + * delete cookie |
| 64 | + * @param {string} cookie name |
| 65 | + * @param {string} Scope |
| 66 | + * @param {sPath} Path of action |
| 67 | + */ |
| 68 | +//forExample: |
| 69 | +cookie_s.del('key') |
| 70 | +
|
| 71 | +
|
| 72 | +
|
| 73 | +/** |
| 74 | + * Set localStorage_s |
| 75 | + * @param {string} localStorage name |
| 76 | + * @param localStorage value |
| 77 | + * @param {int} Failure time (seconds) |
| 78 | + **/ |
| 79 | + //forExample: |
| 80 | +localStorage_s.set('key',data,1*60*60*24*7) |
| 81 | +
|
| 82 | + /** |
| 83 | + * get localStorage |
| 84 | + * @param {string} get localStorage name |
| 85 | + * @return localStorage value |
| 86 | + */ |
| 87 | + //forExample: |
| 88 | +localStorage_s.get('key') |
| 89 | +
|
| 90 | +
|
| 91 | +/** |
| 92 | + * delete localStorage |
| 93 | + * @param {string} localStorage name |
| 94 | + */ |
| 95 | +//forExample: |
| 96 | +localStorage_s.del('key') |
| 97 | +
|
| 98 | +
|
| 99 | +
|
| 100 | +
|
| 101 | +/** |
| 102 | + * Set sessionStorage |
| 103 | + * @param {string} sessionStorage name |
| 104 | + * @param sessionStorage value |
| 105 | + **/ |
| 106 | + //forExample: |
| 107 | + sessionStorage_s.set('key',data) |
| 108 | +
|
| 109 | + /** |
| 110 | + * get sessionStorage |
| 111 | + * @param {string} get sessionStorage name |
| 112 | + * @return sessionStorage value |
| 113 | + */ |
| 114 | + //forExample: |
| 115 | + sessionStorage_s.get('key') |
| 116 | +
|
| 117 | +
|
| 118 | +/** |
| 119 | + * delete sessionStorage |
| 120 | + * @param {string} sessionStorage name |
| 121 | + */ |
| 122 | +//forExample: |
| 123 | +sessionStorage_s.del('key') |
| 124 | +
|
| 125 | +``` |
0 commit comments