{"id":48408,"library":"localit","title":"localit","description":"A lightweight (~1kB gzipped), fully-typed wrapper around the Web Storage API (localStorage / sessionStorage) with expiration support, optional key namespacing, and change event listeners. Version 6.1.0 is the latest stable release, actively maintained on GitHub. Unlike raw storage APIs, localit handles serialization automatically, supports expiration strings like '5m' or '2h', and allows listening to key changes via an `on` method. It requires no external dependencies and ships TypeScript type definitions.","status":"active","version":"6.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/alexmayol/localit","tags":["javascript","JavaScript","library","localStorage","sessionStorage","cache","store","Vite","TypeScript","typescript"],"install":[{"cmd":"npm install localit","lang":"bash","label":"npm"},{"cmd":"yarn add localit","lang":"bash","label":"yarn"},{"cmd":"pnpm add localit","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Named export only, no default export. TypeScript users must use named import.","wrong":"import localit from 'localit'","symbol":"localit","correct":"import { localit } from 'localit'"},{"note":"Type exported for convenience; avoid re-declaring.","wrong":"type ExpirationType = `${number}s` | `${number}m` | `${number}h` | `${number}d` | Date","symbol":"ExpirationType","correct":"import { ExpirationType } from 'localit'"},{"note":"Type exported; import rather than redefine.","wrong":"interface LocalitSetConfig { type?: Storage; family?: string; expiration?: ExpirationType; }","symbol":"LocalitSetConfig","correct":"import { LocalitSetConfig } from 'localit'"},{"note":"Type exported; import rather than redefine.","wrong":"interface LocalitGetConfig { type?: Storage; family?: string; }","symbol":"LocalitGetConfig","correct":"import { LocalitGetConfig } from 'localit'"}],"quickstart":{"code":"import { localit } from 'localit';\n\nlocalit.set('greeting', 'Hello, world!', { expiration: '1h' });\nconst value = localit.get<string>('greeting');\nconsole.log(value); // 'Hello, world!' (if not expired)\n\nlocalit.on('greeting', (newVal) => {\n  console.log('Greeting changed to:', newVal);\n});\n\nlocalit.set('greeting', 'Hi there!'); // triggers log\n\nlocalit.remove('greeting');\nconst afterDelete = localit.get('greeting');\nconsole.log(afterDelete); // null\n\nlocalit.set('config', { theme: 'dark' }, { family: 'app' });\nlocalit.clearFamily('app'); // removes 'app::config' and all other keys in family 'app'","lang":"typescript","description":"Demonstrates setting with expiration, typed get, change listener, removal, and family-based namespacing with clearFamily."},"warnings":[{"fix":"Use the native 'storage' event or a polyfill for cross-tab synchronization.","message":"`localit.on` only triggers for changes made via localit's set/remove methods, not for direct localStorage.setItem or other tabs.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Purge expired entries by calling `get` on them or periodically clearing storage with `bust()`.","message":"Expiration is checked on `get`; if a value expires between calls, it is removed and null returned. However, expired values are NOT automatically cleaned up unless you call `get` or `bust`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use `localit.remove('key', { family: 'familyName' })` to remove a namespaced key.","message":"When using `family`, keys are stored as `family::key`. Removal without specifying the family only deletes the unprefixed key.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Change to `import { localit } from 'localit'`.","message":"In version 5.x and earlier, the import was `import localit from 'localit'`. This default export is removed in v6.","severity":"deprecated","affected_versions":">=6.0.0"},{"fix":"Use valid format: e.g., '1d' for 1 day. Or pass a Date object.","message":"The expiration string format is strict: only `Xs`, `Xm`, `Xh`, `Xd` are supported (e.g., '5m', '2h'). Leading/trailing spaces or other units (e.g., '1day') will be ignored and no expiration is set.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1kb':4 '2h':52 '5m':50 '6.1.0':28 'activ':34 'allow':54 'api':14,41 'around':10 'automat':45 'cach':78 'chang':24,58 'definit':72 'depend':67 'event':25 'expir':18,47 'extern':66 'fulli':7 'fully-typ':6 'github':37 'gzip':5 'handl':43 'javascript':73,74 'key':21,57 'latest':31 'librari':75 'lightweight':3 'like':49 'listen':26,55 'localit':1,42 'localstorag':15,76 'maintain':35 'method':62 'namespac':22 'option':20 'raw':39 'releas':33 'requir':64 'serial':44 'sessionstorag':16,77 'ship':69 'stabl':32 'storag':13,40 'store':79 'string':48 'support':19,46 'type':8,71 'typescript':70,81,82 'unlik':38 'version':27 'via':59 'vite':80 'web':12 'wrapper':9","created_at":"2026-06-07T16:56:29.687755+00:00","updated_at":"2026-06-07T16:56:29.687755+00:00","problems":[{"fix":"Replace `import localit from 'localit'` with `import { localit } from 'localit'`.","cause":"Using default import instead of named import in bundler environment.","error":"TypeError: localit__WEBPACK_IMPORTED_MODULE_0___default(...).set is not a function"},{"fix":"Wrap usage in a try-catch or check `typeof window !== 'undefined'` before calling localit methods.","cause":"localStorage or sessionStorage is not available (e.g., in private browsing mode or SSR).","error":"Uncaught TypeError: Cannot read properties of null (reading 'set')"},{"fix":"Update to v6.1.0: `npm install localit@latest`. For v5, use `import localit from 'localit'`.","cause":"Package version is older than 6.0.0 where only a default export existed, or missing TypeScript types.","error":"TypeScript error: Module '\"localit\"' has no exported member 'localit'"},{"fix":"Ensure the `family` config matches between `set` and `get`. Or omit family entirely if not needed.","cause":"The key might be stored under a different `family` than expected, or storage was cleared externally.","error":"localit.get returns null even though I just set a value without expiration"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/alexmayol/localit#readme","github":"https://github.com/alexmayol/localit","docs":null,"changelog":null,"pypi":null,"npm":"localit","openapi_spec":null,"status_page":null,"smithery":null,"categories":["storage"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}