forked from CorentinTh/it-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix CorentinTh#817
- Loading branch information
Showing
8 changed files
with
178 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { List } from '@vicons/tabler'; | ||
import { defineTool } from '../tool'; | ||
|
||
export const tool = defineTool({ | ||
name: 'Lists Comparer', | ||
path: '/list-comparer', | ||
description: 'Compare two list items', | ||
keywords: ['list', 'comparer'], | ||
component: () => import('./list-comparer.vue'), | ||
icon: List, | ||
createdAt: new Date('2024-08-15'), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { compareLists } from './list-comparer.service'; | ||
|
||
describe('list-comparer', () => { | ||
describe('compareLists', () => { | ||
it('return correct comparaison', () => { | ||
expect(compareLists({ | ||
list1: '1\n 2\n3\n4\n5\n4\n7\nA', | ||
list2: '1\n2\n3\n4\n6\n4\n7\na', | ||
trimItems: true, | ||
ignoreCase: true, | ||
})).to.deep.eq({ | ||
list1Not2: [ | ||
'5', | ||
], | ||
list2Not1: [ | ||
'6', | ||
], | ||
same: '1\n2\n3\n4\n4\n7\na', | ||
sameDistinct: '1\n2\n3\n4\n7\na', | ||
}); | ||
|
||
expect(compareLists({ | ||
list1: '1\n 2\n3\n4\n5\n4\n7\nA', | ||
list2: '1\n2\n3\n4\n6\n4\n7\na', | ||
trimItems: false, | ||
ignoreCase: false, | ||
})).to.deep.eq({ | ||
list1Not2: [ | ||
' 2', | ||
'5', | ||
'A', | ||
], | ||
list2Not1: [ | ||
'2', | ||
'6', | ||
'a', | ||
], | ||
same: '1\n3\n4\n4\n7', | ||
sameDistinct: '1\n3\n4\n7', | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import _ from 'lodash'; | ||
import * as diff from 'fast-array-diff'; | ||
|
||
export function compareLists({ | ||
list1, | ||
list2, | ||
ignoreCase, | ||
trimItems, | ||
}: { | ||
list1: string | ||
list2: string | ||
ignoreCase: boolean | ||
trimItems: boolean | ||
}) { | ||
const prepareList = (list: string) => | ||
_.chain(list ?? '') | ||
.thru(text => ignoreCase ? text.toLowerCase() : text) | ||
.split('\n') | ||
.map(text => trimItems ? text.trim() : text) | ||
.value(); | ||
|
||
const list1Arr = prepareList(list1); | ||
const list2Arr = prepareList(list2); | ||
|
||
const arrSame = diff.same(list1Arr, list2Arr); | ||
const arrDifferences = diff.diff(list1Arr, list2Arr); | ||
return { | ||
same: arrSame.join('\n'), | ||
sameDistinct: [...new Set(arrSame)].join('\n'), | ||
list2Not1: arrDifferences.added, | ||
list1Not2: arrDifferences.removed, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<script setup lang="ts"> | ||
import { compareLists } from './list-comparer.service'; | ||
const compareConfig = useStorage<{ ignoreCase: boolean; trimItems: boolean }>('list-cmp:conf', { | ||
ignoreCase: false, | ||
trimItems: true, | ||
}); | ||
const list1 = ref(''); | ||
const list2 = ref(''); | ||
const compareResult = computed(() => { | ||
return compareLists({ | ||
list1: list1.value, | ||
list2: list2.value, | ||
ignoreCase: compareConfig.value.ignoreCase, | ||
trimItems: compareConfig.value.trimItems, | ||
}); | ||
}); | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<n-space justify="space-evenly"> | ||
<n-form-item label="Trim items" label-placement="left" mb-2> | ||
<n-switch v-model:value="compareConfig.trimItems" /> | ||
</n-form-item> | ||
<n-form-item | ||
label="Ignore case" | ||
label-placement="left" | ||
:show-feedback="false" | ||
mb-2 | ||
> | ||
<n-switch v-model:value="compareConfig.ignoreCase" /> | ||
</n-form-item> | ||
</n-space> | ||
|
||
<div flex gap-1> | ||
<c-input-text | ||
multiline | ||
rows="10" | ||
label="List 1" | ||
:value="list1" | ||
/> | ||
<c-input-text | ||
multiline | ||
rows="10" | ||
label="List 2" | ||
:value="list2" | ||
/> | ||
</div> | ||
|
||
<div v-if="list1 && list2"> | ||
<n-divider /> | ||
|
||
<c-card title="Items in bot</div>h lists" mb-2> | ||
<textarea-copyable :value="compareResult.same" /> | ||
</c-card> | ||
<c-card title="Items in both lists (no duplicate)" mb-2> | ||
<textarea-copyable :value="compareResult.sameDistinct" /> | ||
</c-card> | ||
<c-card title="Items in List 1 but not in List 2" mb-2> | ||
<textarea-copyable :value="compareResult.list1Not2" /> | ||
</c-card> | ||
<c-card title="Items in List 2 but not in List 1" mb-2> | ||
<textarea-copyable :value="compareResult.list2Not1" /> | ||
</c-card> | ||
</div> | ||
</div> | ||
</template> |