Skip to content

Releases: manuel-lohmus/data-context

v2.0.0

16 Oct 18:38

Choose a tag to compare

data-context v2.0.0

✨ Highlights

  • First-class TypeScript support: bundled index.d.ts with accurate, recursive DataContext typing for objects and arrays.
  • Stabilized event model: property events new, set, reposition, delete, plus bubbled - and debounced -change.
  • Smarter stringify: modified-data mode with optional includeBOM and correct handling of non-enumerable metadata.
  • Safer overwriting on parse: robust parse(text, DC) into existing contexts, preserving event wiring and metadata.
  • Node helper: watchJsonFile(...) to keep a JSON file in sync with a DataContext (Node-only).

What’s Added

  • Type definitions for the full API: createDataContext, parse, stringify, syncData, stringifyChanges, event APIs.
  • Options: includeBOM in stringify; ignoreMetadata toggle exposed publicly.
  • Watcher callbacks: onDataChange and onFileChange with strChanges, strJson, and datacontext.

Changes

  • Clearer, consistent event semantics and result reporting.
  • Dual package: CJS (require) and ESM (import via wrapper.mjs), with browser field for direct script usage.

Fixes

  • Consistent handling of metadata keys across parse/stringify.
  • More predictable overwrite semantics when parsing into existing contexts.

Migration Notes

  • No breaking API changes intended vs 1.x. If you relied on private internals, prefer the public API reflected in typings.
  • watchJsonFile is Node-only; it’s a no-op in browsers.

Install

npm i data-context@^2

Quick Start (Node)

const DC = require('data-context');
const { createDataContext, parse, stringify } = DC;

const ctx = parse('{ "count": 0 }', createDataContext);
ctx.on('count', e => { if (e.newValue > 10) return false; return true; });
ctx.on('-change', () => console.log(ctx.stringifyChanges(null, 2, true, true)));
ctx.count++;

Quick Start (ESM)

import DC from 'data-context/wrapper.mjs';
const { parse, createDataContext } = DC;
const ctx = parse('{"ok":true}', createDataContext);

Changelog

  • See CHANGELOG.md for full details.