Meteor.js Usage for ClientStorage

April 27, 2026 · View on GitHub

Install

meteor add ostrio:cstorage
# or meteor npm install --save @veliovgroup/client-storage

Import

As Meteor/Atmosphere package

import { ClientStorage } from 'meteor/ostrio:cstorage';
const clientStorage = new ClientStorage();

As NPM package

import { ClientStorage } from '@veliovgroup/client-storage';
const clientStorage = new ClientStorage();

Full API and examples in README.md.

TypeScript

Atmosphere package includes index.d.ts via zodern:types.

import { ClientStorage } from 'meteor/ostrio:cstorage';

const storage = new ClientStorage('localStorage');
const saved: boolean = storage.set('layout', 'two-columns');
const layout: unknown = storage.get('layout');

ReactiveVar Wrapper

Improved wrapper (uses storage for persistence):

import { ReactiveVar } from 'meteor/reactive-var';
import { Tracker } from 'meteor/tracker';
import { ClientStorage } from 'meteor/ostrio:cstorage';

const persistentReactive = (key, initial = undefined) => {
  const storage = new ClientStorage();
  const rv = new ReactiveVar(
    storage.has(key) ? storage.get(key) : initial
  );

  rv.set = function (newValue) {
    const oldValue = rv.curValue;
    if (Tracker.nonreactive(() => rv.equals(oldValue, newValue))) return;
    rv.curValue = newValue;
    storage.set(key, newValue);
    rv.dep.changed();
  };

  return rv;
};

// Usage
const layout = persistentReactive('ui-layout', 'two-columns');
console.log(layout.get()); // two-columns
layout.set('single-column'); // persists + reactive

Running Tests

  1. Clone this package
  2. In Terminal (Console) go to directory where package is cloned
  3. Then run:

Meteor/Tinytest

# Default
meteor test-packages ./

# With custom port
meteor test-packages ./ --port 8888

# With local MongoDB and custom port
MONGO_URL="mongodb://127.0.0.1:27017/client-storage-tests" meteor test-packages ./ --port 8888

Uses Tinytest. Covers all drivers, TTL async, Unicode, objects, edges. Jest for NPM side.

See README.md for general usage.

Support this project