diff-leven 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +15 -15
- package/dist/index.mjs +15 -15
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _leven = require('leven'); var _leven2 = _interopRequireDefault(_leven);var
|
|
2
|
-
${f}
|
|
3
|
-
${
|
|
4
|
-
`,f=0;if(e.children)for(let
|
|
5
|
-
`),
|
|
6
|
-
`),
|
|
7
|
-
`),
|
|
8
|
-
`,f=0;if(e.children){let
|
|
9
|
-
`)&&(
|
|
10
|
-
`),
|
|
11
|
-
`)&&(
|
|
12
|
-
`)||(
|
|
13
|
-
`)}}return f>0&&!
|
|
14
|
-
`)&&(
|
|
15
|
-
`),
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _leven = require('leven'); var _leven2 = _interopRequireDefault(_leven);var h=(u=>(u.ADDED="added",u.REMOVED="removed",u.CHANGED="changed",u.UNCHANGED="unchanged",u))(h||{});function p(e,t,s={},n=[]){let{keysOnly:u=!1,ignoreValues:D=!1}=s;if(e===void 0&&t===void 0)return{type:"unchanged"};if(e===void 0)return{type:"added",path:n,newValue:t};if(t===void 0)return{type:"removed",path:n,oldValue:e};if(typeof e!="object"||typeof t!="object"||e===null||t===null){if(u||D)return{type:"unchanged",path:n,oldValue:e,newValue:t,meta:{ignored:!0}};if(e===t)return{type:"unchanged",path:n,oldValue:e,newValue:t};if(typeof e=="string"&&typeof t=="string"){let c=_leven2.default.call(void 0, e,t),i=Math.max(e.length,t.length),r=i>0?1-c/i:1;return{type:"changed",path:n,oldValue:e,newValue:t,meta:{levenDistance:c,similarity:r}}}return{type:"changed",path:n,oldValue:e,newValue:t}}return Array.isArray(e)!==Array.isArray(t)?{type:"changed",path:n,oldValue:e,newValue:t}:Array.isArray(e)&&Array.isArray(t)?C(e,t,s,n):S(e,t,s,n)}function S(e,t,s,n){let{ignoreKeys:u=[]}=s,D=new Set([...Object.keys(e).filter(r=>!u.includes(r)),...Object.keys(t).filter(r=>!u.includes(r))]),c=[],i=!1;for(let r of D){let f=[...n,r],y=e[r],l=t[r],o=p(y,l,s,f);o.type!=="unchanged"&&(i=!0),c.push(o)}return i?{type:"changed",path:n,oldValue:e,newValue:t,children:c}:{type:"unchanged",path:n,oldValue:e,newValue:t}}function C(e,t,s,n){let u=Math.max(e.length,t.length),D=[],c=!1;for(let i=0;i<u;i++){let r=[...n,i.toString()];if(i>=e.length)D.push({type:"added",path:r,newValue:t[i]}),c=!0;else if(i>=t.length)D.push({type:"removed",path:r,oldValue:e[i]}),c=!0;else{let f=p(e[i],t[i],s,r);f.type!=="unchanged"&&(c=!0),D.push(f)}}return c?{type:"changed",path:n,oldValue:e,newValue:t,children:D}:{type:"unchanged",path:n,oldValue:e,newValue:t}}var a={reset:"\x1B[0m",red:"\x1B[31m",green:"\x1B[32m",gray:"\x1B[90m"};function E(e,t={}){let{color:s=!0,full:n=!1,withSimilarity:u=!1}=t;return e.type==="unchanged"&&!n&&(!e.children||e.children.length===0)?"":!e.children||e.children.length===0?G(e,s,u):H(e,t,0)}function G(e,t,s=!1){let n=O(e.type),u="";switch(e.type){case"added":return u=$(e.newValue),t?`${a.green}${n} ${u}${a.reset}`:`${n} ${u}`;case"removed":return u=$(e.oldValue),t?`${a.red}${n} ${u}${a.reset}`:`${n} ${u}`;case"changed":{let D=$(e.oldValue),c=$(e.newValue),i="";if(s&&_optionalChain([e, 'access', _ => _.meta, 'optionalAccess', _2 => _2.similarity])!==void 0&&typeof e.oldValue=="string"&&typeof e.newValue=="string"){let y=Math.round(e.meta.similarity*100);i=t?`${a.gray} (${y}% similar)${a.reset}`:` (${y}% similar)`}let r=t?`${a.green}+ ${c}${a.reset}${i}`:`+ ${c}${i}`,f=t?`${a.red}- ${D}${a.reset}`:`- ${D}`;return`${r}
|
|
2
|
+
${f}`}default:return u=$(_nullishCoalesce(e.newValue, () => (e.oldValue))),t?`${a.gray}${n} ${u}${a.reset}`:`${n} ${u}`}}function H(e,t,s=0){let{full:n=!1}=t;return e.type==="unchanged"&&!n&&(!e.children||e.children.length===0||typeof e.oldValue!="object"&&typeof e.newValue!="object")?"":Array.isArray(e.oldValue)||Array.isArray(e.newValue)?b(e,t,s):d(e,t,s)}function V(e,t,s,n,u,D){let{color:c,withSimilarity:i}=s,r="";i&&u!==void 0&&(r=c?`${a.gray} (${Math.round(u*100)}% similar)${a.reset}`:` (${Math.round(u*100)}% similar)`);let f=D?`${D}: `:"",y=c?`${n}${a.green}+ ${f}${$(e)}${a.reset}${r}`:`${n}+ ${f}${$(e)}${r}`,l=c?`${n}${a.red}- ${f}${$(t)}${a.reset}`:`${n}- ${f}${$(t)}`;return`${y}
|
|
3
|
+
${l}`}function b(e,t,s=0){let{color:n=!0,full:u=!1,withSimilarity:D=!1}=t,c=" ".repeat(s),i=" ".repeat(s+2),r=`[
|
|
4
|
+
`,f=0;if(e.children)for(let y=0;y<e.children.length;y++){let l=e.children[y];if(!(l.type==="unchanged"&&!u&&(!l.children||l.children.length===0)))if(l.children&&l.children.length>0){let o=Array.isArray(l.newValue||l.oldValue)?b(l,t,s+2):d(l,t,s+2);o!=="[]"&&o!=="{}"&&(f>0&&(r+=`,
|
|
5
|
+
`),r+=i,r+=o,f++)}else switch(f>0&&(r+=`,
|
|
6
|
+
`),l.type){case"added":r+=n?`${i}${a.green}+ ${$(l.newValue)}${a.reset}`:`${i}+ ${$(l.newValue)}`,f++;break;case"removed":r+=n?`${i}${a.red}- ${$(l.oldValue)}${a.reset}`:`${i}- ${$(l.oldValue)}`,f++;break;case"unchanged":_optionalChain([l, 'access', _3 => _3.meta, 'optionalAccess', _4 => _4.ignored])&&l.path?r+=n?`${i}${a.gray} ${l.path[l.path.length-1]||""}${a.reset}`:`${i} ${l.path[l.path.length-1]||""}`:r+=n?`${i}${a.gray} ${$(l.newValue)}${a.reset}`:`${i} ${$(l.newValue)}`,f++;break;case"changed":r+=V(l.newValue,l.oldValue,{color:n,withSimilarity:D},i,_optionalChain([l, 'access', _5 => _5.meta, 'optionalAccess', _6 => _6.similarity])),f++;break}}return f>0&&(r+=`
|
|
7
|
+
`),r+=`${c}]`,r}function d(e,t,s=0){let{color:n=!0,full:u=!1,withSimilarity:D=!1}=t,c=" ".repeat(s),i=" ".repeat(s+2),r=`{
|
|
8
|
+
`,f=0;if(e.children){let y=e.children.filter(l=>{if(l.type!=="unchanged"||u||l.children&&l.children.length>0)return!0;let o=_optionalChain([l, 'access', _7 => _7.path, 'optionalAccess', _8 => _8[l.path.length-1]])||"";return!!_optionalChain([t, 'access', _9 => _9.outputKeys, 'optionalAccess', _10 => _10.includes, 'call', _11 => _11(o)])});for(let l=0;l<y.length;l++){let o=y[l],g=_optionalChain([o, 'access', _12 => _12.path, 'optionalAccess', _13 => _13[o.path.length-1]])||"",A=l===y.length-1;if(f>0&&!r.endsWith(`
|
|
9
|
+
`)&&(r+=`,
|
|
10
|
+
`),o.children&&o.children.length>0){let m=Array.isArray(o.newValue||o.oldValue)?b(o,t,s+2):d(o,t,s+2);m!=="{}"&&m!=="[]"&&(r+=`${i}${g}: `,r+=m,f++)}else switch(o.type){case"added":r+=n?`${i}${a.green}+ ${g}: ${$(o.newValue)}${a.reset}`:`${i}+ ${g}: ${$(o.newValue)}`,f++;break;case"removed":r+=n?`${i}${a.red}- ${g}: ${$(o.oldValue)}${a.reset}`:`${i}- ${g}: ${$(o.oldValue)}`,f++;break;case"changed":r+=V(o.newValue,o.oldValue,{color:n,withSimilarity:D},i,_optionalChain([o, 'access', _14 => _14.meta, 'optionalAccess', _15 => _15.similarity]),g),f++;break;case"unchanged":(u||_optionalChain([t, 'access', _16 => _16.outputKeys, 'optionalAccess', _17 => _17.includes, 'call', _18 => _18(g)]))&&(_optionalChain([o, 'access', _19 => _19.meta, 'optionalAccess', _20 => _20.ignored])?r+=n?`${i}${a.gray} ${g}${a.reset}`:`${i} ${g}`:r+=n?`${i}${a.gray} ${g}: ${$(o.newValue)}${a.reset}`:`${i} ${g}: ${$(o.newValue)}`,f++);break}!A&&!r.endsWith(`
|
|
11
|
+
`)&&(r+=","),r.endsWith(`
|
|
12
|
+
`)||(r+=`
|
|
13
|
+
`)}}return f>0&&!r.endsWith(`
|
|
14
|
+
`)&&(r+=`
|
|
15
|
+
`),r+=`${c}}`,r}function O(e){switch(e){case"added":return"+";case"removed":return"-";case"changed":return"!";default:return" "}}function $(e){return e===void 0?"undefined":e===null?"null":typeof e=="string"?`'${e}'`:typeof e=="number"||typeof e=="boolean"?e.toString():typeof e=="object"?JSON.stringify(e,null,2):String(e)}function N(e,t,s={}){return p(e,t,s)}function Q(e,t,s={}){let n=N(e,t,s);return E(n,s)}function X(e,t,s={}){return N(e,t,s).type!=="unchanged"}exports.DiffType = h; exports.diff = Q; exports.diffRaw = N; exports.isDiff = X;
|
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
${f}
|
|
3
|
-
${
|
|
4
|
-
`,f=0;if(e.children)for(let
|
|
5
|
-
`),
|
|
6
|
-
`),
|
|
7
|
-
`),
|
|
8
|
-
`,f=0;if(e.children){let
|
|
9
|
-
`)&&(
|
|
10
|
-
`),
|
|
11
|
-
`)&&(
|
|
12
|
-
`)||(
|
|
13
|
-
`)}}return f>0&&!
|
|
14
|
-
`)&&(
|
|
15
|
-
`),
|
|
1
|
+
import R from"leven";var h=(u=>(u.ADDED="added",u.REMOVED="removed",u.CHANGED="changed",u.UNCHANGED="unchanged",u))(h||{});function p(e,t,s={},n=[]){let{keysOnly:u=!1,ignoreValues:D=!1}=s;if(e===void 0&&t===void 0)return{type:"unchanged"};if(e===void 0)return{type:"added",path:n,newValue:t};if(t===void 0)return{type:"removed",path:n,oldValue:e};if(typeof e!="object"||typeof t!="object"||e===null||t===null){if(u||D)return{type:"unchanged",path:n,oldValue:e,newValue:t,meta:{ignored:!0}};if(e===t)return{type:"unchanged",path:n,oldValue:e,newValue:t};if(typeof e=="string"&&typeof t=="string"){let c=R(e,t),i=Math.max(e.length,t.length),r=i>0?1-c/i:1;return{type:"changed",path:n,oldValue:e,newValue:t,meta:{levenDistance:c,similarity:r}}}return{type:"changed",path:n,oldValue:e,newValue:t}}return Array.isArray(e)!==Array.isArray(t)?{type:"changed",path:n,oldValue:e,newValue:t}:Array.isArray(e)&&Array.isArray(t)?C(e,t,s,n):S(e,t,s,n)}function S(e,t,s,n){let{ignoreKeys:u=[]}=s,D=new Set([...Object.keys(e).filter(r=>!u.includes(r)),...Object.keys(t).filter(r=>!u.includes(r))]),c=[],i=!1;for(let r of D){let f=[...n,r],y=e[r],l=t[r],o=p(y,l,s,f);o.type!=="unchanged"&&(i=!0),c.push(o)}return i?{type:"changed",path:n,oldValue:e,newValue:t,children:c}:{type:"unchanged",path:n,oldValue:e,newValue:t}}function C(e,t,s,n){let u=Math.max(e.length,t.length),D=[],c=!1;for(let i=0;i<u;i++){let r=[...n,i.toString()];if(i>=e.length)D.push({type:"added",path:r,newValue:t[i]}),c=!0;else if(i>=t.length)D.push({type:"removed",path:r,oldValue:e[i]}),c=!0;else{let f=p(e[i],t[i],s,r);f.type!=="unchanged"&&(c=!0),D.push(f)}}return c?{type:"changed",path:n,oldValue:e,newValue:t,children:D}:{type:"unchanged",path:n,oldValue:e,newValue:t}}var a={reset:"\x1B[0m",red:"\x1B[31m",green:"\x1B[32m",gray:"\x1B[90m"};function E(e,t={}){let{color:s=!0,full:n=!1,withSimilarity:u=!1}=t;return e.type==="unchanged"&&!n&&(!e.children||e.children.length===0)?"":!e.children||e.children.length===0?G(e,s,u):H(e,t,0)}function G(e,t,s=!1){let n=O(e.type),u="";switch(e.type){case"added":return u=$(e.newValue),t?`${a.green}${n} ${u}${a.reset}`:`${n} ${u}`;case"removed":return u=$(e.oldValue),t?`${a.red}${n} ${u}${a.reset}`:`${n} ${u}`;case"changed":{let D=$(e.oldValue),c=$(e.newValue),i="";if(s&&e.meta?.similarity!==void 0&&typeof e.oldValue=="string"&&typeof e.newValue=="string"){let y=Math.round(e.meta.similarity*100);i=t?`${a.gray} (${y}% similar)${a.reset}`:` (${y}% similar)`}let r=t?`${a.green}+ ${c}${a.reset}${i}`:`+ ${c}${i}`,f=t?`${a.red}- ${D}${a.reset}`:`- ${D}`;return`${r}
|
|
2
|
+
${f}`}default:return u=$(e.newValue??e.oldValue),t?`${a.gray}${n} ${u}${a.reset}`:`${n} ${u}`}}function H(e,t,s=0){let{full:n=!1}=t;return e.type==="unchanged"&&!n&&(!e.children||e.children.length===0||typeof e.oldValue!="object"&&typeof e.newValue!="object")?"":Array.isArray(e.oldValue)||Array.isArray(e.newValue)?b(e,t,s):d(e,t,s)}function V(e,t,s,n,u,D){let{color:c,withSimilarity:i}=s,r="";i&&u!==void 0&&(r=c?`${a.gray} (${Math.round(u*100)}% similar)${a.reset}`:` (${Math.round(u*100)}% similar)`);let f=D?`${D}: `:"",y=c?`${n}${a.green}+ ${f}${$(e)}${a.reset}${r}`:`${n}+ ${f}${$(e)}${r}`,l=c?`${n}${a.red}- ${f}${$(t)}${a.reset}`:`${n}- ${f}${$(t)}`;return`${y}
|
|
3
|
+
${l}`}function b(e,t,s=0){let{color:n=!0,full:u=!1,withSimilarity:D=!1}=t,c=" ".repeat(s),i=" ".repeat(s+2),r=`[
|
|
4
|
+
`,f=0;if(e.children)for(let y=0;y<e.children.length;y++){let l=e.children[y];if(!(l.type==="unchanged"&&!u&&(!l.children||l.children.length===0)))if(l.children&&l.children.length>0){let o=Array.isArray(l.newValue||l.oldValue)?b(l,t,s+2):d(l,t,s+2);o!=="[]"&&o!=="{}"&&(f>0&&(r+=`,
|
|
5
|
+
`),r+=i,r+=o,f++)}else switch(f>0&&(r+=`,
|
|
6
|
+
`),l.type){case"added":r+=n?`${i}${a.green}+ ${$(l.newValue)}${a.reset}`:`${i}+ ${$(l.newValue)}`,f++;break;case"removed":r+=n?`${i}${a.red}- ${$(l.oldValue)}${a.reset}`:`${i}- ${$(l.oldValue)}`,f++;break;case"unchanged":l.meta?.ignored&&l.path?r+=n?`${i}${a.gray} ${l.path[l.path.length-1]||""}${a.reset}`:`${i} ${l.path[l.path.length-1]||""}`:r+=n?`${i}${a.gray} ${$(l.newValue)}${a.reset}`:`${i} ${$(l.newValue)}`,f++;break;case"changed":r+=V(l.newValue,l.oldValue,{color:n,withSimilarity:D},i,l.meta?.similarity),f++;break}}return f>0&&(r+=`
|
|
7
|
+
`),r+=`${c}]`,r}function d(e,t,s=0){let{color:n=!0,full:u=!1,withSimilarity:D=!1}=t,c=" ".repeat(s),i=" ".repeat(s+2),r=`{
|
|
8
|
+
`,f=0;if(e.children){let y=e.children.filter(l=>{if(l.type!=="unchanged"||u||l.children&&l.children.length>0)return!0;let o=l.path?.[l.path.length-1]||"";return!!t.outputKeys?.includes(o)});for(let l=0;l<y.length;l++){let o=y[l],g=o.path?.[o.path.length-1]||"",A=l===y.length-1;if(f>0&&!r.endsWith(`
|
|
9
|
+
`)&&(r+=`,
|
|
10
|
+
`),o.children&&o.children.length>0){let m=Array.isArray(o.newValue||o.oldValue)?b(o,t,s+2):d(o,t,s+2);m!=="{}"&&m!=="[]"&&(r+=`${i}${g}: `,r+=m,f++)}else switch(o.type){case"added":r+=n?`${i}${a.green}+ ${g}: ${$(o.newValue)}${a.reset}`:`${i}+ ${g}: ${$(o.newValue)}`,f++;break;case"removed":r+=n?`${i}${a.red}- ${g}: ${$(o.oldValue)}${a.reset}`:`${i}- ${g}: ${$(o.oldValue)}`,f++;break;case"changed":r+=V(o.newValue,o.oldValue,{color:n,withSimilarity:D},i,o.meta?.similarity,g),f++;break;case"unchanged":(u||t.outputKeys?.includes(g))&&(o.meta?.ignored?r+=n?`${i}${a.gray} ${g}${a.reset}`:`${i} ${g}`:r+=n?`${i}${a.gray} ${g}: ${$(o.newValue)}${a.reset}`:`${i} ${g}: ${$(o.newValue)}`,f++);break}!A&&!r.endsWith(`
|
|
11
|
+
`)&&(r+=","),r.endsWith(`
|
|
12
|
+
`)||(r+=`
|
|
13
|
+
`)}}return f>0&&!r.endsWith(`
|
|
14
|
+
`)&&(r+=`
|
|
15
|
+
`),r+=`${c}}`,r}function O(e){switch(e){case"added":return"+";case"removed":return"-";case"changed":return"!";default:return" "}}function $(e){return e===void 0?"undefined":e===null?"null":typeof e=="string"?`'${e}'`:typeof e=="number"||typeof e=="boolean"?e.toString():typeof e=="object"?JSON.stringify(e,null,2):String(e)}function N(e,t,s={}){return p(e,t,s)}function Q(e,t,s={}){let n=N(e,t,s);return E(n,s)}function X(e,t,s={}){return N(e,t,s).type!=="unchanged"}export{h as DiffType,Q as diff,N as diffRaw,X as isDiff};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "diff-leven",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Git like diff between two strings, using the Levenshtein distance algorithm",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -52,14 +52,14 @@
|
|
|
52
52
|
},
|
|
53
53
|
"homepage": "https://github.com/kushalshit27/diff-leven#readme",
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"eslint": "^
|
|
55
|
+
"eslint": "^10.0.3",
|
|
56
56
|
"husky": "9.1.7",
|
|
57
|
-
"prettier": "^3.
|
|
57
|
+
"prettier": "^3.8.1",
|
|
58
58
|
"ts-node": "^10.9.2",
|
|
59
59
|
"tsup": "^8.5.1",
|
|
60
60
|
"typescript": "^5.9.3",
|
|
61
|
-
"typescript-eslint": "^8.
|
|
62
|
-
"vitest": "^4.0.
|
|
61
|
+
"typescript-eslint": "^8.57.0",
|
|
62
|
+
"vitest": "^4.0.18"
|
|
63
63
|
},
|
|
64
64
|
"engines": {
|
|
65
65
|
"node": ">=18"
|