jhchen / fast-diff Goto Github PK
View Code? Open in Web Editor NEWA fast Javascript string diff
License: Apache License 2.0
A fast Javascript string diff
License: Apache License 2.0
In 1.1.2 it works correctly:
node -e 'console.log(require(".")("aaaaa", "aaaa", 1))'
[ [ 0, 'a' ], [ -1, 'a' ], [ 0, 'aaa' ] ]
In 1.2.0 it does not work correctly:
node -e 'console.log(require(".")("aaaaa", "aaaa", 1))'
[ [ -1, 'a' ], [ 0, 'aaaa' ] ]
There are likely more cases, where the editing position does not have the desired effect.
What license(s) is this piece of code released under?
Hello, do you think you can add a create unified diff patch function like this ?
https://github.com/kpdecker/jsdiff/blob/master/src/patch/create.js
thanks
This library is awesome, but one thing it suffers from is huge memory consumption on large strings as the resulting array can be pretty gigantic. I would love a generator version that spits out small chunks instead of a giant result array.
I attempted this by myself but unicode and "cleanup" turned out to be out of my understanding.
See master...LiraNuna:fast-diff-iterator:master for my attempt.
Hello. Thanks for project, very nice work, but can you add parameter to diff function for case insensitive comparison?
I'll try and see
also substring -> slice
Hi guys,
would you mind to add LICENSE.md
file inside the repo root? Apache 2.0 requires to distribute license text along the source code and now there is none in repo and npm package, so it means that this code cannot be legally used by anyone.
So if you have a few minutes to add this https://www.apache.org/licenses/LICENSE-2.0 to the repository and release new patch version with the license, it would be really great.
Thank you
Hi @jhchen,
I've been happily enjoying your fast-diff library in a custom editor that I'm building.
However, I came across an issue when trying to support code points outside of the BMP. In its current implementation fast-diff checks each JS "character" or "code unit". Being that ES5 JS iterates over code units rather than code points this creates issues with symbols outside the BMP.
A diff of two different string symbols such as "🐶" and "🐯" results in the first code unit matching and the second code unit non-matching. Thereby splitting up the surrogate pairs and potentially causing unwanted side effects.
Fast-Diff Produces:
[ [ 0, '�' ], [ -1, '�' ], [ 1, '�' ] ]
Rather than:
[ [ -1, '🐶' ], [ 1, '🐯' ] ]
I've modified your library to handle surrogate pairs as single "symbols". You can find my changes at fast-diff-astral. If you would like I can submit a pull request.
The method it uses is to break up the string into an array of symbols. Thereby allowing iteration over each symbol and full comparison of each surrogate pair as a single code point.
This may cause some extra overhead in terms of processing speed, which, along with the amount of changes, is why I broke it out into a separate library. That said, it still seems quick but I haven't tested the speed differences.
I've chosen to use a custom method to find and group surrogate pairs into an array rather than using the new ES6 String iterator methods. I did so only to avoid introducing a transpiler to the build process.
Hope you get a chance to look over it. Let me know if you'd like a pull request.
Cheers!
Refs: Great article by Mathias Bynens on JS unicode support, if you haven't already read it.
Hi,
Could you please add a LICENSE file with your license text?
We need a plain text license file for our FOSS report.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.