{"id":49361,"library":"simple-memory-storage","title":"Simple Memory Storage","description":"A lightweight, zero-dependency in-memory storage implementation that mirrors the Web Storage API (localStorage/sessionStorage). Version 1.0.0 is the initial stable release, with no further updates since. It provides a simple JavaScript object-based store with methods: setItem, getItem, removeItem, clear, key, and length. Differentiates from localStorage by not persisting data, making it ideal for testing and ephemeral state in Node.js or browser environments. Includes TypeScript types.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/bouzuya/simple-memory-storage","tags":["javascript","typescript"],"install":[{"cmd":"npm install simple-memory-storage","lang":"bash","label":"npm"},{"cmd":"yarn add simple-memory-storage","lang":"bash","label":"yarn"},{"cmd":"pnpm add simple-memory-storage","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Only named export available; default import will cause runtime error.","wrong":"import SimpleMemoryStorage from 'simple-memory-storage'","symbol":"SimpleMemoryStorage","correct":"import { SimpleMemoryStorage } from 'simple-memory-storage'"},{"note":"Package is ESM-only; CommonJS require is not supported.","wrong":"const { SimpleMemoryStorage } = require('simple-memory-storage')","symbol":"SimpleMemoryStorage","correct":"import { SimpleMemoryStorage } from 'simple-memory-storage'"},{"note":"Dynamic import works in ESM; require will throw MODULE_NOT_FOUND.","wrong":"const SimpleMemoryStorage = require('simple-memory-storage')","symbol":"SimpleMemoryStorage","correct":"const { SimpleMemoryStorage } = await import('simple-memory-storage')"}],"quickstart":{"code":"import { SimpleMemoryStorage } from 'simple-memory-storage';\n\nconst storage = new SimpleMemoryStorage();\nstorage.setItem('key1', 'value1');\nconsole.log(storage.length); // 1\nconsole.log(storage.key(0)); // 'key1'\nconsole.log(storage.getItem('key1')); // 'value1'\n\nstorage.setItem('key2', 'value2');\nconsole.log(storage.length); // 2\nconsole.log(storage.getItem('key2')); // 'value2'\n\nstorage.removeItem('key2');\nconsole.log(storage.getItem('key2')); // null\n\nstorage.clear();\nconsole.log(storage.length); // 0","lang":"typescript","description":"Instantiate SimpleMemoryStorage and use Web Storage API methods (setItem, getItem, removeItem, clear, key, length)."},"warnings":[{"fix":"Create a single instance and pass it around, or use a global singleton pattern.","message":"Storage is not shared between instances; each SimpleMemoryStorage has its own independent data.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always read length after calling setItem/removeItem/clear to get the current count.","message":"The length property is a number that only updates after mutations; it is not reactive.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Check if the returned value is null before using it as a key.","message":"key() returns null if index is out of bounds; does not throw an error.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use JSON.stringify/parse for non-string data.","message":"The storage only stores string values; other types are coerced to strings.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.0.0':22 'api':19 'base':40 'browser':69 'clear':47 'data':57 'depend':8 'differenti':51 'environ':70 'ephemer':64 'getitem':45 'ideal':60 'implement':13 'in-memori':9 'includ':71 'initi':25 'javascript':37,74 'key':48 'length':50 'lightweight':5 'localstorag':53 'localstorage/sessionstorage':20 'make':58 'memori':2,11 'method':43 'mirror':15 'node.js':67 'object':39 'object-bas':38 'persist':56 'provid':34 'releas':27 'removeitem':46 'setitem':44 'simpl':1,36 'sinc':32 'stabl':26 'state':65 'storag':3,12,18 'store':41 'test':62 'type':73 'typescript':72,75 'updat':31 'version':21 'web':17 'zero':7 'zero-depend':6","created_at":"2026-06-07T17:01:22.223149+00:00","updated_at":"2026-06-07T17:01:22.223149+00:00","problems":[{"fix":"Change to `import { SimpleMemoryStorage } from 'simple-memory-storage'`.","cause":"Using default import instead of named import.","error":"TypeError: simple_memory_storage_1.SimpleMemoryStorage is not a constructor"},{"fix":"Switch to ESM imports (`import { SimpleMemoryStorage } from 'simple-memory-storage'`) or use dynamic import in CommonJS.","cause":"Attempting to use CommonJS require on an ESM-only package.","error":"Cannot find module 'simple-memory-storage'"},{"fix":"Use `storage.key(index)` instead of `storage[index]`.","cause":"Using a numeric index directly on the storage object instead of the key() method.","error":"TypeError: storage.key is not a function"}],"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/bouzuya/simple-memory-storage#readme","github":"https://github.com/bouzuya/simple-memory-storage","docs":null,"changelog":null,"pypi":null,"npm":"simple-memory-storage","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}}