Giter Site home page Giter Site logo

json-delta's People

Contributors

corps avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

wms clipchamp

json-delta's Issues

TS2322: Type 'null' is not assignable to type 'void | Diff'

the diff function return type is Diff | void however it returns null in line 152:

json-delta/index.ts

Lines 144 to 154 in 41275a6

export function diff(
a: AnyJson,
b: AnyJson,
tolerance = Infinity
): Diff | void {
let result: Diff = [];
if (gatherDiff(a, b, tolerance, [], result) || result.length > tolerance)
return [[[], b]];
if (result.length === 0) return null;
return result;
}

I can prepare a PR if it helps

TS2322: Type '[number, number] | null' is not assignable to type 'void | [number, number]'

the shortestEdit function return type is [number, number] | void however it returns null in line 335:

json-delta/index.ts

Lines 300 to 336 in 41275a6

let shortestEdit: [number, number] | void = (function() {
for (var d = 0; d <= tolerance; ++d) {
for (var k = -d; k <= d; k += 2) {
let aIdx: number;
let takeB = aOfDiagonal[k + 1 + tolerance];
let takeA = aOfDiagonal[k - 1 + tolerance];
if (k === -d || (k !== d && takeA < takeB)) {
aIdx = takeB;
} else {
aIdx = takeA + 1;
}
let bIdx = aIdx - k;
while (
aIdx < aLen &&
bIdx < bLen &&
deepEqual(a[aIdx], b[bIdx])
) {
aIdx++;
bIdx++;
}
aOfDiagonal[k + tolerance] = aIdx;
if (aIdx >= aLen && bIdx >= bLen) {
aOfDiagonalForEditSize[d] = aOfDiagonal.slice();
return [d, k] as [number, number];
}
}
aOfDiagonalForEditSize[d] = aOfDiagonal.slice();
}
return null;
})();

I can prepare a PR if it helps

ReadonlyArray Type not supported

applyDiff creates a shallowCopy so it does not modify the input.
However it does not accept read only data structures.

Would it be possible to change that e.g.:

interface JsonMap {
  [key: string]: Readonly<AnyJson>;
}
interface JsonArray extends ReadonlyArray<AnyJson> {}

It would also be nice to return the input type:

export function applyDiff<T extends AnyJson>(o: T, d: Diff | void): T {

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.