# @types/jiff

> TypeScript definitions for jiff

Latest version **0.7.7** (published 2025-02-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install @types/jiff
pnpm add @types/jiff
yarn add @types/jiff
bun add @types/jiff
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; no vulnerabilities; high maintenance score; popular repo; extremely popular.

Warnings: low downloads; no esm support; pre 1.0.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 0.7.7 |
| Published | 2025-02-25 |
| First published | 2023-06-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 51429 |
| Maintainers | types |

## Links

- npm: https://www.npmjs.com/package/@types/jiff
- Repository: https://github.com/DefinitelyTyped/DefinitelyTyped
- Homepage: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/jiff
- npm.io page: https://npm.io/package/@types/jiff

## Recent versions

- 0.7.7 (latest) — 2025-02-25
- 0.7.6 (ts4.8) — 2024-08-22
- 0.7.5 (ts4.6) — 2023-11-21
- 0.7.1 (ts4.3) — 2023-09-09
- 0.7.4 — 2023-11-07
- 0.7.3 — 2023-10-18
- 0.7.2 — 2023-09-15
- 0.7.0 — 2023-06-28

## README

# Installation
> `npm install --save @types/jiff`

# Summary
This package contains type definitions for jiff (https://github.com/cujojs/jiff#readme).

# Details
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/jiff.
## [index.d.ts](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/jiff/index.d.ts)
````ts
declare namespace jiff {
    type JSONArray = JSONValue[];
    type JSONObject = object;
    type JSONValue = string | number | boolean | null | JSONObject | JSONArray;

    type JSONPatch = Array<{
        op: "add" | "remove" | "replace" | "move" | "copy" | "test";
        path: string;
        value?: any;
        from?: string;
        context?: any;
    }>;

    type HashFunction = (value: any) => string | number;

    interface DiffOptions {
        /** used to hash array items in order to recognize identical objects, defaults to JSON.stringify */
        hash?: HashFunction;
        /** used to generate patch context. If not provided, context will not be generated */
        makeContext?: (index: number, array: any[]) => any;
        invertible?: boolean;
    }

    interface PatchOptions {
        /** function used adjust array indexes for smarty/fuzzy patching, for patches containing context */
        findContext?: (index: number, array: any[], context: any) => any;
    }
}

declare var jiff: {
    InvalidPatchOperationError: new(message: string) => Error & { name: "InvalidPatchOperationError" };
    TestFailedError: new(message: string) => Error & { name: "TestFailedError" };
    PatchNotInvertibleError: new(message: string) => Error & { name: "PatchNotInvertibleError" };
    /**
     * Create a deep copy of x which must be a legal JSON object/array/value
     * @param x object/array/value to clone
     * @returns clone of x
     */
    clone<T extends jiff.JSONValue>(x: T): T;
    /**
     * Compute a JSON Patch representing the differences between a and b.
     * @param a
     * @param b
     * @param options if a function, see options.hash
     * @returns JSON Patch such that patch(diff(a, b), a) ~ b
     */
    diff(a: jiff.JSONValue, b: jiff.JSONValue, options?: jiff.HashFunction | jiff.DiffOptions): jiff.JSONPatch;
    inverse(patch: jiff.JSONPatch): jiff.JSONPatch;
    /**
     * Apply the supplied JSON Patch to x
     * @param changes JSON Patch
     * @param x object/array/value to patch
     * @param options
     *
     * @returns patched version of x. If x is
     *  an array or object, it will be mutated and returned. Otherwise, if
     *  x is a value, the new value will be returned.
     */
    patch(changes: jiff.JSONPatch, x: jiff.JSONValue, options?: jiff.PatchOptions): jiff.JSONValue;
    patchInPlace(patch: jiff.JSONPatch, a: jiff.JSONValue, options?: jiff.PatchOptions): jiff.JSONValue;
};

export = jiff;

````

### Additional Details
 * Last updated: Tue, 25 Feb 2025 00:03:48 GMT
 * Dependencies: none

# Credits
These definitions were written by [Daniel Kneip](https://github.com/daniel-kneip).

---
_Source: https://npm.io/package/@types/jiff · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
