Improve str length tool

This commit is contained in:
Illya Marchenko 2023-12-14 20:39:52 +02:00
parent 02bc94d10c
commit 6bf9e60c60
Signed by: stuzer05
GPG Key ID: A6ABAAA9268F9F4F

@ -7,13 +7,18 @@
<textarea id="data" v-model="toolData.data" style="height: 150px"></textarea> <textarea id="data" v-model="toolData.data" style="height: 150px"></textarea>
</div> </div>
<div class="input-group">
<label for="data_delimiter">Delimiter</label>
<input id="data_delimiter" v-model="toolData.dataDelimiter" placeholder="," type="text">
</div>
<div class="input-group"> <div class="input-group">
<label>Mode</label> <label>Mode</label>
<div> <div>
<input id="count_mode_characters" value="characters" name="count_mode" v-model="toolData.countMode" type="radio"> <label for="count_mode_characters">characters</label><br> <input id="count_mode_characters" value="characters" name="count_mode" v-model="toolData.countMode" :disabled="toolData.dataDelimiter.length" type="radio"> <label for="count_mode_characters">characters</label><br>
<input id="count_mode_words" value="words" name="count_mode" v-model="toolData.countMode" type="radio"> <label for="count_mode_words">words</label><br> <input id="count_mode_words" value="words" name="count_mode" v-model="toolData.countMode" :disabled="toolData.dataDelimiter.length" type="radio"> <label for="count_mode_words">words</label><br>
<input id="count_mode_lines" value="lines" name="count_mode" v-model="toolData.countMode" type="radio"> <label for="count_mode_lines">lines</label> <input id="count_mode_lines" value="lines" name="count_mode" v-model="toolData.countMode" :disabled="toolData.dataDelimiter.length" type="radio"> <label for="count_mode_lines">lines</label>
</div> </div>
</div> </div>
@ -31,19 +36,24 @@ export default {
return { return {
toolData: { toolData: {
data: '', data: '',
dataDelimiter: '',
countMode: 'characters', countMode: 'characters',
}, },
}; };
}, },
computed: { computed: {
toolResult() { toolResult() {
switch (this.toolData.countMode) { if (this.toolData.dataDelimiter.length) {
case 'characters': return this.toolData.data.split(this.toolData.dataDelimiter).length;
return this.toolData.data.length; } else {
case 'words': switch (this.toolData.countMode) {
return this.toolData.data.trim().split(/\s+/).length; case 'characters':
case 'lines': return this.toolData.data.length;
return this.toolData.data.split('\n').length; case 'words':
return this.toolData.data.trim().split(/\s+/).length;
case 'lines':
return this.toolData.data.split('\n').length;
}
} }
}, },
}, },