Socket
Socket
Sign inDemoInstall

@analytics/storage-utils

Package Overview
Dependencies
3
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.1 to 0.2.2

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

## [0.2.2](https://github.com/DavidWells/analytics/compare/@analytics/storage-utils@0.2.0...@analytics/storage-utils@0.2.2) (2019-10-03)
**Note:** Version bump only for package @analytics/storage-utils
# 0.2.0 (2019-10-01)

@@ -8,0 +16,0 @@

65

dist/@analytics/storage-utils.js
var analyticsUtilStorage = (function (exports) {
'use strict';
var noOp = function noOp() {};
/* This module will shake out unused code and work in browser and node 🎉 */
function cookie(name, value, ttl, path, domain, secure) {
if (typeof window === 'undefined') return;
if (arguments.length > 1) {
/* eslint-disable no-return-assign */
return document.cookie = "".concat(name, "=").concat(encodeURIComponent(value)).concat(!ttl ? '' : "; expires=".concat(new Date(+new Date() + ttl * 1000).toUTCString())).concat(!path ? '' : "; path=".concat(path)).concat(!domain ? '' : "; domain=".concat(domain)).concat(!secure ? '' : '; secure');
/* eslint-enable */
}
var cookie$1 = noOp;
return decodeURIComponent(("; ".concat(document.cookie).split("; ".concat(name, "="))[1] || '').split(';')[0]);
}

@@ -14,3 +20,7 @@ function hasCookieSupport() {

return document.cookie.indexOf(key) !== -1;
cookie(key, '1');
var valueSet = document.cookie.indexOf(key) !== -1; // Cleanup cookie
cookie(key, '', -1);
return valueSet;
} catch (e) {

@@ -27,3 +37,3 @@ return false;

var getCookie = cookie$1;
var getCookie = cookie;
/**

@@ -36,3 +46,3 @@ * Set a cookie value

var setCookie = cookie$1;
var setCookie = cookie;
/**

@@ -44,3 +54,3 @@ * Remove a cookie value.

function removeCookie(name) {
return cookie$1(name, '', -1);
return cookie(name, '', -1);
}

@@ -142,10 +152,10 @@

if (!key) return null;
var storage = getStorageType(options); // Get value from all locations
var storageType = getStorageType(options); // Get value from all locations
if (storage === 'all') return getAll(key);
if (storageType === 'all') return getAll(key);
/* 1. Try localStorage */
if (useLocal(storage)) {
if (useLocal(storageType)) {
var value = localStorage.getItem(key);
if (value || storage === LOCAL_STORAGE) return parse(value);
if (value || storageType === LOCAL_STORAGE) return parse(value);
}

@@ -155,6 +165,6 @@ /* 2. Fallback to cookie */

if (useCookie(storage)) {
if (useCookie(storageType)) {
var _value = getCookie(key);
if (_value || storage === COOKIE) return parse(_value);
if (_value || storageType === COOKIE) return parse(_value);
}

@@ -187,7 +197,7 @@ /* 3. Fallback to window/global. */

if (!key || !value) return false;
var storage = getStorageType(options);
var storageType = getStorageType(options);
var saveValue = JSON.stringify(value);
/* 1. Try localStorage */
if (useLocal(storage)) {
if (useLocal(storageType)) {
// console.log('SET as localstorage', saveValue)

@@ -206,5 +216,7 @@ var _oldValue = parse(localStorage.getItem(key));

if (useCookie(storage)) {
if (useCookie(storageType)) {
// console.log('SET as cookie', saveValue)
var _oldValue2 = parse(getCookie(key));
setCookie(key, saveValue);
return {

@@ -237,9 +249,11 @@ value: value,

if (!key) return false;
var storage = getStorageType(options);
var storageType = getStorageType(options);
if (useLocal(storage)) {
if (useLocal(storageType)) {
/* 1. Try localStorage */
localStorage.removeItem(key);
return LOCAL_STORAGE;
} else if (useCookie(storage)) {
} else if (useCookie(storageType)) {
/* 2. Fallback to cookie */
removeCookie(key);
return COOKIE;

@@ -265,12 +279,6 @@ }

}
var index = {
getItem: getItem,
setItem: setItem,
removeItem: removeItem,
hasLocalStorageSupport: hasLocalStorage,
getCookie: getCookie,
setCookie: setCookie,
removeCookie: removeCookie,
hasCookieSupport: hasCookieSupport
removeItem: removeItem
};

@@ -281,2 +289,7 @@

exports.removeItem = removeItem;
exports.getCookie = getCookie;
exports.setCookie = setCookie;
exports.removeCookie = removeCookie;
exports.hasLocalStorageSupport = hasLocalStorage;
exports.hasCookieSupport = hasCookieSupport;
exports.default = index;

@@ -283,0 +296,0 @@

2

dist/@analytics/storage-utils.min.js

@@ -1,1 +0,1 @@

var analyticsUtilStorage=function(t){"use strict";var e=function(){};function o(){try{return-1!==document.cookie.indexOf("___c")}catch(t){return!1}}var u=e,r=e;function n(){try{if("undefined"==typeof localStorage||"undefined"==typeof JSON)return!1;localStorage.setItem("__test","1"),localStorage.removeItem("__test")}catch(t){return!1}return!0}function l(t){return(l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(e){var o;try{void 0===(o=JSON.parse(e))&&(o=e),"true"===o&&(o=!0),"false"===o&&(o=!1),parseFloat(o)===o&&"object"!==l(o)&&(o=parseFloat(o))}catch(t){o=e}return o}function f(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0!==this?this:{}}var c="localStorage",g="cookie",v="global",a=n(),s=o();function m(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(!t)return null;var o,r=S(e);if("all"===r)return{cookie:i(u(o=t)),localStorage:i(localStorage.getItem(o)),global:f[o]||null};if(p(r)){var n=localStorage.getItem(t);if(n||r===c)return i(n)}if(b(r)){var l=u(t);if(l||r===g)return i(l)}return f[t]||null}function d(t,e){var o=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};if(!t||!e)return!1;var r=S(o),n=JSON.stringify(e);if(p(r)){var l=i(localStorage.getItem(t));return localStorage.setItem(t,n),{value:e,oldValue:l,location:c}}if(b(r))return{value:e,oldValue:i(u(t)),location:g};var a=f[t];return{value:f[t]=e,oldValue:a,location:v}}function y(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(!t)return!1;var o=S(e);return p(o)?(localStorage.removeItem(t),c):b(o)?g:(f[t]=null,v)}function S(t){return"string"==typeof t?t:t.storage}function p(t){return a&&(!t||t===c)}function b(t){return s&&(!t||t===g)}var I={getItem:m,setItem:d,removeItem:y,hasLocalStorageSupport:n,getCookie:u,setCookie:r,removeCookie:function(t){return e(t,"",-1)},hasCookieSupport:o};return t.getItem=m,t.setItem=d,t.removeItem=y,t.default=I,t}({});
var analyticsUtilStorage=function(t){"use strict";function o(t,e,o,n,r,a){if("undefined"!=typeof window)return 1<arguments.length?document.cookie="".concat(t,"=").concat(encodeURIComponent(e)).concat(o?"; expires=".concat(new Date(+new Date+1e3*o).toUTCString()):"").concat(n?"; path=".concat(n):"").concat(r?"; domain=".concat(r):"").concat(a?"; secure":""):decodeURIComponent(("; ".concat(document.cookie).split("; ".concat(t,"="))[1]||"").split(";")[0])}function e(){try{var t="___c";o(t,"1");var e=-1!==document.cookie.indexOf(t);return o(t,"",-1),e}catch(t){return!1}}var i=o,u=o;function n(t){return o(t,"",-1)}function r(){try{if("undefined"==typeof localStorage||"undefined"==typeof JSON)return!1;localStorage.setItem("__test","1"),localStorage.removeItem("__test")}catch(t){return!1}return!0}function a(t){return(a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function f(e){var o;try{void 0===(o=JSON.parse(e))&&(o=e),"true"===o&&(o=!0),"false"===o&&(o=!1),parseFloat(o)===o&&"object"!==a(o)&&(o=parseFloat(o))}catch(t){o=e}return o}function d(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0!==this?this:{}}var g="localStorage",s="cookie",m="global",c=r(),l=e();function v(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(!t)return null;var o,n=S(e);if("all"===n)return{cookie:f(i(o=t)),localStorage:f(localStorage.getItem(o)),global:d[o]||null};if(I(n)){var r=localStorage.getItem(t);if(r||n===g)return f(r)}if(b(n)){var a=i(t);if(a||n===s)return f(a)}return d[t]||null}function p(t,e){var o=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};if(!t||!e)return!1;var n=S(o),r=JSON.stringify(e);if(I(n)){var a=f(localStorage.getItem(t));return localStorage.setItem(t,r),{value:e,oldValue:a,location:g}}if(b(n)){var c=f(i(t));return u(t,r),{value:e,oldValue:c,location:s}}var l=d[t];return{value:d[t]=e,oldValue:l,location:m}}function y(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(!t)return!1;var o=S(e);return I(o)?(localStorage.removeItem(t),g):b(o)?(n(t),s):(d[t]=null,m)}function S(t){return"string"==typeof t?t:t.storage}function I(t){return c&&(!t||t===g)}function b(t){return l&&(!t||t===s)}var h={getItem:v,setItem:p,removeItem:y};return t.getItem=v,t.setItem=p,t.removeItem=y,t.getCookie=i,t.setCookie=u,t.removeCookie=n,t.hasLocalStorageSupport=r,t.hasCookieSupport=e,t.default=h,t}({});

@@ -101,10 +101,10 @@ 'use strict';

if (!key) return null;
var storage = getStorageType(options); // Get value from all locations
var storageType = getStorageType(options); // Get value from all locations
if (storage === 'all') return getAll(key);
if (storageType === 'all') return getAll(key);
/* 1. Try localStorage */
if (useLocal(storage)) {
if (useLocal(storageType)) {
var value = localStorage.getItem(key);
if (value || storage === LOCAL_STORAGE) return parse(value);
if (value || storageType === LOCAL_STORAGE) return parse(value);
}

@@ -114,6 +114,6 @@ /* 2. Fallback to cookie */

if (useCookie(storage)) {
if (useCookie(storageType)) {
var _value = cookieUtils.getCookie(key);
if (_value || storage === COOKIE) return parse(_value);
if (_value || storageType === COOKIE) return parse(_value);
}

@@ -146,7 +146,7 @@ /* 3. Fallback to window/global. */

if (!key || !value) return false;
var storage = getStorageType(options);
var storageType = getStorageType(options);
var saveValue = JSON.stringify(value);
/* 1. Try localStorage */
if (useLocal(storage)) {
if (useLocal(storageType)) {
// console.log('SET as localstorage', saveValue)

@@ -165,3 +165,3 @@ var _oldValue = parse(localStorage.getItem(key));

if (useCookie(storage)) {
if (useCookie(storageType)) {
// console.log('SET as cookie', saveValue)

@@ -198,9 +198,9 @@ var _oldValue2 = parse(cookieUtils.getCookie(key));

if (!key) return false;
var storage = getStorageType(options);
var storageType = getStorageType(options);
if (useLocal(storage)) {
if (useLocal(storageType)) {
/* 1. Try localStorage */
localStorage.removeItem(key);
return LOCAL_STORAGE;
} else if (useCookie(storage)) {
} else if (useCookie(storageType)) {
/* 2. Fallback to cookie */

@@ -228,17 +228,16 @@ cookieUtils.removeCookie(key);

}
var index = {
getItem: getItem,
setItem: setItem,
removeItem: removeItem,
hasLocalStorageSupport: hasLocalStorage,
getCookie: cookieUtils.getCookie,
setCookie: cookieUtils.setCookie,
removeCookie: cookieUtils.removeCookie,
hasCookieSupport: cookieUtils.hasCookieSupport
removeItem: removeItem
};
exports.getCookie = cookieUtils.getCookie;
exports.setCookie = cookieUtils.setCookie;
exports.removeCookie = cookieUtils.removeCookie;
exports.hasCookieSupport = cookieUtils.hasCookieSupport;
exports.getItem = getItem;
exports.setItem = setItem;
exports.removeItem = removeItem;
exports.hasLocalStorageSupport = hasLocalStorage;
exports.default = index;

@@ -1,2 +0,3 @@

import { getCookie, setCookie, removeCookie, hasCookieSupport } from '@analytics/cookie-utils';
import { hasCookieSupport, getCookie, setCookie, removeCookie } from '@analytics/cookie-utils';
export { getCookie, setCookie, removeCookie, hasCookieSupport } from '@analytics/cookie-utils';

@@ -97,10 +98,10 @@ function hasLocalStorage() {

if (!key) return null;
var storage = getStorageType(options); // Get value from all locations
var storageType = getStorageType(options); // Get value from all locations
if (storage === 'all') return getAll(key);
if (storageType === 'all') return getAll(key);
/* 1. Try localStorage */
if (useLocal(storage)) {
if (useLocal(storageType)) {
var value = localStorage.getItem(key);
if (value || storage === LOCAL_STORAGE) return parse(value);
if (value || storageType === LOCAL_STORAGE) return parse(value);
}

@@ -110,6 +111,6 @@ /* 2. Fallback to cookie */

if (useCookie(storage)) {
if (useCookie(storageType)) {
var _value = getCookie(key);
if (_value || storage === COOKIE) return parse(_value);
if (_value || storageType === COOKIE) return parse(_value);
}

@@ -142,7 +143,7 @@ /* 3. Fallback to window/global. */

if (!key || !value) return false;
var storage = getStorageType(options);
var storageType = getStorageType(options);
var saveValue = JSON.stringify(value);
/* 1. Try localStorage */
if (useLocal(storage)) {
if (useLocal(storageType)) {
// console.log('SET as localstorage', saveValue)

@@ -161,3 +162,3 @@ var _oldValue = parse(localStorage.getItem(key));

if (useCookie(storage)) {
if (useCookie(storageType)) {
// console.log('SET as cookie', saveValue)

@@ -194,9 +195,9 @@ var _oldValue2 = parse(getCookie(key));

if (!key) return false;
var storage = getStorageType(options);
var storageType = getStorageType(options);
if (useLocal(storage)) {
if (useLocal(storageType)) {
/* 1. Try localStorage */
localStorage.removeItem(key);
return LOCAL_STORAGE;
} else if (useCookie(storage)) {
} else if (useCookie(storageType)) {
/* 2. Fallback to cookie */

@@ -224,15 +225,9 @@ removeCookie(key);

}
var index = {
getItem: getItem,
setItem: setItem,
removeItem: removeItem,
hasLocalStorageSupport: hasLocalStorage,
getCookie: getCookie,
setCookie: setCookie,
removeCookie: removeCookie,
hasCookieSupport: hasCookieSupport
removeItem: removeItem
};
export default index;
export { getItem, setItem, removeItem };
export { getItem, setItem, removeItem, hasLocalStorage as hasLocalStorageSupport };

@@ -102,10 +102,10 @@ 'use strict';

if (!key) return null;
var storage = getStorageType(options); // Get value from all locations
var storageType = getStorageType(options); // Get value from all locations
if (storage === 'all') return getAll(key);
if (storageType === 'all') return getAll(key);
/* 1. Try localStorage */
if (useLocal(storage)) {
if (useLocal(storageType)) {
var value = localStorage.getItem(key);
if (value || storage === LOCAL_STORAGE) return parse(value);
if (value || storageType === LOCAL_STORAGE) return parse(value);
}

@@ -115,6 +115,6 @@ /* 2. Fallback to cookie */

if (useCookie(storage)) {
if (useCookie(storageType)) {
var _value = cookieUtils.getCookie(key);
if (_value || storage === COOKIE) return parse(_value);
if (_value || storageType === COOKIE) return parse(_value);
}

@@ -147,7 +147,7 @@ /* 3. Fallback to window/global. */

if (!key || !value) return false;
var storage = getStorageType(options);
var storageType = getStorageType(options);
var saveValue = JSON.stringify(value);
/* 1. Try localStorage */
if (useLocal(storage)) {
if (useLocal(storageType)) {
// console.log('SET as localstorage', saveValue)

@@ -166,3 +166,3 @@ var _oldValue = parse(localStorage.getItem(key));

if (useCookie(storage)) {
if (useCookie(storageType)) {
// console.log('SET as cookie', saveValue)

@@ -199,9 +199,9 @@ var _oldValue2 = parse(cookieUtils.getCookie(key));

if (!key) return false;
var storage = getStorageType(options);
var storageType = getStorageType(options);
if (useLocal(storage)) {
if (useLocal(storageType)) {
/* 1. Try localStorage */
localStorage.removeItem(key);
return LOCAL_STORAGE;
} else if (useCookie(storage)) {
} else if (useCookie(storageType)) {
/* 2. Fallback to cookie */

@@ -229,17 +229,16 @@ cookieUtils.removeCookie(key);

}
var index = {
getItem: getItem,
setItem: setItem,
removeItem: removeItem,
hasLocalStorageSupport: hasLocalStorage,
getCookie: cookieUtils.getCookie,
setCookie: cookieUtils.setCookie,
removeCookie: cookieUtils.removeCookie,
hasCookieSupport: cookieUtils.hasCookieSupport
removeItem: removeItem
};
exports.getCookie = cookieUtils.getCookie;
exports.setCookie = cookieUtils.setCookie;
exports.removeCookie = cookieUtils.removeCookie;
exports.hasCookieSupport = cookieUtils.hasCookieSupport;
exports.getItem = getItem;
exports.setItem = setItem;
exports.removeItem = removeItem;
exports.hasLocalStorageSupport = hasLocalStorage;
exports.default = index;

@@ -1,2 +0,3 @@

import { getCookie, setCookie, removeCookie, hasCookieSupport } from '@analytics/cookie-utils';
import { hasCookieSupport, getCookie, setCookie, removeCookie } from '@analytics/cookie-utils';
export { getCookie, setCookie, removeCookie, hasCookieSupport } from '@analytics/cookie-utils';

@@ -98,10 +99,10 @@ function hasLocalStorage() {

if (!key) return null;
var storage = getStorageType(options); // Get value from all locations
var storageType = getStorageType(options); // Get value from all locations
if (storage === 'all') return getAll(key);
if (storageType === 'all') return getAll(key);
/* 1. Try localStorage */
if (useLocal(storage)) {
if (useLocal(storageType)) {
var value = localStorage.getItem(key);
if (value || storage === LOCAL_STORAGE) return parse(value);
if (value || storageType === LOCAL_STORAGE) return parse(value);
}

@@ -111,6 +112,6 @@ /* 2. Fallback to cookie */

if (useCookie(storage)) {
if (useCookie(storageType)) {
var _value = getCookie(key);
if (_value || storage === COOKIE) return parse(_value);
if (_value || storageType === COOKIE) return parse(_value);
}

@@ -143,7 +144,7 @@ /* 3. Fallback to window/global. */

if (!key || !value) return false;
var storage = getStorageType(options);
var storageType = getStorageType(options);
var saveValue = JSON.stringify(value);
/* 1. Try localStorage */
if (useLocal(storage)) {
if (useLocal(storageType)) {
// console.log('SET as localstorage', saveValue)

@@ -162,3 +163,3 @@ var _oldValue = parse(localStorage.getItem(key));

if (useCookie(storage)) {
if (useCookie(storageType)) {
// console.log('SET as cookie', saveValue)

@@ -195,9 +196,9 @@ var _oldValue2 = parse(getCookie(key));

if (!key) return false;
var storage = getStorageType(options);
var storageType = getStorageType(options);
if (useLocal(storage)) {
if (useLocal(storageType)) {
/* 1. Try localStorage */
localStorage.removeItem(key);
return LOCAL_STORAGE;
} else if (useCookie(storage)) {
} else if (useCookie(storageType)) {
/* 2. Fallback to cookie */

@@ -225,15 +226,9 @@ removeCookie(key);

}
var index = {
getItem: getItem,
setItem: setItem,
removeItem: removeItem,
hasLocalStorageSupport: hasLocalStorage,
getCookie: getCookie,
setCookie: setCookie,
removeCookie: removeCookie,
hasCookieSupport: hasCookieSupport
removeItem: removeItem
};
export default index;
export { getItem, setItem, removeItem };
export { getItem, setItem, removeItem, hasLocalStorage as hasLocalStorageSupport };
{
"name": "@analytics/storage-utils",
"version": "0.2.1",
"version": "0.2.2",
"description": "Storage utilities for saving values in browser",

@@ -49,4 +49,5 @@ "author": "David Wells",

"dependencies": {
"@analytics/cookie-utils": "^0.2.1"
}
"@analytics/cookie-utils": "^0.2.2"
},
"gitHead": "bb1865b49b78e9aae3acac4018c46cea35ef2695"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc