mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-22 22:02:38 +03:00
feat(new tool): Distinct Words Counter
This commit is contained in:
1 parent
9c925ac711
commit
2593df0ef5
2 files changed
+48
No files matched your search
@@ -0,0 +1,35 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
import { computed, ref } from 'vue';
|
||||||
|
import { countBy, orderBy } from 'lodash';
|
||||||
|
|
||||||
|
const inputText = ref('');
|
||||||
|
const sortedWordCounts = computed(() => {
|
||||||
|
// Remove punctuation, extract words, count occurrences
|
||||||
|
const cleanedText = inputText.value.replace(/\p{P}+\s|\s\p{P}+|\p{P}+$|^\p{P}+|\s+/gu, ' ').trim(); // Remove punctuation
|
||||||
|
const wordCountObj = countBy(cleanedText.split(' ') || []);
|
||||||
|
|
||||||
|
// Convert to array and sort by count descending
|
||||||
|
return orderBy(Object.entries(wordCountObj), ([, count]) => count, 'desc');
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<c-input-text v-model:value="inputText" multiline rows="10" label="Text:" placeholder="Enter text..." mb-1 />
|
||||||
|
<c-card title="Distinct words">
|
||||||
|
<n-table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Word</th>
|
||||||
|
<th>Count</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr v-for="([word, count]) in sortedWordCounts" :key="word">
|
||||||
|
<td>{{ word }}</td><td>{{ count }}</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</n-table>
|
||||||
|
</c-card>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import { FileText } from '@vicons/tabler';
|
||||||
|
import { defineTool } from '../tool';
|
||||||
|
|
||||||
|
export const tool = defineTool({
|
||||||
|
name: 'Distinct Words',
|
||||||
|
path: '/distinct-words',
|
||||||
|
description: 'Extract and count occurences of each unique word in a text',
|
||||||
|
keywords: ['distinct', 'words'],
|
||||||
|
component: () => import('./distinct-words.vue'),
|
||||||
|
icon: FileText,
|
||||||
|
createdAt: new Date('2025-05-01'),
|
||||||
|
category: 'Text',
|
||||||
|
});
|
||||||
Reference in new issue
Block a user