init-storage
Version:
为应用中的storage提供丝滑的typescript支持
2 lines (1 loc) • 1.19 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).WaterMark={})}(this,(function(e){"use strict";var t={defaultUseInit:!1};e.setInitStorage=function(e,o){void 0===o&&(o=t);var n=e.local,i=e.session,r=function(e,t,n){return{get:function(t,i){var r=void 0===i?o.defaultUseInit:i,a=null;if("undefined"!=typeof window){var f=e.getItem(t);if(f)try{a=JSON.parse(f)}catch(e){a=f}else r&&(a=n[t])}return a},set:function(t,o){"undefined"!=typeof window&&e.setItem(t,JSON.stringify(o))},remove:function(t){"undefined"!=typeof window&&e.removeItem(t)},clear:function(){"undefined"!=typeof window&&e.clear()}}[t]},a="undefined"!=typeof window?localStorage:{},f="undefined"!=typeof window?sessionStorage:{};return{getLocalStorageItem:r(a,"get",n),setLocalStorageItem:r(a,"set",n),removeLocalStorageItem:r(a,"remove",n),clearLocalStorageItem:r(a,"clear",n),getSessionStorageItem:r(f,"get",i),setSessionStorageItem:r(f,"set",i),removeSessionStorageItem:r(f,"remove",i),clearSessionStorageItem:r(f,"clear",i)}},Object.defineProperty(e,"__esModule",{value:!0})}));