Giter Site home page Giter Site logo

antfu / diff-match-patch-es Goto Github PK

View Code? Open in Web Editor NEW
152.0 3.0 1.0 129 KB

ESM and TypeScript rewrite of Google's diff-match-patch for JavaScript

License: Apache License 2.0

TypeScript 99.93% JavaScript 0.07%
diff esm javascript typescript dff-match-patch

diff-match-patch-es's Introduction

diff-match-patch-es

npm version npm downloads bundle JSDocs License

ESM and TypeScript rewrite of Google's diff-match-patch (for JavaScript).

Features

  • Rewritten in ESM and TypeScript, ships with type declarations
  • Published as dual ESM/CJS formats
  • Refactor all to pure functions, fully tree-shakable

Migration

Migration from diff-match-patch npm package

  • Default export and the class constructor has been removed
  • Function name has been unified to camelCase
  • Previous options like Diff_Timeout and Diff_EditCost are now passed as an options object in the arguments if needed
// before
import DiffMatchPatch from 'diff-match-patch'

const dmp = new DiffMatchPatch()
dmp.Diff_Timeout = 1
const result = dmp.diff_main('hello', 'world')
// after
import { diff } from 'diff-match-patch-es'

const result = diff('hello', 'world', { diffTimeout: 1 })

Why?

Well, the code source repo from Google hasn't been updated for 5 years, and the npm package diff-match-patch hasn't been published for 4 years. And the code is not ESM nor tree-shakable. While this library is a composition of diff patch and match functions, sometimes you don't need all of them but since all functions were bound to a single class, all the code has to be included in the bundle. It's probably not a big deal as this whole library is still relatively small, but it's a bit annoying to me when you know something wasn't optimal. So I took an afternoon porting and rewriting the library to ESM and TypeScript. Helpfully it will lead to better maintainability and help the community to move forward with the modern JavaScript ecosystem.

Sponsors

License

Apache-2.0 License

diff-match-patch-es's People

Contributors

antfu avatar anubra266 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

anubra266

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.