@livelybone/storage
Version:
A module for localStorage, support custom solution of quota exceeded. When localStorage is not supported by browser, it will be degrading to use Cookie or Map
10 lines (8 loc) • 1.02 kB
JavaScript
/**
* Bundle of @livelybone/storage
* Generated: 2020-06-03
* Version: 1.7.2
* License: MIT
* Author: 2631541504@qq.com
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).utilsStorage={})}(this,function(e){"use strict";function r(e){return 22===e.code||0<=e.name.toLowerCase().indexOf("quota")}e.cookieAvailable=function(){try{return document.cookie||!0}catch(e){return!1}},e.isStorageExceeded=r,e.parseJSON=function(t){try{if("undefined"===t)return;return"NaN"===t?NaN:"Infinity"===t?1/0:JSON.parse(t)}catch(e){return t}},e.storageAvailable=function(){try{var e=window.localStorage,t="storage-available";e.setItem(t,t);var n=e.getItem(t)===t;return e.removeItem(t),n}catch(e){return r(e)&&0<window.localStorage.length}},e.stringifyJSON=function(e){if("number"==typeof e){if(isNaN(e))return"NaN";if(!isFinite(e))return"Infinity"}return JSON.stringify(e)},Object.defineProperty(e,"__esModule",{value:!0})});