Slugify a text, removing/replacing all special characters and spaces with dashes '-'
@param {string} str - The string to sanitize
@return {string} The modified string
@example
slugifyText('Olá Mundo!'); // 'ola-mundo'
972928
function slugifyText(str) {
        str = str.replace(/^\s+|\s+$/g, '') // trim
        .toLowerCase().replace(/\./g, '-') // Replace a dot for a -
        .replace(/\*/g, '-') // Replace a * for a -
        .replace(/\+/g, '-'); // Replace a + for a -

        // Remove accents, swap ñ for n, etc
        var from = 'àáäâãèéëêìíïîòóöôõùúüûýÿñç·/_,:;';
        var to = 'aaaaaeeeeiiiiooooouuuuyync------';

        for (var i = 0, len = from.length; i < len; i += 1) {
            str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
        }

        str = str.replace(/[^a-z0-9 -]/g, '') // Remove invalid chars
        .replace(/\s+/g, '-') // Collapse whitespace and replace by -
        .replace(/-+/g, '-'); // Collapse dashes

        if (str.charAt(0) === '-') str = str.substr(1);
        if (str.charAt(str.length - 1) === '-') str = str.substr(0, str.length - 1);

        return str;
    }
748767
function slugify(string) {
    return _.deburr(string).trim().toLowerCase().replace(/ /g, '-').replace(/([^a-zA-Z0-9\._-]+)/, '');
}
1338972
public static function slug(string $str, string $delimiter = '-') : string
    {
        $str = static::toAscii($str);

        // Remove all characters that are neither alphanumeric, nor the separator nor a whitespace.
        $str = preg_replace('![^'.preg_quote($delimiter).'\pL\pN\s]+!u', '', mb_strtolower($str));

        // Standardize the separator.
        $flip = $delimiter == '-' ? '_' : '-';
        $str = preg_replace('!['.preg_quote($flip).']+!u', $delimiter, $str);

        // Replace all separator characters and whitespace by a single separator.
        $str = preg_replace('!['.preg_quote($delimiter).'\s]+!u', $delimiter, $str);

        return trim($str, $delimiter);
    }
1010058
function cleanCode(str) {
  str = str
    .replace(/\r\n|[\r\n\u2028\u2029]/g, '\n') // unify linebreaks
    .replace(/^\uFEFF/, ''); // replace zero-width no-break space

  str = stripFnStart(str) // replace function declaration
    .replace(/\)\s*\)\s*$/, ')') // replace closing paren
    .replace(/\s*};?\s*$/, ''); // replace closing bracket

  // Preserve indentation by finding leading tabs/spaces
  // and removing that amount of space from each line
  const spaces = str.match(/^\n?( *)/)[1].length;
  const tabs = str.match(/^\n?(\t*)/)[1].length;
  /* istanbul ignore next */
  const indentRegex = new RegExp(`^\n?${tabs ? '\t' : ' '}{${tabs || spaces}}`, 'gm');

  str = str.replace(indentRegex, '').trim();
  return str;
}
1276812
function trim( str, chr ){
	if ( !chr ){
		chr = '\\s';
	}
	return str.replace( new RegExp('^'+chr+'+|'+chr+'+$','g'), '' );
}
577846
function (str) {
                if (!str) {
                    return str;
                }
                return String(str).replace(/[\uff-\uffff]/g, function (c) {
                    return escape(c).replace('%', '\\');
                });
            }
2802
public static function makeSafe($str, $strict = false, $extrachars = '')
    {
        $str = str_replace('&amp;', '', $str);

        $delim = '/';
        if ($extrachars != '') {
            $extrachars = preg_quote($extrachars, $delim);
        }
        if ($strict) {
            $slugify = Slugify::create([
                'regexp' => '/[^a-z0-9_' . $extrachars . ' -]+/'
            ]);
            $str = $slugify->slugify($str, '');
            $str = str_replace(' ', '-', $str);
        } else {
            // Allow Uppercase and don't convert spaces to dashes
            $slugify = Slugify::create([
                'regexp' => '/[^a-zA-Z0-9_.,' . $extrachars . ' -]+/',
                'lowercase' => false
            ]);
            $str = $slugify->slugify($str, '');
        }

        return $str;
    }
347374
function normalizeText(str) {
        var _this = this;

        var re = /(^|[.!?]\s+)([a-z])/g;
        var normalize = function normalize(str) {
            return str.toLowerCase().replace(re, function (m, $1, $2) {
                return $1 + $2.toUpperCase();
            });
        };
        var addSpace = function addSpace(str) {
            return _this.strCompact(str.replace(/[,.!?:;]+(?=\S)/g, '$& '));
        };

        return normalize(addSpace(str));
    }
361677
function slugify()
    {
        $text = (string) $this;

        // replace non letter or digits by -
        $text = preg_replace('~[^\pL\d]+~u', '-', $text);

        // transliterate
        $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);

        // remove unwanted characters
        $text = preg_replace('~[^-\w]+~', '', $text);

        // trim
        $text = trim($text, '-');

        // remove duplicate -
        $text = preg_replace('~-+~', '-', $text);

        // lowercase
        $text = strtolower($text);

        if (empty($text))
            return 'n-a';

        return new self($text);
    }
22064
function slugify(str) {
  return str
    .replace(/[ÀÁÂÃÄÅàáâãäåæÆ]/g, 'a')
    .replace(/[çÇ]/g, 'c')
    .replace(/[ðÐ]/g, 'd')
    .replace(/[ÈÉÊËéèêë]/g, 'e')
    .replace(/[ÏïÎîÍíÌì]/g, 'i')
    .replace(/[Ññ]/g, 'n')
    .replace(/[øØœŒÕõÔôÓóÒò]/g, 'o')
    .replace(/[ÜüÛûÚúÙù]/g, 'u')
    .replace(/[ŸÿÝý]/g, 'y')
    .replace(/[^a-z0-9- ]/gi, '')
    .replace(/ /gi, '-')
    .toLowerCase();
}
26607
def slugify(text, length_limit=0, delimiter=u'-'):
    """"""
    result = []
    for word in _punctuation_regex.split(text.lower()):
        word = _available_unicode_handlers[0](word)
        if word:
            result.append(word)
    slug = delimiter.join(result)
    if length_limit > 0:
        return slug[0:length_limit]
    return slug
463155
function(str) {
    return trim(str).replace(/([\r\n\s　])+/g, function(match, whitespace) {
      return whitespace === '　' ? whitespace : ' ';
    });
  }
918575
public static function sanitizeJsVarName($str)
    {
        $out = preg_replace("/ /", '_', trim($str));
        $out = preg_replace("/[^A-Za-z_]/", '', $out);

        return $out;
    }
1285603
function(text) {
        return text.replace(/"([^"]|"")*"/g, function(value) {
            return value.replace(LF, CUSTOM_LF_SUBCHAR)
                .replace(CR, CUSTOM_CR_SUBCHAR);
        });
    }
182238
public static function slugify($text)
    {
        // replace non letter or digits by -
        $text = preg_replace('#[^\\pL\d]+#u', '-', $text);

        // trim
        $text = trim($text, '-');

        // transliterate
        if (function_exists('iconv')) {
            $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
        }

        // lowercase
        $text = mb_strtolower($text);

        // remove unwanted characters
        $text = preg_replace('#[^-\w]+#', '', $text);

        if (empty($text)) {
            return 'n-a';
        }

        return $text;
    }
980899
def slugify(string):
    
    filtered_string = []
    if isinstance(string, str):
        string = unicode(string, 'utf-8')
    for i in unicodedata.normalize('NFKC', string):
        cat = unicodedata.category(i)[0]
        # filter out all the non letter and non number characters from the
        # input (L is letter and N is number)
        if cat in 'LN' or i in '-_':
            filtered_string.append(i)
        elif cat in 'Z':
            filtered_string.append(' ')
    return re.sub('\s+', '-', ''.join(filtered_string)).lower()
766538
function _remove_invisible_characters($str)
	{
		static $non_displayables;

		if ( ! isset($non_displayables))
		{
			// every control character except newline (dec 10), carriage return (dec 13), and horizontal tab (dec 09),
			$non_displayables = array(
										'/%0[0-8bcef]/',			// url encoded 00-08, 11, 12, 14, 15
										'/%1[0-9a-f]/',				// url encoded 16-31
										'/[\x00-\x08]/',			// 00-08
										'/\x0b/', '/\x0c/',			// 11, 12
										'/[\x0e-\x1f]/'				// 14-31
									);
		}

		do
		{
			$cleaned = $str;
			$str = preg_replace($non_displayables, '', $str);
		}
		while ($cleaned != $str);

		return $str;
	}