Merge pull request #1260 from danielesreis/add/remove-accents

Add removeAccents
This commit is contained in:
Angelos Chalaris
2020-10-04 16:42:50 +03:00
committed by GitHub

17
snippets/removeAccents.md Normal file
View File

@ -0,0 +1,17 @@
---
title: removeAccents
tags: string,beginner
---
Removes accents from strings.
- Use `String.prototype.normalize()` to convert the string to a normalized Unicode format.
- Use `String.prototype.replace()` to replace diacritical marks in the given Unicode range by empty strings.
```js
const removeAccents = str => str.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
```
```js
removeAccents('Antoine de Saint-Exupéry'); // 'Antoine de Saint-Exupery'
```