From 7d7aebde6e5ff1aeb221bc1b94adba4663880954 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sat, 3 Apr 2021 18:29:35 -0300 Subject: /home/andreh/dev/libre/dotfiles/scripts/pastebin.sh: Auto-add _pastebins/2021-04-03-javascript-naive-slugify.md --- _pastebins/2021-04-03-javascript-naive-slugify.md | 39 +++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 _pastebins/2021-04-03-javascript-naive-slugify.md (limited to '_pastebins/2021-04-03-javascript-naive-slugify.md') diff --git a/_pastebins/2021-04-03-javascript-naive-slugify.md b/_pastebins/2021-04-03-javascript-naive-slugify.md new file mode 100644 index 0000000..05251c7 --- /dev/null +++ b/_pastebins/2021-04-03-javascript-naive-slugify.md @@ -0,0 +1,39 @@ +--- + +title: JavaScript naive slugify + +date: 2021-04-03 + +layout: post + +lang: en + +ref: javascript-naive-slugify + +--- + +```javascript +const s = "Pézão: açaí, saci-pererê."; + +function slugify(s) { + return s + .toLowerCase() + .replaceAll(":", "") + .replaceAll(".", "") + .replaceAll(",", "") + .replaceAll("-", "") + .replaceAll("á", "a") + .replaceAll("ã", "a") + .replaceAll("à", "a") + .replaceAll("é", "e") + .replaceAll("ê", "e") + .replaceAll("í", "i") + .replaceAll("ó", "o") + .replaceAll("ô", "o") + .replaceAll("ú", "u") + .replaceAll("ü", "u") + .replaceAll("ç", "c"); +} + +console.log(slugify(s)); +``` -- cgit v1.2.3