diff-leven 0.3.0 → 0.3.2
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/README.md +2 -2
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +11 -14
- package/dist/index.mjs +11 -14
- package/package.json +22 -7
package/README.md
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
> Git-like diff between two strings or objects, powered by the Levenshtein distance algorithm
|
|
4
4
|
|
|
5
|
-
[](https://
|
|
5
|
+
[](https://www.npmjs.com/package/diff-leven)
|
|
6
6
|
[](https://www.npmjs.com/package/diff-leven)
|
|
7
|
+
[](https://www.jsdelivr.com/package/npm/diff-leven)
|
|
7
8
|

|
|
8
9
|
|
|
9
10
|
---
|
|
@@ -17,7 +18,6 @@
|
|
|
17
18
|
- Strings (character-level differences)
|
|
18
19
|
- Numbers, Booleans, and any serializable value
|
|
19
20
|
- **Rich Output Options**:
|
|
20
|
-
|
|
21
21
|
- Git-style colorized output diff format with clear additions/removals
|
|
22
22
|
|
|
23
23
|
- **Flexible Configuration**:
|
package/dist/index.d.mts
CHANGED
|
@@ -53,8 +53,8 @@ declare enum DiffType {
|
|
|
53
53
|
interface DiffResult {
|
|
54
54
|
type: DiffType;
|
|
55
55
|
path?: string[];
|
|
56
|
-
oldValue?:
|
|
57
|
-
newValue?:
|
|
56
|
+
oldValue?: SerializableValue;
|
|
57
|
+
newValue?: SerializableValue;
|
|
58
58
|
children?: DiffResult[];
|
|
59
59
|
/**
|
|
60
60
|
* Additional metadata about the diff, such as Levenshtein distance metrics
|
|
@@ -65,7 +65,7 @@ interface DiffResult {
|
|
|
65
65
|
/** Similarity ratio (0-1) where 1 means identical */
|
|
66
66
|
similarity?: number;
|
|
67
67
|
/** Any other metadata properties */
|
|
68
|
-
[key: string]:
|
|
68
|
+
[key: string]: unknown;
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
71
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -53,8 +53,8 @@ declare enum DiffType {
|
|
|
53
53
|
interface DiffResult {
|
|
54
54
|
type: DiffType;
|
|
55
55
|
path?: string[];
|
|
56
|
-
oldValue?:
|
|
57
|
-
newValue?:
|
|
56
|
+
oldValue?: SerializableValue;
|
|
57
|
+
newValue?: SerializableValue;
|
|
58
58
|
children?: DiffResult[];
|
|
59
59
|
/**
|
|
60
60
|
* Additional metadata about the diff, such as Levenshtein distance metrics
|
|
@@ -65,7 +65,7 @@ interface DiffResult {
|
|
|
65
65
|
/** Similarity ratio (0-1) where 1 means identical */
|
|
66
66
|
similarity?: number;
|
|
67
67
|
/** Any other metadata properties */
|
|
68
|
-
[key: string]:
|
|
68
|
+
[key: string]: unknown;
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
71
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,18 +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
|
-
${
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
`),
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
`,f=0;if(e.children){let y=e.children.filter(i=>{if(i.type!=="unchanged"||o||i.children&&i.children.length>0)return!0;let a=_optionalChain([i, 'access', _9 => _9.path, 'optionalAccess', _10 => _10[i.path.length-1]])||"";return!!_optionalChain([t, 'access', _11 => _11.outputKeys, 'optionalAccess', _12 => _12.includes, 'call', _13 => _13(a)])});for(let i=0;i<y.length;i++){let a=y[i],m=_optionalChain([a, 'access', _14 => _14.path, 'optionalAccess', _15 => _15[a.path.length-1]])||"",R=i===y.length-1;if(f>0&&!n.endsWith(`
|
|
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 p=(f=>(f.ADDED="added",f.REMOVED="removed",f.CHANGED="changed",f.UNCHANGED="unchanged",f))(p||{});function y(e,t,a={},r=[]){let{keysOnly:f=!1,ignoreValues:g=!1}=a;if(e===void 0&&t===void 0)return{type:"unchanged"};if(e===void 0)return{type:"added",path:r,newValue:t};if(t===void 0)return{type:"removed",path:r,oldValue:e};if(typeof e!="object"||typeof t!="object"||e===null||t===null){if(f||g)return{type:"unchanged",path:r,oldValue:e,newValue:t,meta:{ignored:!0}};if(e===t)return{type:"unchanged",path:r,oldValue:e,newValue:t};if(typeof e=="string"&&typeof t=="string"){let c=_leven2.default.call(void 0, e,t),l=Math.max(e.length,t.length),n=l>0?1-c/l:1;return{type:"changed",path:r,oldValue:e,newValue:t,meta:{levenDistance:c,similarity:n}}}return{type:"changed",path:r,oldValue:e,newValue:t}}return Array.isArray(e)&&Array.isArray(t)?C(e,t,a,r):A(e,t,a,r)}function A(e,t,a,r){let{ignoreKeys:f=[]}=a,g=new Set([...Object.keys(e).filter(n=>!f.includes(n)),...Object.keys(t).filter(n=>!f.includes(n))]),c=[],l=!1;for(let n of g){let s=[...r,n],D=e[n],i=t[n],o=y(D,i,a,s);o.type!=="unchanged"&&(l=!0),c.push(o)}return l?{type:"changed",path:r,oldValue:e,newValue:t,children:c}:{type:"unchanged",path:r,oldValue:e,newValue:t}}function C(e,t,a,r){if(e.length!==t.length){let c=[],l=Math.max(e.length,t.length);for(let n=0;n<l;n++){let s=[...r,n.toString()];n>=e.length?c.push({type:"added",path:s,newValue:t[n]}):n>=t.length?c.push({type:"removed",path:s,oldValue:e[n]}):c.push(y(e[n],t[n],a,s))}return{type:"changed",path:r,oldValue:e,newValue:t,children:c}}let f=[],g=!1;for(let c=0;c<e.length;c++){let l=[...r,c.toString()],n=e[c],s=t[c],D;if(typeof n=="string"&&typeof s=="string")if(n===s)D={type:"unchanged",path:l,oldValue:n,newValue:s};else{let i=_leven2.default.call(void 0, n,s),o=Math.max(n.length,s.length),h=o>0?1-i/o:1;D={type:"changed",path:l,oldValue:n,newValue:s,meta:{levenDistance:i,similarity:h}},g=!0}else D=y(n,s,a,l),D.type!=="unchanged"&&(g=!0);f.push(D)}return g?{type:"changed",path:r,oldValue:e,newValue:t,children:f}:{type:"unchanged",path:r,oldValue:e,newValue:t}}var u={reset:"\x1B[0m",red:"\x1B[31m",green:"\x1B[32m",gray:"\x1B[90m"};function E(e,t={}){let{color:a=!0,full:r=!1,withSimilarity:f=!1}=t;return e.type==="unchanged"&&!r&&(!e.children||e.children.length===0)?"":!e.children||e.children.length===0?G(e,a,f):H(e,t,0)}function G(e,t,a=!1){let r=x(e.type),f="";switch(e.type){case"added":return f=$(e.newValue),t?`${u.green}${r} ${f}${u.reset}`:`${r} ${f}`;case"removed":return f=$(e.oldValue),t?`${u.red}${r} ${f}${u.reset}`:`${r} ${f}`;case"changed":let g=$(e.oldValue),c=$(e.newValue),l="";if(a&&_optionalChain([e, 'access', _ => _.meta, 'optionalAccess', _2 => _2.similarity])!==void 0&&typeof e.oldValue=="string"&&typeof e.newValue=="string"){let D=Math.round(e.meta.similarity*100);l=t?`${u.gray} (${D}% similar)${u.reset}`:` (${D}% similar)`}let n=t?`${u.green}+ ${c}${l}${u.reset}`:`+ ${c}${l}`,s=t?`${u.red}- ${g}${u.reset}`:`- ${g}`;return`${n}
|
|
2
|
+
${s}`;default:return f=$(_nullishCoalesce(e.newValue, () => (e.oldValue))),t?`${u.gray}${r} ${f}${u.reset}`:`${r} ${f}`}}function H(e,t,a=0){let{full:r=!1}=t;return e.type==="unchanged"&&!r&&(!e.children||e.children.length===0||typeof e.oldValue!="object"&&typeof e.newValue!="object")?"":Array.isArray(e.oldValue)||Array.isArray(e.newValue)?m(e,t,a):b(e,t,a)}function N(e,t,a,r,f,g){let{color:c,withSimilarity:l}=a,n="";l&&f!==void 0&&(n=c?`${u.gray} (${Math.round(f*100)}% similar)${u.reset}`:` (${Math.round(f*100)}% similar)`);let s=g?`${g}: `:"",D=c?`${r}${u.green}+ ${s}${$(e)}${n}${u.reset}`:`${r}+ ${s}${$(e)}${n}`,i=c?`${r}${u.red}- ${s}${$(t)}${u.reset}`:`${r}- ${s}${$(t)}`;return`${D}
|
|
3
|
+
${i}`}function m(e,t,a=0){let{color:r=!0,full:f=!1,withSimilarity:g=!1}=t,c=" ".repeat(a),l=" ".repeat(a+2),n=`[
|
|
4
|
+
`,s=0;if(e.children)for(let D=0;D<e.children.length;D++){let i=e.children[D];if(!(i.type==="unchanged"&&!f&&(!i.children||i.children.length===0)))if(i.children&&i.children.length>0){let o=Array.isArray(i.newValue||i.oldValue)?m(i,t,a+2):b(i,t,a+2);o.trim().length>2&&(s>0&&(n+=`,
|
|
5
|
+
`),n+=l,n+=o,s++)}else switch(s>0&&(n+=`,
|
|
6
|
+
`),i.type){case"added":n+=r?`${l}${u.green}+ ${$(i.newValue)}${u.reset}`:`${l}+ ${$(i.newValue)}`,s++;break;case"removed":n+=r?`${l}${u.red}- ${$(i.oldValue)}${u.reset}`:`${l}- ${$(i.oldValue)}`,s++;break;case"unchanged":_optionalChain([i, 'access', _3 => _3.meta, 'optionalAccess', _4 => _4.ignored])&&i.path?n+=r?`${l}${u.gray} ${i.path[i.path.length-1]||""}${u.reset}`:`${l} ${i.path[i.path.length-1]||""}`:n+=r?`${l}${u.gray} ${$(i.newValue)}${u.reset}`:`${l} ${$(i.newValue)}`,s++;break;case"changed":n+=N(i.newValue,i.oldValue,{color:r,withSimilarity:g},l,_optionalChain([i, 'access', _5 => _5.meta, 'optionalAccess', _6 => _6.similarity])),s++;break}}return s>0&&(n+=`
|
|
7
|
+
`),n+=`${c}]`,n}function b(e,t,a=0){let{color:r=!0,full:f=!1,withSimilarity:g=!1}=t,c=" ".repeat(a),l=" ".repeat(a+2),n=`{
|
|
8
|
+
`,s=0;if(e.children){let D=e.children.filter(i=>{if(i.type!=="unchanged"||f||i.children&&i.children.length>0)return!0;let o=_optionalChain([i, 'access', _7 => _7.path, 'optionalAccess', _8 => _8[i.path.length-1]])||"";return!!_optionalChain([t, 'access', _9 => _9.outputKeys, 'optionalAccess', _10 => _10.includes, 'call', _11 => _11(o)])});for(let i=0;i<D.length;i++){let o=D[i],h=_optionalChain([o, 'access', _12 => _12.path, 'optionalAccess', _13 => _13[o.path.length-1]])||"",S=i===D.length-1;if(s>0&&!n.endsWith(`
|
|
10
9
|
`)&&(n+=`,
|
|
11
|
-
`),
|
|
12
|
-
${l}${s.green}+ ${m}: ${c(a.newValue)}${_optionalChain([a, 'access', _16 => _16.meta, 'optionalAccess', _17 => _17.similarity])!==void 0&&D?r?`${s.gray} (${Math.round(a.meta.similarity*100)}% similar)${s.reset}`:` (${Math.round(a.meta.similarity*100)}% similar)`:""}${s.reset}`:`${l}- ${m}: ${c(a.oldValue)}
|
|
13
|
-
${l}+ ${m}: ${c(a.newValue)}${_optionalChain([a, 'access', _18 => _18.meta, 'optionalAccess', _19 => _19.similarity])!==void 0&&D?` (${Math.round(a.meta.similarity*100)}% similar)`:""}`,f++;break;case"unchanged":(o||_optionalChain([t, 'access', _20 => _20.outputKeys, 'optionalAccess', _21 => _21.includes, 'call', _22 => _22(m)]))&&(_optionalChain([a, 'access', _23 => _23.meta, 'optionalAccess', _24 => _24.ignored])?n+=r?`${l}${s.gray} ${m}${s.reset}`:`${l} ${m}`:n+=r?`${l}${s.gray} ${m}: ${c(a.newValue)}${s.reset}`:`${l} ${m}: ${c(a.newValue)}`,f++);break}!R&&!n.endsWith(`
|
|
10
|
+
`),o.children&&o.children.length>0){let d=Array.isArray(o.newValue||o.oldValue)?m(o,t,a+2):b(o,t,a+2);d.trim().length>2&&(n+=`${l}${h}: `,n+=d,s++)}else switch(o.type){case"added":n+=r?`${l}${u.green}+ ${h}: ${$(o.newValue)}${u.reset}`:`${l}+ ${h}: ${$(o.newValue)}`,s++;break;case"removed":n+=r?`${l}${u.red}- ${h}: ${$(o.oldValue)}${u.reset}`:`${l}- ${h}: ${$(o.oldValue)}`,s++;break;case"changed":n+=N(o.newValue,o.oldValue,{color:r,withSimilarity:g},l,_optionalChain([o, 'access', _14 => _14.meta, 'optionalAccess', _15 => _15.similarity]),h),s++;break;case"unchanged":(f||_optionalChain([t, 'access', _16 => _16.outputKeys, 'optionalAccess', _17 => _17.includes, 'call', _18 => _18(h)]))&&(_optionalChain([o, 'access', _19 => _19.meta, 'optionalAccess', _20 => _20.ignored])?n+=r?`${l}${u.gray} ${h}${u.reset}`:`${l} ${h}`:n+=r?`${l}${u.gray} ${h}: ${$(o.newValue)}${u.reset}`:`${l} ${h}: ${$(o.newValue)}`,s++);break}!S&&!n.endsWith(`
|
|
14
11
|
`)&&(n+=","),n.endsWith(`
|
|
15
12
|
`)||(n+=`
|
|
16
|
-
`)}}return
|
|
13
|
+
`)}}return s>0&&!n.endsWith(`
|
|
17
14
|
`)&&(n+=`
|
|
18
|
-
`),n+=`${
|
|
15
|
+
`),n+=`${c}}`,n}function x(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 R(e,t,a={}){return y(e,t,a)}function F(e,t,a={}){let r=R(e,t,a);return E(r,a)}function Q(e,t,a={}){return R(e,t,a).type!=="unchanged"}exports.DiffType = p; exports.diff = F; exports.diffRaw = R; exports.isDiff = Q;
|
package/dist/index.mjs
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import V from"leven";var
|
|
2
|
-
${
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
`),
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
`,f=0;if(e.children){let y=e.children.filter(i=>{if(i.type!=="unchanged"||o||i.children&&i.children.length>0)return!0;let a=i.path?.[i.path.length-1]||"";return!!t.outputKeys?.includes(a)});for(let i=0;i<y.length;i++){let a=y[i],m=a.path?.[a.path.length-1]||"",R=i===y.length-1;if(f>0&&!n.endsWith(`
|
|
1
|
+
import V from"leven";var p=(f=>(f.ADDED="added",f.REMOVED="removed",f.CHANGED="changed",f.UNCHANGED="unchanged",f))(p||{});function y(e,t,a={},r=[]){let{keysOnly:f=!1,ignoreValues:g=!1}=a;if(e===void 0&&t===void 0)return{type:"unchanged"};if(e===void 0)return{type:"added",path:r,newValue:t};if(t===void 0)return{type:"removed",path:r,oldValue:e};if(typeof e!="object"||typeof t!="object"||e===null||t===null){if(f||g)return{type:"unchanged",path:r,oldValue:e,newValue:t,meta:{ignored:!0}};if(e===t)return{type:"unchanged",path:r,oldValue:e,newValue:t};if(typeof e=="string"&&typeof t=="string"){let c=V(e,t),l=Math.max(e.length,t.length),n=l>0?1-c/l:1;return{type:"changed",path:r,oldValue:e,newValue:t,meta:{levenDistance:c,similarity:n}}}return{type:"changed",path:r,oldValue:e,newValue:t}}return Array.isArray(e)&&Array.isArray(t)?C(e,t,a,r):A(e,t,a,r)}function A(e,t,a,r){let{ignoreKeys:f=[]}=a,g=new Set([...Object.keys(e).filter(n=>!f.includes(n)),...Object.keys(t).filter(n=>!f.includes(n))]),c=[],l=!1;for(let n of g){let s=[...r,n],D=e[n],i=t[n],o=y(D,i,a,s);o.type!=="unchanged"&&(l=!0),c.push(o)}return l?{type:"changed",path:r,oldValue:e,newValue:t,children:c}:{type:"unchanged",path:r,oldValue:e,newValue:t}}function C(e,t,a,r){if(e.length!==t.length){let c=[],l=Math.max(e.length,t.length);for(let n=0;n<l;n++){let s=[...r,n.toString()];n>=e.length?c.push({type:"added",path:s,newValue:t[n]}):n>=t.length?c.push({type:"removed",path:s,oldValue:e[n]}):c.push(y(e[n],t[n],a,s))}return{type:"changed",path:r,oldValue:e,newValue:t,children:c}}let f=[],g=!1;for(let c=0;c<e.length;c++){let l=[...r,c.toString()],n=e[c],s=t[c],D;if(typeof n=="string"&&typeof s=="string")if(n===s)D={type:"unchanged",path:l,oldValue:n,newValue:s};else{let i=V(n,s),o=Math.max(n.length,s.length),h=o>0?1-i/o:1;D={type:"changed",path:l,oldValue:n,newValue:s,meta:{levenDistance:i,similarity:h}},g=!0}else D=y(n,s,a,l),D.type!=="unchanged"&&(g=!0);f.push(D)}return g?{type:"changed",path:r,oldValue:e,newValue:t,children:f}:{type:"unchanged",path:r,oldValue:e,newValue:t}}var u={reset:"\x1B[0m",red:"\x1B[31m",green:"\x1B[32m",gray:"\x1B[90m"};function E(e,t={}){let{color:a=!0,full:r=!1,withSimilarity:f=!1}=t;return e.type==="unchanged"&&!r&&(!e.children||e.children.length===0)?"":!e.children||e.children.length===0?G(e,a,f):H(e,t,0)}function G(e,t,a=!1){let r=x(e.type),f="";switch(e.type){case"added":return f=$(e.newValue),t?`${u.green}${r} ${f}${u.reset}`:`${r} ${f}`;case"removed":return f=$(e.oldValue),t?`${u.red}${r} ${f}${u.reset}`:`${r} ${f}`;case"changed":let g=$(e.oldValue),c=$(e.newValue),l="";if(a&&e.meta?.similarity!==void 0&&typeof e.oldValue=="string"&&typeof e.newValue=="string"){let D=Math.round(e.meta.similarity*100);l=t?`${u.gray} (${D}% similar)${u.reset}`:` (${D}% similar)`}let n=t?`${u.green}+ ${c}${l}${u.reset}`:`+ ${c}${l}`,s=t?`${u.red}- ${g}${u.reset}`:`- ${g}`;return`${n}
|
|
2
|
+
${s}`;default:return f=$(e.newValue??e.oldValue),t?`${u.gray}${r} ${f}${u.reset}`:`${r} ${f}`}}function H(e,t,a=0){let{full:r=!1}=t;return e.type==="unchanged"&&!r&&(!e.children||e.children.length===0||typeof e.oldValue!="object"&&typeof e.newValue!="object")?"":Array.isArray(e.oldValue)||Array.isArray(e.newValue)?m(e,t,a):b(e,t,a)}function N(e,t,a,r,f,g){let{color:c,withSimilarity:l}=a,n="";l&&f!==void 0&&(n=c?`${u.gray} (${Math.round(f*100)}% similar)${u.reset}`:` (${Math.round(f*100)}% similar)`);let s=g?`${g}: `:"",D=c?`${r}${u.green}+ ${s}${$(e)}${n}${u.reset}`:`${r}+ ${s}${$(e)}${n}`,i=c?`${r}${u.red}- ${s}${$(t)}${u.reset}`:`${r}- ${s}${$(t)}`;return`${D}
|
|
3
|
+
${i}`}function m(e,t,a=0){let{color:r=!0,full:f=!1,withSimilarity:g=!1}=t,c=" ".repeat(a),l=" ".repeat(a+2),n=`[
|
|
4
|
+
`,s=0;if(e.children)for(let D=0;D<e.children.length;D++){let i=e.children[D];if(!(i.type==="unchanged"&&!f&&(!i.children||i.children.length===0)))if(i.children&&i.children.length>0){let o=Array.isArray(i.newValue||i.oldValue)?m(i,t,a+2):b(i,t,a+2);o.trim().length>2&&(s>0&&(n+=`,
|
|
5
|
+
`),n+=l,n+=o,s++)}else switch(s>0&&(n+=`,
|
|
6
|
+
`),i.type){case"added":n+=r?`${l}${u.green}+ ${$(i.newValue)}${u.reset}`:`${l}+ ${$(i.newValue)}`,s++;break;case"removed":n+=r?`${l}${u.red}- ${$(i.oldValue)}${u.reset}`:`${l}- ${$(i.oldValue)}`,s++;break;case"unchanged":i.meta?.ignored&&i.path?n+=r?`${l}${u.gray} ${i.path[i.path.length-1]||""}${u.reset}`:`${l} ${i.path[i.path.length-1]||""}`:n+=r?`${l}${u.gray} ${$(i.newValue)}${u.reset}`:`${l} ${$(i.newValue)}`,s++;break;case"changed":n+=N(i.newValue,i.oldValue,{color:r,withSimilarity:g},l,i.meta?.similarity),s++;break}}return s>0&&(n+=`
|
|
7
|
+
`),n+=`${c}]`,n}function b(e,t,a=0){let{color:r=!0,full:f=!1,withSimilarity:g=!1}=t,c=" ".repeat(a),l=" ".repeat(a+2),n=`{
|
|
8
|
+
`,s=0;if(e.children){let D=e.children.filter(i=>{if(i.type!=="unchanged"||f||i.children&&i.children.length>0)return!0;let o=i.path?.[i.path.length-1]||"";return!!t.outputKeys?.includes(o)});for(let i=0;i<D.length;i++){let o=D[i],h=o.path?.[o.path.length-1]||"",S=i===D.length-1;if(s>0&&!n.endsWith(`
|
|
10
9
|
`)&&(n+=`,
|
|
11
|
-
`),
|
|
12
|
-
${l}${s.green}+ ${m}: ${c(a.newValue)}${a.meta?.similarity!==void 0&&D?r?`${s.gray} (${Math.round(a.meta.similarity*100)}% similar)${s.reset}`:` (${Math.round(a.meta.similarity*100)}% similar)`:""}${s.reset}`:`${l}- ${m}: ${c(a.oldValue)}
|
|
13
|
-
${l}+ ${m}: ${c(a.newValue)}${a.meta?.similarity!==void 0&&D?` (${Math.round(a.meta.similarity*100)}% similar)`:""}`,f++;break;case"unchanged":(o||t.outputKeys?.includes(m))&&(a.meta?.ignored?n+=r?`${l}${s.gray} ${m}${s.reset}`:`${l} ${m}`:n+=r?`${l}${s.gray} ${m}: ${c(a.newValue)}${s.reset}`:`${l} ${m}: ${c(a.newValue)}`,f++);break}!R&&!n.endsWith(`
|
|
10
|
+
`),o.children&&o.children.length>0){let d=Array.isArray(o.newValue||o.oldValue)?m(o,t,a+2):b(o,t,a+2);d.trim().length>2&&(n+=`${l}${h}: `,n+=d,s++)}else switch(o.type){case"added":n+=r?`${l}${u.green}+ ${h}: ${$(o.newValue)}${u.reset}`:`${l}+ ${h}: ${$(o.newValue)}`,s++;break;case"removed":n+=r?`${l}${u.red}- ${h}: ${$(o.oldValue)}${u.reset}`:`${l}- ${h}: ${$(o.oldValue)}`,s++;break;case"changed":n+=N(o.newValue,o.oldValue,{color:r,withSimilarity:g},l,o.meta?.similarity,h),s++;break;case"unchanged":(f||t.outputKeys?.includes(h))&&(o.meta?.ignored?n+=r?`${l}${u.gray} ${h}${u.reset}`:`${l} ${h}`:n+=r?`${l}${u.gray} ${h}: ${$(o.newValue)}${u.reset}`:`${l} ${h}: ${$(o.newValue)}`,s++);break}!S&&!n.endsWith(`
|
|
14
11
|
`)&&(n+=","),n.endsWith(`
|
|
15
12
|
`)||(n+=`
|
|
16
|
-
`)}}return
|
|
13
|
+
`)}}return s>0&&!n.endsWith(`
|
|
17
14
|
`)&&(n+=`
|
|
18
|
-
`),n+=`${
|
|
15
|
+
`),n+=`${c}}`,n}function x(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 R(e,t,a={}){return y(e,t,a)}function F(e,t,a={}){let r=R(e,t,a);return E(r,a)}function Q(e,t,a={}){return R(e,t,a).type!=="unchanged"}export{p as DiffType,F as diff,R as diffRaw,Q as isDiff};
|
package/package.json
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "diff-leven",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
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",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./dist/index.d.mts",
|
|
12
|
+
"default": "./dist/index.mjs"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
8
20
|
"files": [
|
|
9
21
|
"dist"
|
|
10
22
|
],
|
|
@@ -16,7 +28,7 @@
|
|
|
16
28
|
"format": "npm run format:check && npm run format:fix",
|
|
17
29
|
"format:check": "prettier --check .",
|
|
18
30
|
"format:fix": "prettier --write .",
|
|
19
|
-
"test": "vitest run",
|
|
31
|
+
"test": "vitest run --reporter=verbose",
|
|
20
32
|
"test:watch": "vitest",
|
|
21
33
|
"examples:basic": "node examples/basic.js",
|
|
22
34
|
"examples:advanced": "node examples/advanced.js",
|
|
@@ -40,19 +52,22 @@
|
|
|
40
52
|
},
|
|
41
53
|
"homepage": "https://github.com/kushalshit27/diff-leven#readme",
|
|
42
54
|
"devDependencies": {
|
|
43
|
-
"eslint": "^9.
|
|
55
|
+
"eslint": "^9.30.1",
|
|
44
56
|
"husky": "9.1.7",
|
|
45
|
-
"prettier": "^3.
|
|
57
|
+
"prettier": "^3.6.2",
|
|
46
58
|
"ts-node": "^10.9.2",
|
|
47
59
|
"tsup": "^8.5.0",
|
|
48
60
|
"typescript": "^5.8.3",
|
|
49
|
-
"typescript-eslint": "^8.
|
|
50
|
-
"vitest": "^3.
|
|
61
|
+
"typescript-eslint": "^8.35.1",
|
|
62
|
+
"vitest": "^3.2.4"
|
|
51
63
|
},
|
|
52
64
|
"engines": {
|
|
53
|
-
"node": ">=
|
|
65
|
+
"node": ">=18"
|
|
54
66
|
},
|
|
55
67
|
"dependencies": {
|
|
56
68
|
"leven": "^4.0.0"
|
|
69
|
+
},
|
|
70
|
+
"optionalDependencies": {
|
|
71
|
+
"@rollup/rollup-linux-x64-gnu": "^4.44.1"
|
|
57
72
|
}
|
|
58
73
|
}
|