Skip to content

Instantly share code, notes, and snippets.

@DesolatorMagno
Created May 13, 2020 01:54
Show Gist options
  • Save DesolatorMagno/0116229f853226e4d21f0935214159e7 to your computer and use it in GitHub Desktop.
Save DesolatorMagno/0116229f853226e4d21f0935214159e7 to your computer and use it in GitHub Desktop.
fetch(route,{
method: 'get'
}).then(function(response){
return response.text();
}).then(function(res){
console.log(res)
}).catch(function(err){
});
//Rendodea cualquiera numero a 1 o 2 decimales
function roundToTwo(num) {
return +(Math.round(num + "e+2") + "e-2");
}
function roundToOne(num) {
return +(Math.round(num + "e+1") + "e-1");
}
//Slugify a string
function slugify(string) {
const a = 'àáâäæãåāăąçćčđďèéêëēėęěğǵḧîïíīįìłḿñńǹňôöòóœøōõṕŕřßśšşșťțûüùúūǘůűųẃẍÿýžźż·/_,:;';
const b = 'aaaaaaaaaacccddeeeeeeeegghiiiiiilmnnnnooooooooprrsssssttuuuuuuuuuwxyyzzz------';
const p = new RegExp(a.split('').join('|'), 'g');
return string.toString()
.toLowerCase()
.replace(/\s+/g, "-")
.replace(p, c => b.charAt(a.indexOf(c)))
.replace(/&/g, '-and-')
.replace(/[^\w\-]+/g, '')
.replace(/\-\-+/g, '-')
.replace(/^-+/, '')
.replace(/-+$/, '');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment