Typer-Diff, a npm package for comparing two typed strings
Typer Diff Project
Typer Diff allows you to compare two strings and receive a detailed report on the differences between them. The library provides a simple API that makes it easy to use in your application.
Key Features
- Easy to use: Typer Diff’s API is designed to be simple and intuitive, making it easy to integrate into your project.
- Fast and lightweight: With no dependencies, Typer Diff is a fast and efficient library that won’t slow down your application.
- Detailed reporting: Get a detailed report on the differences between two strings, including correct, extra, missing, wrong, untouched, and spacer items.
Usage
To use Typer Diff in your project, you can install it using npm:
Then, you can import the library and use its API to compare two strings. For example:
Types
Typer Diff provides several types that you can use in your project:
-
DiffItem
: An object representing a single difference between the two input strings. +value
: The value of the item (a string). +type
: The type of the item (one of “correct”, “extra”, “missing”, “wrong”, “untouched”, or “spacer”). -
DiffResult
: An object representing the result of comparing two strings using Typer Diff. +diff
: An array ofDiffItem
s representing the differences between the two input strings. +end
: A boolean indicating whether the end of one of the input strings has been reached.
Design Decisions
I chose to use TypeScript to take advantage of its type safety features and improve code quality. Additionally, I implemented auto-versioning using Changeset, which allows me to keep track of changes and releases efficiently. To automate the build, testing, and deployment process, I set up GitHub CI/CD pipelines. Finally, I used Turborepo to speed up development and separate packages from documentation.
Demo
Check out a live demo of Typer Diff in action at typer-diff.vercel.app.