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

@form-guardian/core

v1.0.5

Published

Headless core library for form autosave functionality. Provides IndexedDB storage, draft management, and TTL support. Framework-agnostic and works with any JavaScript environment.

Downloads

472

Readme

@form-guardian/core

Headless core library for form autosave functionality. Provides IndexedDB storage, draft management, and TTL support. Framework-agnostic and works with any JavaScript environment.

Overview

@form-guardian/core is the foundation of Form Guardian. It provides low-level APIs for saving, loading, and managing form drafts using IndexedDB. This package has no framework dependencies and can be used in any JavaScript environment (browser, Node.js with polyfills, etc.).

Installation

npm install @form-guardian/core

Features

  • IndexedDB Storage - Persistent storage for form drafts
  • TTL Support - Automatic expiration of drafts
  • Draft Management - Save, load, check, and clear drafts
  • Framework Agnostic - Works with any JavaScript framework or vanilla JS
  • TypeScript Support - Full type definitions included

API

saveDraftCore<T>(draftId, values, options?)

Save form values as a draft.

import { saveDraftCore } from '@form-guardian/core';

await saveDraftCore('my-form', { name: 'John', email: '[email protected]' }, {
  formId: 'my-form',
  origin: window.location.origin,
  ttl: { days: 7 }
});

loadDraftCore<T>(draftId, options?)

Load a saved draft.

import { loadDraftCore } from '@form-guardian/core';

const draft = await loadDraftCore('my-form', { ttl: { days: 7 } });
if (draft) {
  console.log(draft.values); // { name: 'John', email: '[email protected]' }
  console.log(draft.updatedAt); // timestamp
}

hasDraftCore(draftId)

Check if a draft exists.

import { hasDraftCore } from '@form-guardian/core';

const exists = await hasDraftCore('my-form');

clearDraft(draftId)

Remove a draft from storage.

import { clearDraft } from '@form-guardian/core';

await clearDraft('my-form');

makeDraftId(formId, options?)

Generate a unique draft ID with optional origin and prefix.

import { makeDraftId } from '@form-guardian/core';

const draftId = makeDraftId('my-form', {
  includeOrigin: true,
  prefix: 'fg'
});

debounce(func, wait)

Utility function for debouncing function calls.

import { debounce } from '@form-guardian/core';

const debouncedSave = debounce((values) => {
  saveDraftCore('my-form', values);
}, 500);

Storage

The package uses IndexedDBStorage by default, which implements the DraftStorage interface. You can also create custom storage implementations:

import type { DraftStorage, DraftData } from '@form-guardian/core';

class CustomStorage implements DraftStorage {
  async save<T>(draftId: string, data: DraftData<T>): Promise<void> {
    // Custom save logic
  }
  
  async load<T>(draftId: string): Promise<DraftData<T> | null> {
    // Custom load logic
  }
  
  async remove(draftId: string): Promise<void> {
    // Custom remove logic
  }
  
  async has(draftId: string): Promise<boolean> {
    // Custom has logic
  }
}

TTL (Time To Live)

Drafts can automatically expire after a specified time:

// Expire after 7 days
await saveDraftCore('my-form', values, {
  ttl: { days: 7 }
});

// Expire after 2 hours
await saveDraftCore('my-form', values, {
  ttl: { hours: 2 }
});

// Expire after 30 minutes
await saveDraftCore('my-form', values, {
  ttl: { minutes: 30 }
});

// Expire after specific milliseconds
await saveDraftCore('my-form', values, {
  ttl: 86400000 // 1 day in milliseconds
});

When to Use

Use @form-guardian/core directly if you:

  • Need low-level control over draft storage
  • Are building a custom integration
  • Want to implement your own DOM/form handling logic
  • Are working in a non-browser environment (with polyfills)

For most use cases, consider using:

  • @form-guardian/dom - for universal DOM-based autosave
  • @form-guardian/react - for React-specific hooks