feat(Text Statistics): add more stats

Sentences, Words with punctuations, Chars by type (upper, lower, digits, puncts...)
This commit is contained in:
ShareVB 2024-04-28 14:07:46 +02:00
parent 2d87aaf484
commit af1013da36
2 changed files with 23 additions and 7 deletions

View file

@ -1,19 +1,33 @@
<script setup lang="ts">
import { getStringSizeInBytes } from './text-statistics.service';
import { getStringSizeInBytes, textStatistics } from './text-statistics.service';
import { formatBytes } from '@/utils/convert';
const text = ref('');
const stats = computed(() => textStatistics(text.value));
</script>
<template>
<c-card>
<c-input-text v-model:value="text" multiline placeholder="Your text..." rows="5" />
<div mt-5 flex>
<n-statistic label="Character count" :value="text.length" flex-1 />
<n-statistic label="Word count" :value="text === '' ? 0 : text.split(/\s+/).length" flex-1 />
<n-statistic label="Line count" :value="text === '' ? 0 : text.split(/\r\n|\r|\n/).length" flex-1 />
<n-statistic label="Byte size" :value="formatBytes(getStringSizeInBytes(text))" flex-1 />
</div>
<n-space mt-3>
<n-statistic label="Character count" :value="stats.chars" />
<n-statistic label="Word count" :value="stats.words" />
<n-statistic label="Sentences count" :value="stats.sentences" />
<n-statistic label="Line count" :value="stats.lines" />
<n-statistic label="Byte size" :value="formatBytes(getStringSizeInBytes(text))" />
</n-space>
<n-divider />
<n-space>
<n-statistic label="Chars (no spaces)" :value="stats.chars_no_spaces" />
<n-statistic label="Uppercase chars" :value="stats.chars_upper" />
<n-statistic label="Lowercase chars" :value="stats.chars_lower" />
<n-statistic label="Digit chars" :value="stats.chars_digits" />
<n-statistic label="Punctuations" :value="stats.chars_puncts" />
<n-statistic label="Spaces chars" :value="stats.chars_spaces" />
<n-statistic label="Word count (no punct)" :value="stats.words_no_puncs" />
</n-space>
</c-card>
</template>