UNPKG

@modern-kit/utils

Version:
20 lines (17 loc) 637 B
import { isClient } from '../../device/isClient/index.mjs'; import { isFunction } from '../../validator/isFunction/index.mjs'; import '../../device/isServer/index.mjs'; function setStorageItem(type, key, value) { if (!isClient()) { throw new Error("Cannot be executed unless it is a client environment."); } try { const storage = window[type]; const newValue = 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}`); } } export { setStorageItem }; //# sourceMappingURL=index.mjs.map