This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const _ = require('lodash'); | |
const str = '1dé@#j. à$42^ù`=:/+%M£¨-)àç!Їжакè§("^é& vu'; | |
// exclude all special characters and spaces in a string | |
const result = _.deburr(str).replace(/\W/g, ''); | |
// result = 1deja42uMaceevu | |
// exclude all special characters and replaces spaces by underscore in a string | |
// N spaces side by side = 1 underscore | |
const result = _.deburr(str).replace(/[^\w\s]/g, '').trim().replace(/\s+/g, '_'); |