“Convertir en slug javascript” Réponses codées

script java convertissant le texte en limace

function convertToSlug(Text)
{
    return Text
        .toLowerCase()
        .replace(/ /g,'-')
        .replace(/[^\w-]+/g,'')
        ;
}
Muddy Mockingbird

Créer des limaces en javascript

function makeSlug(slug){
  let finalSlug = slug.replace(/[^a-zA-Z0-9]/g, ' ');
  //remove multiple space to single
  finalSlug = slug.replace(/  +/g, ' ');
  // remove all white spaces single or multiple spaces
  finalSlug = slug.replace(/\s/g, '-').toLowerCase().replace(/[^\w-]+/g, '-');
  return finalSlug;
}

//example of work 
let slug = makeSlug('What Is a CSS Framework? (And When to Use 6 Popular Options)           ') 

console.log(slug) // what-is-a-css-framework---and-when-to-use-6-popular-options------------
Sharifur Robin

Convertir en slug javascript

    Method 1: 
    var slug = (req.body.package_name).toString().toLowerCase().replace(/\s+/g, '-').replace(/[^\u0100-\uFFFF\w\-]/g,'-').replace(/\-\-+/g, '-').replace(/^-+/, '').replace(/-+$/, '');
    console.log(slug);
    
    Text Tested : "What Is a CSS Framework? (And When to Use 6 Popular Options)           "
    Output : what-is-a-css-framework-and-when-to-use-6-popular-options
    
    Method 2 with function: 
   			 function slugify(text){
  			 return text.toString().toLowerCase()
    		.replace(/\s+/g, '-')           // Replace spaces with -
    		.replace(/[^\u0100-\uFFFF\w\-]/g,'-') // Remove all non-word chars ( fix for UTF-8 chars )
    		.replace(/\-\-+/g, '-')         // Replace multiple - with single -
    		.replace(/^-+/, '')             // Trim - from start of text
    		.replace(/-+$/, '');            // Trim - from end of text
									}
 var slug = slugify(Text);
console.log(slug);
Beautiful Buzzard

Réponses similaires à “Convertir en slug javascript”

Questions similaires à “Convertir en slug javascript”

Plus de réponses similaires à “Convertir en slug javascript” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code