Code Monkey home page Code Monkey logo

difflib.js's People

Contributors

qiao 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar

difflib.js's Issues

Please rewrite this on ES6 and remove require of assert in the production build

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.

contextDiff test failure

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"));

Jest errors out when importing this package

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.

Support for case sensitivity option

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.

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.