Skip to content

A function to deeply compare two strings showing symbol-by-symbols diffs. What was not changed, moved or deleted (added).

License

Notifications You must be signed in to change notification settings

abi83/deep-string-comparison

Repository files navigation

deep-string-comparison allows you to compare two strings deeply, calculate differences and highlight changes in user-friendly manner, like your git tool does.

Algorithm complexity O(n^2), where n is a string length

import { comparator } from "deep-string-comparison";
const { aDiff, bDiff } = comparator(
  'my test string HAS data',
  'my COOL string test data'
)

Output:

[
  { "from":  0, "to":  2, "type": "not_changed", "value": "my "},
  { "from":  3, "to":  6, "type": "moved",     "value": "test" },
  { "from":  7, "to": 14, "type": "not_changed", "value": " string " },
  { "from": 15, "to": 17, "type": "deleted",   "value": "HAS" },
  { "from": 18, "to": 22, "type": "not_changed", "value": " data" }
]

what is in plans:

  • make a package compatible with 'commonJs' modules
  • comparison of multi-line strings
  • improve output for short substrings
  • improve performance

your feedback is strongly appreciated

abi83, Dec. 2022

About

A function to deeply compare two strings showing symbol-by-symbols diffs. What was not changed, moved or deleted (added).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published