Skip to content

Commit af1013d

Browse files
committed
feat(Text Statistics): add more stats
Sentences, Words with punctuations, Chars by type (upper, lower, digits, puncts...)
1 parent 2d87aaf commit af1013d

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

components.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ declare module '@vue/runtime-core' {
144144
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
145145
NMenu: typeof import('naive-ui')['NMenu']
146146
NScrollbar: typeof import('naive-ui')['NScrollbar']
147+
NSpace: typeof import('naive-ui')['NSpace']
147148
NSpin: typeof import('naive-ui')['NSpin']
149+
NStatistic: typeof import('naive-ui')['NStatistic']
148150
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
149151
OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default']
150152
PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default']
Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
<script setup lang="ts">
2-
import { getStringSizeInBytes } from './text-statistics.service';
2+
import { getStringSizeInBytes, textStatistics } from './text-statistics.service';
33
import { formatBytes } from '@/utils/convert';
44
55
const text = ref('');
6+
const stats = computed(() => textStatistics(text.value));
67
</script>
78

89
<template>
910
<c-card>
1011
<c-input-text v-model:value="text" multiline placeholder="Your text..." rows="5" />
1112

12-
<div mt-5 flex>
13-
<n-statistic label="Character count" :value="text.length" flex-1 />
14-
<n-statistic label="Word count" :value="text === '' ? 0 : text.split(/\s+/).length" flex-1 />
15-
<n-statistic label="Line count" :value="text === '' ? 0 : text.split(/\r\n|\r|\n/).length" flex-1 />
16-
<n-statistic label="Byte size" :value="formatBytes(getStringSizeInBytes(text))" flex-1 />
17-
</div>
13+
<n-space mt-3>
14+
<n-statistic label="Character count" :value="stats.chars" />
15+
<n-statistic label="Word count" :value="stats.words" />
16+
<n-statistic label="Sentences count" :value="stats.sentences" />
17+
<n-statistic label="Line count" :value="stats.lines" />
18+
<n-statistic label="Byte size" :value="formatBytes(getStringSizeInBytes(text))" />
19+
</n-space>
20+
21+
<n-divider />
22+
23+
<n-space>
24+
<n-statistic label="Chars (no spaces)" :value="stats.chars_no_spaces" />
25+
<n-statistic label="Uppercase chars" :value="stats.chars_upper" />
26+
<n-statistic label="Lowercase chars" :value="stats.chars_lower" />
27+
<n-statistic label="Digit chars" :value="stats.chars_digits" />
28+
<n-statistic label="Punctuations" :value="stats.chars_puncts" />
29+
<n-statistic label="Spaces chars" :value="stats.chars_spaces" />
30+
<n-statistic label="Word count (no punct)" :value="stats.words_no_puncs" />
31+
</n-space>
1832
</c-card>
1933
</template>

0 commit comments

Comments
 (0)