Improve str length tool
This commit is contained in:
parent
6bf9e60c60
commit
a9e52bfea8
@ -10,10 +10,6 @@
|
|||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<label for="data_delimiter">Delimiter</label>
|
<label for="data_delimiter">Delimiter</label>
|
||||||
<input id="data_delimiter" v-model="toolData.dataDelimiter" placeholder="," type="text">
|
<input id="data_delimiter" v-model="toolData.dataDelimiter" placeholder="," type="text">
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="input-group">
|
|
||||||
<label>Mode</label>
|
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<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_characters" value="characters" name="count_mode" v-model="toolData.countMode" :disabled="toolData.dataDelimiter.length" type="radio"> <label for="count_mode_characters">characters</label><br>
|
||||||
@ -43,17 +39,21 @@ export default {
|
|||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
toolResult() {
|
toolResult() {
|
||||||
|
if (!this.toolData.data.length) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.toolData.dataDelimiter.length) {
|
if (this.toolData.dataDelimiter.length) {
|
||||||
return this.toolData.data.split(this.toolData.dataDelimiter).length;
|
return this.toolData.data.split(this.toolData.dataDelimiter).length;
|
||||||
} else {
|
}
|
||||||
switch (this.toolData.countMode) {
|
|
||||||
case 'characters':
|
switch (this.toolData.countMode) {
|
||||||
return this.toolData.data.length;
|
case 'characters':
|
||||||
case 'words':
|
return this.toolData.data.length;
|
||||||
return this.toolData.data.trim().split(/\s+/).length;
|
case 'words':
|
||||||
case 'lines':
|
return this.toolData.data.trim().split(/\s+/).length;
|
||||||
return this.toolData.data.split('\n').length;
|
case 'lines':
|
||||||
}
|
return this.toolData.data.split('\n').length;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user