appticles/mo-lunfardo/lunfardo.js

58 lines
1.5 KiB
JavaScript
Raw Normal View History

2022-10-19 14:05:11 -03:00
// Runs at https://minimo.io/diccionario-de-lunfardo-2020062059/, loaded via jsdelivr (fetched from Github)
// @minimo-io
2022-10-19 14:00:54 -03:00
const App = Vue.createApp({
data(){
return {
placeholder: 'Buscá che...',
searchQuery: '',
2022-10-20 19:10:23 -03:00
noResults: false,
2022-10-19 14:50:31 -03:00
wordsJson: []
2022-10-19 14:00:54 -03:00
}
},
methods:{
matches(obj) {
const term = this.searchQuery.toLowerCase();
2022-10-19 17:31:31 -03:00
//return obj.t.toLowerCase().includes(term) || obj.d.toLowerCase().includes(term);
// search only on terms not descriptions for it not to be so messy
return obj.t.toLowerCase().includes(term);
2022-10-19 14:00:54 -03:00
}
},
2022-10-19 14:22:46 -03:00
async mounted(){
2022-10-20 19:38:29 -03:00
const res = await fetch("https://cdn.jsdelivr.net/gh/minimo-io/appticles@v0.0.2-5/mo-lunfardo/data/lunfardo-dict-es.json");
2022-10-19 17:31:31 -03:00
// const res = await fetch("tools/dicc.json");
// const res = await fetch("data/lunfardo-dict-es.json");
2022-10-19 14:22:46 -03:00
this.wordsJson = await res.json();
2022-10-19 14:00:54 -03:00
},
computed:{
listValues() {
return Object.values(this.wordsJson);
},
countWords(){
return Object.keys(this.wordsJson).length;
},
filteredList() {
if (!this.searchQuery) {
2022-10-19 14:50:31 -03:00
//return this.listValues.slice(0, 10);
2022-10-19 15:02:20 -03:00
return this.listValues.slice(0, 50);
2022-10-19 14:00:54 -03:00
}
2022-10-20 19:10:23 -03:00
var filteredValues = this.listValues
.map((v) => {
if (this.matches(v)) {
return v;
}
})
.filter((v) => v);
if (filteredValues.length <= 0) this.noResults = true;
return filteredValues;
2022-10-19 14:00:54 -03:00
}
},
}).mount("#app");