qiao / difflib.js Goto Github PK
View Code? Open in Web Editor NEWText diff library in JavaScript, ported from Python's difflib module.
Home Page: http://qiao.github.com/difflib.js
Text diff library in JavaScript, ported from Python's difflib module.
Home Page: http://qiao.github.com/difflib.js
I do realise that this library was created long ago when js didn't had classes but now it is different.
The require of assert is really another specific issue for using the library in electron.
It is recommended to have nodeIntegration turned off, this means that any require will not work, but if it is import, that'ss another story and might just work.
And last time I used assert was for tests or otherthings done only in dev build, not in production.
Insertion of line at index 19 is totally missed by the comparison:
#!/usr/bin/env node
const difflib = require("difflib");
const origLines =
["zero", "one", "two", "three", "four", "five", "six",
"seven", "eight", "nine", "ten", "eleven",
"twelve", "thirteen", "fourteen", "fifteen",
"sixteen", "seventeen", "eighteen", "nineteen"];
const newLines = origLines.slice();
newLines.splice(19, 0, "newteen");
newLines[10] = "changed";
newLines.splice(3, 1);
console.log("Orig: " + origLines);
console.log("New: " + newLines);
console.log(difflib.contextDiff(origLines, newLines,
{ fromfile: "LHS", tofile: "RHS", n: 2, lineterm: "" }
).join("\n"));
The option n
maybe not work, it's just 3
Is it possible to distribute this through bower?
Our app was hitting the following error when we added tests that relied on a package that relied on this package:
TypeError: Cannot assign to read only property 'name' of function 'function SequenceMatcher(isjunk, a, b, autojunk) {
at ../../node_modules/difflib/lib/difflib.js:78:25
at call (../../node_modules/difflib/lib/difflib.js:660:3)
at Object.<anonymous> (../../node_modules/difflib/lib/difflib.js:1486:4)
at Object.<anonymous> (../../node_modules/difflib/index.js:1:18)
with the issue being these two lines:
Per https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name, the issue is that the name
property for a function is not writable, and so doing assignment isn't allowed, and will do nothing in non-strict contexts, or error in strict contexts. For an example of the former context, see this REPL output:
> a = (function() { console.log('foo') });
[Function: a]
> a.name
'a'
> a.name = 'b'
'b'
> a.name
'a'
If assigning the name is necessary, it needs to be done by doing Object.defineProperty
instead, which can bypass the writable
attribute:
> a = (function() { console.log('foo') });
[Function: a]
> a.name
'a'
> Object.defineProperty(a, 'name', { value: 'b' })
[Function: b]
> a
[Function: b]
> a.name
'b'
To workaround this, for now we're mocking out the dependency with a stub as we don't depend on the output, but it'd be nice to not have to.
Line 1192 in e11553b
It would be cool to have a way defining ignore the letter case changes. Like:
difflib.ndiff(before, after, { caseSensitive: false })
I am not sure if I can work this around with charjunk
and linejunk
stuff.
example
findLongestMatch(1234, '1234') will return [0, 0, 1].
I guess the main reason is some object keys do not contain type info. For example in the SequenceMatcher.prototype._chainB function when generate b2j, elt should add the result of typeof elt. Like this elt = typeof elt + elt
.
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.