Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json-diff-kit

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-diff-kit - npm Package Compare versions

Comparing version 1.0.26 to 1.0.27

typings/cli/index.d.ts

16

package.json
{
"name": "json-diff-kit",
"version": "1.0.26",
"version": "1.0.27",
"description": "A better JSON differ & viewer.",

@@ -17,11 +17,9 @@ "main": "dist/cjs/index.js",

"import": "./dist/index.js",
"require": "./dist/cjs/index.js"
"require": "./dist/cjs/index.js",
"types": "./typings/index.d.ts"
},
"./differ": {
"import": "./dist/differ.js",
"require": "./dist/cjs/differ.js"
},
"./viewer": {
"import": "./dist/viewer.js",
"require": "./dist/cjs/viewer.js"
"./*": {
"import": "./dist/*",
"require": "./dist/cjs/*",
"types": "./typings/index.d.ts"
}

@@ -28,0 +26,0 @@ },

@@ -1,436 +0,6 @@

declare module "utils/clean-fields" {
const cleanFields: (obj: unknown) => any;
export default cleanFields;
}
declare module "utils/concat" {
/**
* If we use `a.push(...b)`, it will result in `Maximum call stack size exceeded` error.
* The reason is unclear, it may be a bug of V8, so we should implement a push method by ourselves.
*/
const concat: <T, U>(a: T[], b: U[], prependEach?: boolean) => (T | U)[];
export default concat;
}
declare module "utils/detect-circular" {
const detectCircular: (value: any, map?: Map<any, boolean>) => boolean;
export default detectCircular;
}
declare module "utils/stringify" {
import { UndefinedBehavior } from "differ";
const stringify: (obj: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined, depth?: number, undefinedBehavior?: UndefinedBehavior | undefined) => string;
export default stringify;
}
declare module "utils/format-value" {
import { UndefinedBehavior } from "differ";
const formatValue: (value: any, depth?: number, pretty?: boolean, undefinedBehavior?: UndefinedBehavior) => string;
export default formatValue;
}
declare module "utils/cmp" {
interface CmpOptions {
ignoreCase?: boolean;
keyOrdersMap?: Map<string, number>;
}
/**
* The compare function to correct the order for "array" or "object":
* - The order for 2 values with different types are: boolean, number, string, null, array, object.
* - The order for 2 values with the same type is according to the type:
* - For boolean, number, string: use the `<` sign.
* - For array and object: preserve the original order (or do we have a better idea?)
*/
const cmp: (a: any, b: any, options: CmpOptions) => number;
export default cmp;
}
declare module "utils/get-type" {
const getType: (value: any) => "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "null" | "array";
export default getType;
}
declare module "utils/pretty-append-lines" {
import type { DifferOptions, DiffResult } from "differ";
const prettyAppendLines: (linesLeft: DiffResult[], linesRight: DiffResult[], keyLeft: string, keyRight: string, valueLeft: any, valueRight: any, level: number, options: DifferOptions) => void;
export default prettyAppendLines;
}
declare module "utils/sort-keys" {
import type { DifferOptions } from "differ";
const sortKeys: (arr: string[], options: DifferOptions) => string[];
export default sortKeys;
}
declare module "utils/diff-object" {
import type { DifferOptions, DiffResult, ArrayDiffFunc } from "differ";
const diffObject: (lhs: Record<string, any>, rhs: Record<string, any>, level: number | undefined, options: DifferOptions, arrayDiffFunc: ArrayDiffFunc) => [DiffResult[], DiffResult[]];
export default diffObject;
}
declare module "utils/is-equal" {
import type { DifferOptions } from "differ";
const isEqual: (a: any, b: any, options: DifferOptions) => boolean;
export default isEqual;
}
declare module "utils/shallow-similarity" {
const shallowSimilarity: (left: any, right: any) => number;
export default shallowSimilarity;
}
declare module "utils/diff-array-lcs" {
import type { DifferOptions, DiffResult } from "differ";
const diffArrayLCS: (arrLeft: any[], arrRight: any[], keyLeft: string, keyRight: string, level: number, options: DifferOptions, linesLeft?: DiffResult[], linesRight?: DiffResult[]) => [DiffResult[], DiffResult[]];
export default diffArrayLCS;
}
declare module "utils/diff-array-normal" {
import type { DiffResult, DifferOptions } from "differ";
const diffArrayNormal: (arrLeft: any[], arrRight: any[], keyLeft: string, keyRight: string, level: number, options: DifferOptions, linesLeft?: DiffResult[], linesRight?: DiffResult[]) => [DiffResult[], DiffResult[]];
export default diffArrayNormal;
}
declare module "utils/sort-inner-arrays" {
import type { DifferOptions } from "differ";
const sortInnerArrays: (source: any, options?: DifferOptions | undefined) => any;
export default sortInnerArrays;
}
declare module "differ" {
export interface DifferOptions {
/**
* Whether to detect circular reference in source objects before diff starts. Default
* is `true`. If you are confident for your data (e.g. from `JSON.parse` or an API
* response), you can set it to `false` to improve performance, but the algorithm may
* not stop if circular reference does show up.
*/
detectCircular?: boolean;
/**
* Max depth, default `Infinity` means no depth limit.
*/
maxDepth?: number;
/**
* Support recognizing modifications, default `true` means the differ will output the
* `* modified` sign apart from the basic `+ add` and `- remove` sign. If you prefer
* Git output, please set it to `false`.
*/
showModifications?: boolean;
/**
* The way to diff arrays, default is `"normal"`.
*
* For example, if we got 2 arrays: `a =[1, 2, 3]` and `b = [2, 3, 1, 4, 0]`, and the
* `showModifications` is set to `true`.
*
* When using `normal`, the differ will compare the items in the same index one by one.
* The time complexity is faster (`O(LEN)`). The output will be:
*
* ```diff
* a b
* * 1 2
* * 2 3
* * 3 1
* + 4
* + 0
* ```
*
* When using `lcs`, the differ will perform the LCS (Longest Common Subsequence) algorithm,
* assuming the items in the subsequence are unchanged. The time complexity for LCS is
* slower (`O(LEN^2)`). The output will be:
*
* ```diff
* a b
* - 1
* 2 2
* 3 3
* + 1
* + 4
* + 0
* ```
*
* When using `unorder-normal`, the differ will first sort 2 arrays, then act like `normal`.
* The output will be:
*
* ```diff
* a b
* * 1 0
* * 2 1
* * 3 2
* * 4 3
* + 4
* ```
*
* When using `unorder-lcs`, the differ will first sort 2 arrays, then act like `lcs`.
* The output will be:
*
* ```diff
* a b
* + 0
* 1 1
* 2 2
* 3 3
* + 4
* ```
*/
arrayDiffMethod?: 'normal' | 'lcs' | 'unorder-normal' | 'unorder-lcs';
/**
* Whether to ignore the case when comparing strings, default `false`.
*/
ignoreCase?: boolean;
/**
* Whether to ignore the case when comparing keys, default `false`.
*
* Notice: if there are keys with different cases in the same object, the algorithm may fail
* since it's not able to tell which key is the correct one.
*/
ignoreCaseForKey?: boolean;
/**
* Whether to use recursive equal to compare objects, default `false`.
*
* This will only applied to objects, not arrays.
*
* Two objects are considered equal if they have the same properties and values, for example:
*
* ```js
* const x = { 'a': 1, 'b': 2 };
* const y = { 'b': 2, 'a': 1 };
* ```
*
* The `x` and `y` here will be considered equal.
*
* This comparation process is slow in huge objects.
*/
recursiveEqual?: boolean;
/**
* If the value is set, differ will make sure the key order of results is the same as inputs
* ("before" or "after"). Otherwise, differ will sort the keys of results.
*/
preserveKeyOrder?: 'before' | 'after';
/**
* The behavior when encountering values that are not part of the JSON spec, e.g. `undefined`, `NaN`, `Infinity`, `123n`, `() => alert(1)`, `Symbol.iterator`.
*
* - `UndefinedBehavior.throw`: throw an error
* - `UndefinedBehavior.ignore`: ignore the key-value pair
* - `UndefinedBehavior.stringify`: try to stringify the value
*
* Default is `UndefinedBehavior.stringify`.
*/
undefinedBehavior?: UndefinedBehavior;
}
export enum UndefinedBehavior {
stringify = "stringify",
ignore = "ignore",
throw = "throw"
}
export interface DiffResult {
level: number;
type: 'modify' | 'add' | 'remove' | 'equal';
text: string;
comma?: boolean;
lineNumber?: number;
}
export type ArrayDiffFunc = (arrLeft: any[], arrRight: any[], keyLeft: string, keyRight: string, level: number, options: DifferOptions, ...args: any[]) => [DiffResult[], DiffResult[]];
class Differ {
private options;
private arrayDiffFunc;
constructor({ detectCircular, maxDepth, showModifications, arrayDiffMethod, ignoreCase, ignoreCaseForKey, recursiveEqual, preserveKeyOrder, undefinedBehavior, }?: DifferOptions);
private detectCircular;
private sortResultLines;
private calculateLineNumbers;
private calculateCommas;
diff(sourceLeft: any, sourceRight: any): readonly [DiffResult[], DiffResult[]];
}
export default Differ;
}
declare module "differ.spec" { }
declare module "utils/get-segments" {
import type { DiffResult } from "differ";
import type { HideUnchangedLinesOptions } from "viewer";
export interface SegmentItem {
start: number;
end: number;
isEqual: boolean;
}
export interface HiddenUnchangedLinesInfo extends SegmentItem {
hasLinesBefore: boolean;
hasLinesAfter: boolean;
}
const getSegments: (l: DiffResult[], r: DiffResult[], options: HideUnchangedLinesOptions, jsonsAreEqual: boolean) => (SegmentItem | HiddenUnchangedLinesInfo)[];
export default getSegments;
}
declare module "utils/get-inline-diff" {
export interface InlineDiffOptions {
mode?: 'char' | 'word';
wordSeparator?: string;
}
export interface InlineDiffResult {
type?: 'add' | 'remove';
start: number;
end: number;
}
const getInlineDiff: (l: string, r: string, options: InlineDiffOptions) => [
InlineDiffResult[],
InlineDiffResult[]
];
export default getInlineDiff;
}
declare module "utils/get-inline-syntax-highlight" {
export interface InlineHighlightResult {
start: number;
end: number;
token: 'plain' | 'number' | 'boolean' | 'null' | 'key' | 'punctuation' | 'string' | 'invalid';
}
const syntaxHighlightLine: (enabled: boolean, text: string, offset: number) => InlineHighlightResult[];
export default syntaxHighlightLine;
}
declare module "utils/segment-util" {
import type { InlineDiffResult } from "utils/get-inline-diff";
import type { InlineHighlightResult } from "utils/get-inline-syntax-highlight";
import type { SegmentItem, HiddenUnchangedLinesInfo } from "utils/get-segments";
export const isExpandLine: (segment: SegmentItem | HiddenUnchangedLinesInfo) => segment is HiddenUnchangedLinesInfo;
export const getSegmentHeight: (segment: SegmentItem | HiddenUnchangedLinesInfo, itemHeight: number, expandLineHeight: number) => number;
export type InlineRenderInfo = InlineDiffResult & InlineHighlightResult;
/**
* Merge two segments array into one, divide the segment if necessary.
*/
export const mergeSegments: (tokens: InlineHighlightResult[], diffs: InlineDiffResult[]) => InlineRenderInfo[];
}
declare module "utils/calculate-placeholder-height" {
import type { SegmentItem, HiddenUnchangedLinesInfo } from "utils/get-segments";
const calculatePlaceholderHeight: (segments: Array<SegmentItem | HiddenUnchangedLinesInfo>, accTop: number[], startSegment: number, startLine: number, endSegment: number, endLine: number, itemHeight: number, expandLineHeight: number, totalHeight: number) => number[];
export default calculatePlaceholderHeight;
}
declare module "utils/find-visible-lines" {
import type { SegmentItem, HiddenUnchangedLinesInfo } from "utils/get-segments";
const findVisibleLines: (segments: Array<SegmentItem | HiddenUnchangedLinesInfo>, accTop: number[], viewportTop: number, viewportBottom: number, itemHeight: number, expandLineHeight: number) => number[];
export default findVisibleLines;
}
declare module "viewer" {
import * as React from 'react';
import type { DiffResult } from "differ";
import type { InlineDiffOptions } from "utils/get-inline-diff";
interface ExpandLineRendererOptions {
/**
* If this is `true`, you can show a "⬆️ Show xx lines" button
*/
hasLinesBefore: boolean;
/**
* If this is `true`, you can show a "⬇️ Show xx lines" button
*/
hasLinesAfter: boolean;
/**
* Call this function to expand `lines` lines before,
* if there are not enough lines before, it will expand all lines before.
*/
onExpandBefore: (lines: number) => void;
/**
* Call this function to expand `lines` lines after,
* if there are not enough lines after, it will expand all lines after.
*/
onExpandAfter: (lines: number) => void;
/**
* Call this function to expand all lines in this continuous part.
*/
onExpandAll: () => void;
}
export type HideUnchangedLinesOptions = boolean | {
/**
* If there are continuous unchanged lines exceeding the limit, they should be hidden,
* default is `8`.
*/
threshold?: number;
/**
* We can keep displaying some lines around the "expand" line for a better context,
* default is `3`.
*/
margin?: number;
/**
* Controls how many lines will be displayed when clicking the "Show xx lines before"
* or "Show xx lines after" button in the "expand" line, default is `20`.
*/
expandMoreLinesLimit?: number;
/**
* The custom renderer of the "expand" line,
* default renderer will produce the following buttons in this line:
*
* ```text
* [⬆️ Show 20 lines] [↕️ Show all unchanged lines] [⬇️ Show 20 lines]
* ```
*/
expandLineRenderer?: (options?: ExpandLineRendererOptions) => JSX.Element;
};
export interface ViewerProps {
/** The diff result `[before, after]`. */
diff: readonly [DiffResult[], DiffResult[]];
/** Configure indent, default `2` means 2 spaces. */
indent?: number | 'tab';
/** Background colour for 3 types of lines. */
bgColour?: {
add?: string;
remove?: string;
modify?: string;
};
/** Display line numbers, default is `false`. */
lineNumbers?: boolean;
/** Whether to show the inline diff highlight, default is `false`. */
highlightInlineDiff?: boolean;
/** Controls the inline diff behaviour, the `highlightInlineDiff` must be enabled. */
inlineDiffOptions?: InlineDiffOptions;
/**
* Hide continuous unchanged lines and display an "expand" instead,
* default `false` means it won't hide unchanged lines.
*/
hideUnchangedLines?: HideUnchangedLinesOptions;
/**
* Use virtual list to speed up rendering, default is `false`.
*/
virtual?: boolean | {
/** @default 'body' */
scrollContainer?: string;
/** @default 18 */
itemHeight?: number;
/** @default 26 */
expandLineHeight?: number;
};
/**
* Enable the syntax highlight feature, default is `false`.
*/
syntaxHighlight?: false | {
/**
* The syntax highlighting theme; it will add a className to `table`.
*
* NOTICE:
* - You need to import the corresponding CSS file manually.
* @default 'monokai'
*/
theme?: string;
};
/**
* Configure the texts in the viewer, you can use it to implement i18n.
*/
texts?: {
/** @default 'No change detected' */
noChangeDetected?: string;
};
/** Extra class names */
className?: string;
/** Extra styles */
style?: React.CSSProperties;
}
const Viewer: React.FC<ViewerProps>;
export default Viewer;
}
declare module "index" {
import Differ from "differ";
import Viewer from "viewer";
export type { InlineDiffOptions, InlineDiffResult, } from "utils/get-inline-diff";
export type { ArrayDiffFunc, DifferOptions, DiffResult, } from "differ";
export type { ViewerProps, } from "viewer";
export { Differ, Viewer };
}
declare module "cli/show-in-terminal" {
import type { DiffResult } from "differ";
const showInTerminal: ([leftResult, rightResult]: readonly [DiffResult[], DiffResult[]]) => Promise<void>;
export default showInTerminal;
}
declare module "cli/write-to-file" {
import type { DiffResult } from "differ";
/**
* It's not able to write side-by-side diff to a file,
* so we just use the Git-style output.
*/
const writeToFile: (path: string, content: readonly [DiffResult[], DiffResult[]]) => void;
export default writeToFile;
}
declare module "cli/index" { }
declare module "utils/cmp.spec" { }
declare module "utils/concat.spec" { }
declare module "utils/format-value.spec" { }
declare module "utils/get-type.spec" { }
declare module "utils/sort-inner-arrays.spec" { }
declare module "utils/stringify.spec" { }
import Differ from './differ';
import Viewer from './viewer';
export type { InlineDiffOptions, InlineDiffResult, } from './utils/get-inline-diff';
export type { ArrayDiffFunc, DifferOptions, DiffResult, } from './differ';
export type { ViewerProps, } from './viewer';
export { Differ, Viewer };

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc