npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

local-first-sync-engine

v1.0.2

Published

A local-first sync engine for offline-first apps using IndexedDB and server sync.

Readme

Local-First Sync Engine

A lightweight, modular JavaScript (ES6+) library for building offline-first applications. Data is persisted locally using IndexedDB and synchronized with a remote server when connectivity is available. Designed for easy integration into web apps and PWAs.


Key Features

  • Local persistence via IndexedDB.
  • Two-way sync: push (local → server) and pull (server → local).
  • Simple conflict resolution: last-write-wins (customizable).
  • Full CRUD while offline.
  • Modular codebase (store, sync, utils).
  • No external dependencies.

Project Layout

  • src/index.js — Public API entry.
  • src/store.js — IndexedDB store abstraction (CRUD, unsynced tracking).
  • src/sync.js — Synchronization (push/pull) logic.
  • src/utils.js — Helpers (ID generator, conflict resolver, etc.).
  • test/test.js — Simple local test script.
  • package.json — Package metadata.

Installation

Install from npm (when published):

npm install local-first-sync-engine

For local development:

git clone <repo-url>
cd local-first-sync-engine
npm install

Quick Start

Example (Node/bundler environment):

const { createStore, syncWithServer } = require('local-first-sync-engine');

(async () => {
  const store = createStore('my-store');

  // Create
  const item = await store.addItem({ title: 'Note 1', body: 'Content' });

  // Update
  await store.updateItem(item.id, { title: 'Note 1 (edited)' });

  // Read
  const all = await store.getItems();
  console.log(all);

  // Sync with server
  await syncWithServer(store, 'https://api.example.com');
})();

Note: In-browser usage requires indexedDB and fetch.


API Reference

  • createStore(name)
    Create a LocalStore instance. Returns a store object.

LocalStore instance methods:

  • addItem(item) → Promise<{ id, data, lastModified, synced }>
  • updateItem(id, updates) → Promise
  • deleteItem(id) → Promise
  • getItems() → Promise
  • getUnsyncedItems() → Promise
  • markSynced(id) → Promise

Sync helper:

  • syncWithServer(store, serverUrl) → Promise
    Performs push of unsynced local items, then pulls updates from the server.

Server Contract (Example)

Expected endpoints:

  • POST {serverUrl}/sync/push
    Body: array of local items to push. Return 200 OK on success.

  • GET {serverUrl}/sync/pull
    Response: array of items in server format compatible with local items.

Customize authentication, data mapping, and responses per your server design.


Conflict Resolution

Default strategy: last-write-wins using lastModified timestamps. For complex merging, replace or extend resolveConflict in src/utils.js.


Browser Support & Notes

  • Requires modern browser with IndexedDB and Fetch API.
  • navigator.onLine used as a connectivity heuristic — consider active ping for reliability.
  • For production, consider:
    • Retry/backoff and exponential backoff on failures.
    • Persistent operation queue.
    • Authentication and encryption for data in transit and at rest.

Testing

Run the provided basic test:

npm test

This executes test/test.js to simulate local operations.


Publishing to npm (Quick)

  1. Verify package.json (name, version, main, license).
  2. Login:
npm login
  1. Publish:
npm publish

If the package name is taken, update the name field in package.json.


Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit and push changes
  4. Open a pull request with a clear description

Please run tests and follow code style conventions.


License

MIT — see LICENSE file.


Support

Open an issue in the repository for bugs, questions, or feature requests.

# Local-First Sync Engine

A lightweight, modular JavaScript (ES6+) library for building offline-first applications. Data is persisted locally using IndexedDB and synchronized with a remote server when connectivity is available. Designed for easy integration into web apps and PWAs.

---

## Key Features
- Local persistence via IndexedDB.
- Two-way sync: push (local → server) and pull (server → local).
- Simple conflict resolution: last-write-wins (customizable).
- Full CRUD while offline.
- Modular codebase (store, sync, utils).
- No external dependencies.

---

## Project Layout
- `src/index.js` — Public API entry.
- `src/store.js` — IndexedDB store abstraction (CRUD, unsynced tracking).
- `src/sync.js` — Synchronization (push/pull) logic.
- `src/utils.js` — Helpers (ID generator, conflict resolver, etc.).
- `test/test.js` — Simple local test script.
- `package.json` — Package metadata.

---

## Installation

Install from npm (when published):
```bash
npm install local-first-sync-engine

For local development:

git clone <repo-url>
cd local-first-sync-engine
npm install

Quick Start

Example (Node/bundler environment):

const { createStore, syncWithServer } = require('local-first-sync-engine');

(async () => {
  const store = createStore('my-store');

  // Create
  const item = await store.addItem({ title: 'Note 1', body: 'Content' });

  // Update
  await store.updateItem(item.id, { title: 'Note 1 (edited)' });

  // Read
  const all = await store.getItems();
  console.log(all);

  // Sync with server
  await syncWithServer(store, 'https://api.example.com');
})();

Note: In-browser usage requires indexedDB and fetch.


API Reference

  • createStore(name)
    Create a LocalStore instance. Returns a store object.

LocalStore instance methods:

  • addItem(item) → Promise<{ id, data, lastModified, synced }>
  • updateItem(id, updates) → Promise
  • deleteItem(id) → Promise
  • getItems() → Promise
  • getUnsyncedItems() → Promise
  • markSynced(id) → Promise

Sync helper:

  • syncWithServer(store, serverUrl) → Promise
    Performs push of unsynced local items, then pulls updates from the server.

Server Contract (Example)

Expected endpoints:

  • POST {serverUrl}/sync/push
    Body: array of local items to push. Return 200 OK on success.

  • GET {serverUrl}/sync/pull
    Response: array of items in server format compatible with local items.

Customize authentication, data mapping, and responses per your server design.


Conflict Resolution

Default strategy: last-write-wins using lastModified timestamps. For complex merging, replace or extend resolveConflict in src/utils.js.


Browser Support & Notes

  • Requires modern browser with IndexedDB and Fetch API.
  • navigator.onLine used as a connectivity heuristic — consider active ping for reliability.
  • For production, consider:
    • Retry/backoff and exponential backoff on failures.
    • Persistent operation queue.
    • Authentication and encryption for data in transit and at rest.

Testing

Run the provided basic test:

npm test

This executes test/test.js to simulate local operations.


Publishing to npm (Quick)

  1. Verify package.json (name, version, main, license).
  2. Login:
npm login
  1. Publish:
npm publish

If the package name is taken, update the name field in package.json.


Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit and push changes
  4. Open a pull request with a clear description

Please run tests and follow code style conventions.


License

MIT — see LICENSE file.


Support

Open an issue in the repository for bugs, questions, or feature requests.