-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsi-store.js.map
1 lines (1 loc) · 6.95 KB
/
si-store.js.map
1
{"version":3,"file":null,"sources":["src/config.js","src/utils.js","src/storage/local.js","src/storage/session.js","src/storage/index.js","src/Store.js","src/index.js"],"sourcesContent":["export default {\n size: null, // 大小预留参数尚未支持\n id: 'store', // 在key上回自动带上id\n expires: null, // expires 过期时间\n enableCache: true, // 是否\n storage: 'local' // 使用什么缓存数据 local -> localStorage session -> sessionStorage\n}\n","export const each = function (loopable, callback) {\n if (loopable) {\n if (loopable.length === +loopable.length && loopable.length - 1 in loopable) {\n var i\n for (i = 0; i < loopable.length; i++) {\n if (callback.call(loopable[i], loopable[i], i) === false) break\n }\n } else {\n for (var key in loopable) {\n if (callback.call(loopable[key], loopable[key], key) === false) break\n }\n }\n }\n}\n\nexport const extend = function (base) {\n each(Array.prototype.slice.call(arguments, 1), function (extensionObject) {\n each(extensionObject, function (value, key) {\n if (extensionObject.hasOwnProperty(key)) {\n base[key] = value\n }\n })\n })\n return base\n}\n","let storage = window.localStorage\nexport default {\n set (key, value) {\n storage.setItem(key, JSON.stringify(value))\n },\n get (key) {\n return JSON.parse(storage.getItem(key))\n },\n remove (key) {\n storage.removeItem(key)\n },\n each (callback) {\n for (let key in storage) {\n callback(this.get(key), key)\n }\n }\n}\n","let storage = window.sessionStorage\nexport default {\n set (key, value) {\n storage.setItem(key, JSON.stringify(value))\n },\n get (key) {\n return JSON.parse(storage.getItem(key))\n },\n remove (key) {\n storage.removeItem(key)\n },\n each (callback) {\n for (let key in storage) {\n if (callback(this.get(key), key) === false) return\n }\n }\n}\n","import local from './local'\nimport session from './session'\n\nlet storageMap = {}\nexport const register = function (name, obj) {\n storageMap[name] = obj\n}\n\nexport const getStorage = function (name) {\n return storageMap[name]\n}\n\nregister('local', local)\nregister('session', session)\n","import config from './config'\nimport {\n extend\n} from './utils'\nimport {\n getStorage\n} from './storage'\nexport default class Store {\n constructor (options) {\n this.options = extend({}, config, options)\n this.storage = getStorage(this.options.storage)\n this.length = 0\n this._init()\n }\n\n _init () {\n // 初始化缓存操作\n }\n\n set (key, value, exp) {\n let item = this._setVal(key, value, exp)\n key = this._setKey(key)\n this.storage.set(key, item)\n return this\n }\n\n get (key) {\n key = this._setKey(key)\n let item = this.storage.get(key)\n return this._getVal(item)\n }\n\n remove (key) {\n key = this._setKey(key)\n this.storage.remove(key)\n return this\n }\n\n forEach (callback) {\n this.storage.each((item, key) => {\n key = this._getKey(key)\n if (!key) return\n const value = this._getVal(item)\n if (value !== undefined && value !== null) callback(value, key)\n })\n }\n\n clear () {\n this.forEach((value, key) => {\n this.remove(key)\n })\n return this\n }\n\n has (key) {\n return !!this.get(key)\n }\n\n getAll () {\n let allMap = {}\n this.forEach((value, key) => {\n allMap[key] = value\n })\n return allMap\n }\n\n _setVal (key, value, exp) {\n return {\n value: value,\n key: key,\n exp: exp === undefined || exp === null ? this.options.expires : exp,\n time: new Date().getTime()\n }\n }\n\n _getVal (item) {\n if (item === null) return null\n let nowTime = new Date().getTime()\n if (item.exp !== undefined && item.exp !== null && nowTime - item.time >= item.exp) {\n this.storage.remove(item.key)\n return null\n }\n return item.value\n }\n\n _setKey (key) {\n return this.options.id + '_' + key\n }\n\n _getKey (key) {\n if (key.indexOf(this.options.id + '_') !== 0) return\n return key.substring(this.options.id.length + 1)\n }\n}\n","import Store from './Store'\nimport {register} from './storage/index.js'\n\nlet store = new Store()\n\nstore.version = '0.1.1'\nstore.create = function (options) {\n return new Store(options)\n}\nstore.register = register\n\nexport default store\n"],"names":["each","loopable","callback","length","i","call","key","extend","base","Array","prototype","slice","arguments","extensionObject","value","hasOwnProperty","storage","window","localStorage","setItem","JSON","stringify","parse","getItem","removeItem","this","get","sessionStorage","storageMap","register","name","obj","getStorage","local","session","Store","options","config","_init","exp","item","_setVal","_setKey","set","_getVal","remove","_this","_getKey","undefined","forEach","allMap","expires","Date","getTime","nowTime","time","id","indexOf","substring","store","version","create"],"mappings":"6LACQ,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