@modern-kit/utils
Version:
22 lines (18 loc) • 716 B
JavaScript
;
var deviceIsClient = require('../../device/isClient/index.cjs');
var validatorIsFunction = require('../../validator/isFunction/index.cjs');
require('../../device/isServer/index.cjs');
function setStorageItem(type, key, value) {
if (!deviceIsClient.isClient()) {
throw new Error("Cannot be executed unless it is a client environment.");
}
try {
const storage = window[type];
const newValue = validatorIsFunction.isFunction(value) ? value() : value;
storage.setItem(key, JSON.stringify(newValue));
} catch (err) {
throw new Error(`Failed to store data for key "${key}" in ${type}: ${err}`);
}
}
exports.setStorageItem = setStorageItem;
//# sourceMappingURL=index.cjs.map