UNPKG

@gecut/utilities

Version:

The ultimate utility toolkit from Gecut Company, crafted with TypeScript for optimal speed and efficiency. Designed to boost productivity with a suite of fast and optimized tools.

24 lines 652 B
import { isNode } from './browser-or-node.js'; import { parseJson } from './parse-json.js'; function get(name, defaultValue) { if (isNode()) return defaultValue; const value = localStorage.getItem(name); if (value == null || value === 'null' || value === 'undefined') { return defaultValue; } return parseJson(value) ?? defaultValue; } function set(name, value) { if (isNode()) return; if (value == null) { return localStorage.removeItem(name); } localStorage.setItem(name, JSON.stringify(value)); } export default { get, set, }; //# sourceMappingURL=local-storage-json.js.map