Skip to content
This repository was archived by the owner on Feb 20, 2019. It is now read-only.

Commit 700a007

Browse files
MauricioRobayoKent C. Dodds
authored and
Kent C. Dodds
committed
feat(removeAccents): add removeAccents functions with test (#163)
Implements method to remove accentuated characters from a string. Based on: https://stackoverflow.com/a/37511463/2002514 Closes #161
1 parent ec3881e commit 700a007

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import timeDifference from './timeDifference'
5555
import isPrime from './is-prime'
5656
import swapElements from './swapElements'
5757
import reverse from './reverse'
58+
import removeAccents from './remove-accents'
5859

5960
export {
6061
isOdd,
@@ -114,4 +115,5 @@ export {
114115
isPrime,
115116
swapElements,
116117
reverse,
118+
removeAccents,
117119
}

src/remove-accents.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export default removeAccents
2+
3+
/**
4+
* Original Source: https://stackoverflow.com/a/37511463/2002514
5+
*
6+
* This method will remove accentuated characters from a string.
7+
*
8+
* @param {String} str - The string to remove accentuated characters from.
9+
* @return {String} - The given string without accentuated characters.
10+
*/
11+
function removeAccents(str) {
12+
return str.normalize('NFD').replace(/[\u0300-\u036f]/g, '')
13+
}

test/remove-accents.test.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import test from 'ava'
2+
import {removeAccents} from '../src'
3+
4+
test('remove accentuated characters', t => {
5+
const original = 'Español: Comí Crème Brulée el sábado'
6+
const expected = 'Espanol: Comi Creme Brulee el sabado'
7+
const actual = removeAccents(original)
8+
t.deepEqual(actual, expected)
9+
})

0 commit comments

Comments
 (0)