feat(new tool): Duplicate Lines Finder

This commit is contained in:
ShareVB committed 2025-04-21 22:08:21 +02:00
1 parent 795f713f5c
commit 74f3ab41bd
2 files changed
+69

No files matched your search

@@ -0,0 +1,56 @@
<script setup lang="ts">
import _ from 'lodash';
import { useQueryParamOrStorage } from '@/composable/queryParams';
import { useValidation } from '@/composable/validation';
const input = ref('');
const cleaningRegex = useQueryParamOrStorage({ name: 'clean', storageName: 'dedup:clean', defaultValue: '' });
const regexValidation = useValidation({
source: cleaningRegex,
rules: [
{
message: 'Invalid regex: {0}',
validator: value => new RegExp(value),
getErrorMessage: (value) => {
const _ = new RegExp(value);
return '';
},
},
],
});
const duplicatedLines = computed(() => {
const clean = new RegExp(cleaningRegex.value, 'g');
const lines = input.value.split('\n');
return _.uniq(_.filter(lines.map(val => val.replace(clean, '')), (val, i, iteratee) => val && _.includes(iteratee, val, i + 1))).join('\n');
});
</script>
<template>
<div>
<c-input-text
v-model:value="input"
placeholder="Your string to list duplicated lines..."
raw-text
multiline
rows="10"
label="Your text: "
mb-2
/>
<c-input-text
v-model:value="cleaningRegex"
placeholder="Your cleaning regex..."
raw-text
label="Cleaning regex: "
label-position="left"
label-align="right"
label-width="120px"
:validation="regexValidation"
mb-2
/>
<n-form-item label="Duplicated lines:">
<textarea-copyable :value="duplicatedLines" />
</n-form-item>
</div>
</template>
+13
View File
@@ -0,0 +1,13 @@
import { ListSearch } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Duplicate Lines Finder',
path: '/duplicate-line-finder',
description: 'Find and list duplicated lines',
keywords: ['duplicate', 'line', 'finder'],
component: () => import('./duplicate-line-finder.vue'),
icon: ListSearch,
createdAt: new Date('2025-03-09'),
category: 'Text',
});