Function diffStr

  • Renders the differences between the actual and expected strings. Partially inspired from https://github.com/kpdecker/jsdiff.

    Parameters

    • A: string

      Actual string

    • B: string

      Expected string

    Returns DiffResult<string>[]

    Array of diff results.

    import { diffStr } from "@std/internal/diff-str";
    import { assertEquals } from "@std/assert";

    assertEquals(diffStr("Hello!", "Hello"), [
    {
    type: "removed",
    value: "Hello!\n",
    details: [
    { type: "common", value: "Hello" },
    { type: "removed", value: "!" },
    { type: "common", value: "\n" }
    ]
    },
    {
    type: "added",
    value: "Hello\n",
    details: [
    { type: "common", value: "Hello" },
    { type: "common", value: "\n" }
    ]
    }
    ]);