UNPKG

antui-mobile

Version:
60 lines (47 loc) 1.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Application = exports.Session = undefined; var _stringify = require("babel-runtime/core-js/json/stringify"); var _stringify2 = _interopRequireDefault(_stringify); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * 操作浏览器存储 * * 例: * import {Session, Application} from 'storage'; * * Session.setAttribute("user", user); * Session.getAttribute("user"); * * Application.setAttribute("user", user); * Application.getAttribute("user"); */ function storage(storage) { return { getAttribute: function getAttribute(key) { var value = storage.getItem(key); return JSON.parse(value); }, setAttribute: function setAttribute(key, value) { storage.setItem(key, (0, _stringify2.default)(value)); }, remove: function remove(key) { storage.removeItem(key); }, exist: function exist(key) { return !!storage.getItem(key); } }; } function _Session() { return storage(sessionStorage); } function _Application() { return storage(localStorage); } var Session = new _Session(); var Application = new _Application(); exports.Session = Session; exports.Application = Application;