0.3.1 • Published 8 months ago

@arcanejs/diff v0.3.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

@arcanejs/diff

NPM Version

This package provides an easy way to:

  • Create diffs by comparing objects
  • Update objects by applying diffs

This library is written in TypeScript, and produces diffs that are type-safe, and can only be applied to objects that match the type of the objects being compared.

This package is part of the arcanejs project, and is used to maintain a copy of a JSON tree in downstream clients in real-time via websockets.

Usage

import { diffJson, Diff } from '@arcanejs/diff/diff';
import { patchJson } from '@arcanejs/diff/patch';

type E = {
  foo: string;
  bar?: number[];
};

const a: E = { foo: 'bar' };
const b: E = { foo: 'baz', bar: [1] };

const diffA: Diff<E> = diffJson(a, b);

const resultA = patchJson(a, diffA);

console.log(resultB); // { foo: 'baz', bar: [1] }

const c = { baz: 'foo' };

const resultB = patchJson(c, diffA); // TypeScript Type Error: Property 'baz' is missing in type '{ foo: string; bar?: number[] | undefined; }' but required in type '{ baz: string; }'
0.3.1

8 months ago

0.3.0

10 months ago

0.2.0

12 months ago

0.1.4

12 months ago

0.1.3

12 months ago

0.1.2

12 months ago

0.1.1

12 months ago

0.1.0

12 months ago