Registry / database / can-local-store

can-local-store

JSON →
library1.0.1jsnpmunverified

can-local-store is a client-side data persistence library for the CanJS framework, providing a localStorage-backed database for `can/Map` and `can/List` instances. It enables developers to automatically serialize and deserialize data to and from the browser's `localStorage` API, making it easy to store and retrieve application state or user data directly in the browser. The current stable version is 1.0.1, last released in October 2017. Due to its age and lack of updates since then, the package is considered abandoned, with no ongoing development or maintenance. Its key differentiator was its deep integration with CanJS's observable data structures, allowing seamless persistence without boilerplate. However, modern CanJS applications or new projects would typically opt for more actively maintained state management solutions or direct `localStorage` wrappers.

npm install can-local-store
INSTALL
IMPORT
SIG · CAN-LOCAL-STORE
C
can-local-store
databasejavascriptv1.0.1
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Map
✓ import Map from 'can-local-store/map';
✗ import { Map } from 'can-local-store'; // Incorrect named import from root import Map from 'can-local-store'; // Root default import usually refers to the main 'Map' store, but subpath is clearer
Imports a `can/Map` extended with localStorage persistence. This is the primary way to define models.
List
✓ import List from 'can-local-store/list';
✗ import { List } from 'can-local-store'; // Incorrect named import from root
Imports a `can/List` extended with localStorage persistence. Used for collections of models.
localStore
✓ import localStore from 'can-local-store'; // Or import Store from 'can-local-store';
✗ const localStore = require('can-local-store');
The root import often re-exports the `Map` variant or a factory function. The documentation primarily guides towards subpath imports for clarity. The d.ts indicates the default export is `can-local-store/map`.

Demonstrates defining a CanJS Map-based model with `can-local-store`, then performing CRUD (Create, Read, Update, Delete) operations that persist data in the browser's `localStorage`.

import Map from 'can-local-store/map'; // Define a Todo model that uses can-local-store/map interface TodoAttributes { id?: number; name: string; completed: boolean; } const Todo = Map.extend<TodoAttributes>('todo', { // `todo` is the localStorage key for this model's data seal: false, // Recommended for can-define-stream compatibility init: function(this: any) { if (!this.id) { // Simple ID generation for example purposes this.id = Date.now(); } } }); async function runExample() { console.log('--- can-local-store example ---'); // Create a new todo item const newTodo = new Todo({ name: 'Learn can-local-store', completed: false }); await newTodo.save(); // Saves to localStorage under the key 'todo' console.log('Created todo:', newTodo.serialize()); console.log('localStorage content (key "todo"):', localStorage.getItem('todo')); // Find all todos (loads from localStorage) const todos = await Todo.findAll({}); console.log('All todos after creation:', todos.serialize()); // Update an existing todo const firstTodo = todos.get(0); if (firstTodo) { firstTodo.completed = true; await firstTodo.save(); // Updates in localStorage console.log('Updated todo:', firstTodo.serialize()); console.log('localStorage content (key "todo"):', localStorage.getItem('todo')); } // Find a specific todo by ID const foundTodo = await Todo.findOne({ id: newTodo.id }); console.log('Found todo by ID:', foundTodo?.serialize()); // Delete a todo if (foundTodo) { await foundTodo.destroy(); // Removes from localStorage console.log('Deleted todo:', foundTodo.serialize()); console.log('localStorage content (key "todo"):', localStorage.getItem('todo')); } // Verify deletion by fetching all remaining todos const remainingTodos = await Todo.findAll({}); console.log('Remaining todos:', remainingTodos.serialize()); // Clean up localStorage completely for this example localStorage.removeItem('todo'); console.log('localStorage "todo" key cleared.'); } runExample().catch(console.error);
Debug
Known issues
breakingThe package is considered abandoned, with its last release in October 2017. It is unlikely to receive updates for newer browser features, JavaScript standards, or security patches, and may have compatibility issues with modern CanJS versions (beyond those specified in its peer dependencies) or other contemporary libraries.
fix
Consider migrating to a more actively maintained client-side storage solution or a direct `localStorage` wrapper if starting a new project or updating an existing one.
affects: >=1.0.1
gotcha`localStorage` has a limited storage capacity (typically 5-10 MB per origin). Attempting to store too much data will result in a `QuotaExceededError` or data loss, without graceful degradation unless explicitly handled.
fix
Implement robust error handling around `localStorage` operations and consider alternative storage solutions (e.g., IndexedDB) for larger datasets. Monitor storage usage and prune old data.
affects: >=1.0.0
gotcha`localStorage` operations are synchronous and can block the main thread. Storing or retrieving large amounts of data can lead to UI freezes and a poor user experience, especially on slower devices.
fix
For performance-critical applications or large data sets, use asynchronous storage solutions like IndexedDB or a web worker to offload synchronous `localStorage` operations.
affects: >=1.0.0
gotchaData stored in `localStorage` is not secure and can be accessed or modified by any JavaScript code running on the same origin (e.g., via Cross-Site Scripting). Sensitive user information, authentication tokens, or highly confidential data should never be stored here.
fix
Avoid storing sensitive information. For secure client-side storage, consider using HTTP-only cookies for authentication tokens or server-side storage for critical data.
affects: >=1.0.0
gotchacan-local-store automatically serializes data using `JSON.stringify` and deserializes using `JSON.parse`. This means only JSON-serializable data types (strings, numbers, booleans, null, arrays, plain objects) can be reliably stored. Custom classes, Dates, RegExps, or functions will lose their type or information upon serialization.
fix
Ensure all data intended for storage is JSON-serializable. Manually serialize/deserialize complex types to and from their JSON-compatible representations before interacting with the store.
affects: >=1.0.0
Errors
Common errors & fixes
DOMException: QuotaExceededError: The quota has been exceeded.
Attempting to write more data to localStorage than the browser's allocated limit (typically 5-10 MB per origin) allows.
fix
Reduce the amount of data being stored, implement a caching strategy to only store essential data, or migrate to a different storage mechanism like IndexedDB for larger datasets. Ensure `localStorage.removeItem()` or `localStorage.clear()` is used for cleanup when data is no longer needed.
TypeError: Converting circular structure to JSON
`can-local-store` uses `JSON.stringify` internally, which cannot handle objects with circular references (where an object directly or indirectly refers back to itself).
fix
Before saving, ensure that any data passed to `can-local-store` (via `Map` or `List` instances) does not contain circular references. Manually transform the data to a non-circular structure if necessary.
Property 'save' does not exist on type 'Map<T>'
This usually indicates an issue with how the CanJS `Map` is defined or how `can-local-store/map` is integrated, possibly due to incorrect peer dependency versions or an outdated CanJS setup.
fix
Verify that `can-define` and other peer dependencies are installed and compatible with `can-local-store@1.0.1`. Ensure the `Map` is correctly extended with `can-local-store/map` and that the instance methods like `save()` are available on the created model instance.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
can-definerequiredPeer dependency required for defining observable maps and lists.
can-observationrequiredPeer dependency for observable tracking within CanJS.
can-reflectrequiredPeer dependency for meta programming and reflection utilities in CanJS.
Agent activity
18 hits · last 30 days
node
14
OpenAI (training)
1
Resources
can-local-store — npm install can-local-store · libregistry