Skip to content

Instantly share code, notes, and snippets.

@iArnaud
Forked from denneulin/tips.js
Created March 14, 2019 12:56
Show Gist options
  • Save iArnaud/b38f3b8a150102977f789432cc1a7653 to your computer and use it in GitHub Desktop.
Save iArnaud/b38f3b8a150102977f789432cc1a7653 to your computer and use it in GitHub Desktop.
Tips
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, '_');
// result = 1dej_a42uMacee_vu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment