Add str sort lines tool
This commit is contained in:
parent
77780ec130
commit
932a8250b6
@ -31,6 +31,7 @@ export default {
|
||||
'Strings': {
|
||||
'fix_ru_en_keyboard': 'Fix ru-en keyboard',
|
||||
'str_length': 'Str length',
|
||||
'str_sort_lines': 'Str sort lines',
|
||||
'str_to_lower_upper': 'Str to lower/upper',
|
||||
'str_remove_duplicate_lines': 'Str remove duplicate lines',
|
||||
},
|
||||
|
@ -20,6 +20,11 @@ const router = createRouter({
|
||||
name: 'str_length',
|
||||
component: () => import('../views/StrLength.vue'),
|
||||
},
|
||||
{
|
||||
path: '/str_sort_lines',
|
||||
name: 'str_sort_lines',
|
||||
component: () => import('../views/StrSortLines.vue'),
|
||||
},
|
||||
{
|
||||
path: '/str_to_lower_upper',
|
||||
name: 'str_to_lower_upper',
|
||||
|
84
src/views/StrSortLines.vue
Normal file
84
src/views/StrSortLines.vue
Normal file
@ -0,0 +1,84 @@
|
||||
<template>
|
||||
<h2 class="tool-title">Str sort lines</h2>
|
||||
<hr class="mt-5 mb-5">
|
||||
|
||||
<div class="input-group">
|
||||
<label for="data">Data</label>
|
||||
<textarea id="data" v-model="toolData.data" style="height: 150px"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<label>Mode</label>
|
||||
|
||||
<div>
|
||||
<input id="sort_mode_alpha" value="alpha" name="sort_mode" v-model="toolData.sortMode" type="radio"> <label for="sort_mode_alpha">alphabetically</label><br>
|
||||
<input id="sort_mode_numerically" value="numerically" name="sort_mode" v-model="toolData.sortMode" type="radio"> <label for="sort_mode_numerically">numerically</label><br>
|
||||
<input id="sort_mode_by_length" value="by_length" name="sort_mode" v-model="toolData.sortMode" type="radio"> <label for="sort_mode_by_length">by length</label><br>
|
||||
<input id="sort_mode_random" value="random" name="sort_mode" v-model="toolData.sortMode" type="radio"> <label for="sort_mode_random">random</label><br>
|
||||
<br>
|
||||
<input id="sort_mode_reverse" value="random" name="sort_mode_reverse" v-model="toolData.sortModeReverse" type="checkbox"> <label for="sort_mode_reverse">reverse</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="mt-5 mb-5">
|
||||
|
||||
<div class="input-group">
|
||||
<label for="result">Result</label>
|
||||
<textarea id="result" v-model="toolResult" style="height: 150px"></textarea>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
toolData: {
|
||||
data: '',
|
||||
sortMode: 'alpha',
|
||||
sortModeReverse: false,
|
||||
},
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
toolResult() {
|
||||
let result = []
|
||||
const data = this.toolData.data.split('\n');
|
||||
|
||||
switch (this.toolData.sortMode) {
|
||||
case 'alpha':
|
||||
result = data.sort(function(a, b) {
|
||||
return a.localeCompare(b);
|
||||
});
|
||||
break;
|
||||
case 'numerically':
|
||||
const collator = new Intl.Collator([], {numeric: true});
|
||||
|
||||
result = data.sort(function(a, b) {
|
||||
return collator.compare(a, b);
|
||||
});
|
||||
break;
|
||||
case 'by_length':
|
||||
result = data.sort(function(a, b) {
|
||||
return a.length - b.length;
|
||||
});
|
||||
break;
|
||||
case 'random':
|
||||
result = data.sort(function(a, b) {
|
||||
return Math.random() - .5;
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
if (this.toolData.sortModeReverse) {
|
||||
result = result.reverse();
|
||||
}
|
||||
|
||||
return result.join('\n');
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
|
||||
</style>
|
Loading…
x
Reference in New Issue
Block a user