fix(text-statistics): empty text mean 0 words and 0 lines

This commit is contained in:
Corentin Thomasset 2022-07-23 19:09:22 +02:00
parent 394d085846
commit 92ce419f45
No known key found for this signature in database
GPG key ID: DBD997E935996158

View file

@ -5,19 +5,17 @@
<br />
<n-space justify="space-around">
<n-statistic label="Character count" :value="text.length" />
<n-statistic label="Word count" :value="text.split(/\s+/).length" />
<n-statistic label="Line count" :value="text.split(/\r\n|\r|\n/).length" />
<n-statistic label="Word count" :value="text === '' ? 0 : text.split(/\s+/).length" />
<n-statistic label="Line count" :value="text === '' ? 0 : text.split(/\r\n|\r|\n/).length" />
<n-statistic label="Byte size" :value="formatBytes(getStringSizeInBytes(text))" />
</n-space>
</n-card>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { formatBytes } from '@/utils/convert';
import { ref } from 'vue';
import { getStringSizeInBytes } from './text-statistics.service';
const text = ref(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Commodo risus faucibus varius volutpat habitasse suspendisse justo inceptos primis mi. Fusce molestie lorem bibendum habitasse litora adipiscing turpis egestas quis nec. Non id conubia vulputate etiam iaculis vitae venenatis hac fusce condimentum. Adipiscing pellentesque venenatis ornare pulvinar tempus hac montes velit erat convallis.',
);
const text = ref('');
</script>