@analytics/localstorage-utils
Version:
Tiny LocalStorage utility library
3 lines (2 loc) • 2.25 kB
JavaScript
var utilLocalStorage=function(n){var e="undefined",t="object";"undefined"==typeof process||process;var r="undefined"!=typeof document;function o(n,e){return e.charAt(0)[n]()+e.slice(1)}"undefined"!=typeof Deno&&Deno,r&&"nodejs"===window.name||"undefined"!=typeof navigator&&void 0!==navigator.userAgent&&(navigator.userAgent.includes("Node.js")||navigator.userAgent.includes("jsdom"));var u=o.bind(null,"toUpperCase"),i=o.bind(null,"toLowerCase");function l(n,e){void 0===e&&(e=!0);var t=function(n){return s(n)?u("null"):"object"==typeof n?function(n){return a(n.constructor)?n.constructor.name:null}(n):Object.prototype.toString.call(n).slice(8,-1)}(n);return e?i(t):t}function c(n,e){return typeof e===n}var a=c.bind(null,"function"),f=c.bind(null,"string");function s(n){return null===n}function d(n,e){if("object"!=typeof e||s(e))return!1;if(e instanceof n)return!0;var t=l(new n(""));if(function(n){return n instanceof Error||f(n.message)&&n.constructor&&function(n){return"number"===l(n)&&!isNaN(n)}(n.constructor.stackTraceLimit)}(e))for(;e;){if(l(e)===t)return!0;e=Object.getPrototypeOf(e)}return!1}function v(n,e){var t=n instanceof Element||n instanceof HTMLDocument;return t&&e?function(n,e){return void 0===e&&(e=""),n&&n.nodeName===e.toUpperCase()}(n,e):t}function b(n){var e=[].slice.call(arguments,1);return function(){return n.apply(void 0,[].slice.call(arguments).concat(e))}}c.bind(null,"undefined"),c.bind(null,"boolean"),c.bind(null,"symbol"),d.bind(null,TypeError),d.bind(null,SyntaxError),b(v,"form"),b(v,"button"),b(v,"input"),b(v,"select");var m="__global__",p=typeof self===t&&self.self===self&&self||typeof global===t&&global.global===global&&global||void 0;function g(n,e,t){var r;try{if(j(n)){var o=window[n];r=o[e].bind(o)}}catch(n){}return r||t}p[m]||(p[m]={});var y={};function j(n){if(typeof y[n]!==e)return y[n];try{var t=window[n];t.setItem(e,e),t.removeItem(e)}catch(e){return y[n]=!1}return y[n]=!0}var w="localStorage",I=j.bind(null,w),L=g(w,"getItem",function(n){return p[m][n]}),A=g(w,"setItem",function(n,e){return p[m][n]=e}),S=g(w,"removeItem",function(n){delete p[m][n]});return n.LOCAL_STORAGE=w,n.getItem=L,n.hasLocalStorage=I,n.removeItem=S,n.setItem=A,n}({});
//# sourceMappingURL=localstorage-utils.js.map