New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fast-myers-diff

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-myers-diff - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

2

dist/index.js

@@ -1,1 +0,1 @@

"use strict";function*diff_rec(e,t,f,l,o,i){const n=[];let r=2*Math.min(f,i)+2,c=new Uint32Array(r),s=new Uint32Array(r),[a,y,d,h,u]=[0,0,0,0,0];for(;;){e:{if(f>0&&i>0){const p=f+i,g=f-i,x=(p>>>1)+(1&p);t:for(let n=0;n<=x;n++){const x=2*Math.max(0,n-i)-n,b=n-2*Math.max(0,n-f);for(let P=x;P<=b;P+=2){const x=c[(r+P+1)%r],b=c[(r+P-1)%r];for(h=P===-n||P!==n&&b<x?x:b+1,u=h-P,[y,d]=[h,u];h<f&&u<i&&e[t+h]===l[o+u];)h++,u++;c[(r+P)%r]=h;const M=g-P;if(1==(1&p)&&M>-n&&M<n&&h+s[(r+M)%r]>=f){a=2*n-1;break t}}[c,s]=[s,c];for(let P=x;P<=b;P+=2){const x=c[(r+P+1)%r],b=c[(r+P-1)%r];y=P===-n||P!==n&&b<x?x:b+1,d=y-P,[h,u]=[f-y,i-d];const M=t+f-1,_=o+i-1;for(;y<f&&d<i&&e[M-y]===l[_-d];)y++,d++;c[(r+P)%r]=y;const m=g-P;if(0==(1&p)&&m>=-n&&m<=n&&y+s[(r+m)%r]>=f){[a,y,d]=[2*n,f-y,i-d];break t}}[c,s]=[s,c]}if((a>1||y!==h&&d!==u)&&(n.push([t+h,f-h,o+u,i-u]),[f,i]=[y,d],f>0&&i>0))break e}if(i>f){const[e,l]=[t+f,o+f];yield[e,e,l,l+i]}else if(i<f){const[e,l]=[t+i,o+i];yield[e,e+f,l,l]}if(0===n.length)return;[t,f,o,i]=n.pop()}r=2*Math.min(f,i)+2,a=c[1]=s[1]=0}}function*diff(e,t){let f=e.length,l=t.length,o=0;for(;o<f&&o<l&&e[o]===t[o];)o++;if(o===f&&f===l)return;for(;f>o&&l>o&&e[--f]===t[--l];);const i=diff_rec(e,o,f+1-o,t,o,l+1-o);let n=i.next().value;for(const e of i){const[t,f,l,o]=e;t===f?l===n[3]?n[3]=o:n[2]===n[3]&&t>=n[0]&&t<=n[1]?(n[2]=l,n[3]=o):(yield n,n=e):t===n[1]?n[1]=f:(yield n,n=e)}yield n}function*lcs(e,t){const f=e.length,l=t.length;let o=0;for(;o<f&&o<l&&e[o]===t[o];)o++;if(o>0&&(yield[0,0,o]),o===f&&f===l)return;let[i,n]=[f,l];for(;i>o&&n>o&&e[--i]===t[--n];);const r=diff_rec(e,o,i+1-o,t,o,n+1-o);let[c,s,a,y]=r.next().value,d=o+y-a;o+=s-c;for(const e of r)[c,s,,y]=e,o!==c&&(e.length--,[e[0],e[1],e[2]]=[o,d,c-o],yield e),[o,d]=[s,y];o<f&&(yield[o,d,f-o])}function*calcPatch(e,t){if(ArrayBuffer.isView(t))for(const[f,l,o,i]of diff(e,t))yield[f,l,t.subarray(o,i)];else for(const[f,l,o,i]of diff(e,t))yield[f,l,t.slice(o,i)]}function*applyPatch(e,t){let f=0;if(ArrayBuffer.isView(e)){for(const[l,o,i]of t)f<l&&(yield e.subarray(f,l)),i.length>0&&(yield i),f=o;f<e.length&&(yield e.subarray(f))}else{for(const[l,o,i]of t)f<l&&(yield e.slice(f,l)),i.length>0&&(yield i),f=o;f<e.length&&(yield e.slice(f))}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.diff=diff,exports.lcs=lcs,exports.calcPatch=calcPatch,exports.applyPatch=applyPatch;
"use strict";function*diff_rec(t,e,n,o,f,r){const i=[];let c=2*Math.min(n,r)+2,l=new Uint32Array(c),s=new Uint32Array(c),[a,y,u,d,h]=[0,0,0,0,0];for(;;){t:{if(n>0&&r>0){const p=n+r,x=1&p,g=n-r,P=(p>>>1)+x;e:for(let i=0;i<=P;i++){const p=2*Math.max(0,i-r)-i,P=i-2*Math.max(0,i-n);for(let b=p;b<=P;b+=2){const p=b%c+c,[P,A]=[l[(p+1)%c],l[(p-1)%c]];for(d=b===-i||b<i&&A<P?P:A+1,h=d-b,[y,u]=[d,h];d<n&&h<r&&t[e+d]===o[f+h];)d++,h++;l[p%c]=d;const M=g-b;if(1===x&&M>-i&&M<i&&d+s[(c+M%c)%c]>=n){a=2*i-1;break e}}[l,s]=[s,l];for(let b=p;b<=P;b+=2){const p=b%c+c,[P,A]=[l[(p+1)%c],l[(p-1)%c]];y=b===-i||b<i&&A<P?P:A+1,u=y-b,[d,h]=[n-y,r-u];const M=e+n-1,_=f+r-1;for(;y<n&&u<r&&t[M-y]===o[_-u];)y++,u++;l[p%c]=y;const m=g-b;if(0===x&&m>=-i&&m<=i&&y+s[(c+m%c)%c]>=n){[a,y,u]=[2*i,n-y,r-u];break e}}[l,s]=[s,l]}if((a>1||y!==d&&u!==h)&&(i.push([e+d,n-d,f+h,r-h]),[n,r]=[y,u],n>0&&r>0))break t}if(r>n){const[t,o]=[e+n,f+n];yield[t,t,o,o+r]}else if(r<n){const[t,o]=[e+r,f+r];yield[t,t+n,o,o]}if(0===i.length)return;[e,n,f,r]=i.pop()}c=2*Math.min(n,r)+2,a=l[1]=s[1]=0}}function*diff(t,e){let[n,o,f]=[0,t.length,e.length];for(;n<o&&n<f&&t[n]===e[n];)n++;if(n===o&&o===f)return;for(;o>n&&f>n&&t[--o]===e[--f];);const r=diff_rec(t,n,o+1-n,e,n,f+1-n);let i=r.next().value;for(const t of r){const[e,n,o,f]=t;if(e===n){if(o===i[3]){i[3]=f;continue}if(i[2]===i[3]&&e>=i[0]&&e<=i[1]){[i[2],i[3]]=[o,f];continue}}else if(e===i[1]){i[1]=n;continue}yield i,i=t}yield i}function*lcs(t,e){let[n,o,f]=[0,t.length,e.length];for(;n<o&&n<f&&t[n]===e[n];)n++;if(n>0&&(yield[0,0,n]),n===o&&o===f)return;let[r,i]=[o,f];for(;r>n&&i>n&&t[--r]===e[--i];);const c=diff_rec(t,n,r+1-n,e,n,i+1-n);let[l,s,a,y]=c.next().value,u=n+y-a;n+=s-l;for(const t of c)[l,s,,y]=t,n!==l&&(t.length--,[t[0],t[1],t[2]]=[n,u,l-n],yield t),[n,u]=[s,y];n<o&&(yield[n,u,o-n])}function*calcPatch(t,e){const n=ArrayBuffer.isView(e)?Uint8Array.prototype.subarray:e.slice;for(const[o,f,r,i]of diff(t,e))yield[o,f,n.call(e,r,i)]}function*applyPatch(t,e){let n=0;const o=ArrayBuffer.isView(t)?Uint8Array.prototype.subarray:t.slice;for(const[f,r,i]of e)n<f&&(yield o.call(t,n,f)),i.length>0&&(yield i),n=r;n<t.length&&(yield o.call(t,n))}Object.defineProperty(exports,"__esModule",{value:!0}),exports.diff=diff,exports.lcs=lcs,exports.calcPatch=calcPatch,exports.applyPatch=applyPatch;
{
"name": "fast-myers-diff",
"version": "1.0.0",
"version": "1.0.1",
"description": "A fast, minimal, memory-efficient diff algorithm on strings, arrays, and typed arrays.",

@@ -25,3 +25,12 @@ "main": "dist/index.js",

"typescript": "^3.8.3"
}
},
"dependencies": {},
"repository": {
"type": "git",
"url": "git+https://github.com/gliese1337/fast-myers-diff.git"
},
"bugs": {
"url": "https://github.com/gliese1337/fast-myers-diff/issues"
},
"homepage": "https://github.com/gliese1337/fast-myers-diff#readme"
}

@@ -5,3 +5,3 @@ Fast-Myers-Diff

This is a fast, compact, memory efficient implementation of the O(ND) Myers diff algorithm.
The core diff algorithm, including blank lines and comment, is only 123 lines. With LCS and patch features added, the total library is still less than 200 lines.
The core diff algorithm, including blank lines and comment, is only 117 lines. With LCS and patch features added, the total library is still less than 200 lines.
Minified and including type definitions, the published library is less than 3KB.

@@ -50,2 +50,2 @@

This `diff(xs, ys)` and `lcs(xs, ys)` will also work with custom container types, as long as your container objects have a numeric `length` property. `calcPatch(xs, ys)` and 'applyPatch(xs, ys)` will also with with custom types, provided that they also implement a suitable `slice(start[, end])` method.
This `diff(xs, ys)` and `lcs(xs, ys)` will also work with custom container types, as long as your container objects have a numeric `length` property. `calcPatch(xs, ys)` and `applyPatch(xs, ys)` will also with with custom types, provided that they also implement a suitable `slice(start[, end])` method.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc