-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
53 additions
and
10 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
var makeString = require('./helper/makeString'); | ||
|
||
var from = "ąàáäâãåæăćčĉęèéëêĝĥìíïîĵłľńňòóöőôõðøśșšŝťțŭùúüűûñÿýçżźž", | ||
to = "aaaaaaaaaccceeeeeghiiiijllnnoooooooossssttuuuuuunyyczzz"; | ||
|
||
from += from.toUpperCase(); | ||
to += to.toUpperCase(); | ||
|
||
module.exports = function cleanDiacritics(str) { | ||
return makeString(str).replace(/.{1}/g, function(c){ | ||
var index = from.indexOf(c); | ||
return index === -1 ? c : to.charAt(index); | ||
}); | ||
}; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
var equal = require('assert').equal; | ||
var cleanDiacritics = require('../cleanDiacritics'); | ||
|
||
var from = "ąàáäâãåæăćčĉęèéëêĝĥìíïîĵłľńňòóöőôõðøśșšŝťțŭùúüűûñÿýçżźž", | ||
to = "aaaaaaaaaccceeeeeghiiiijllnnoooooooossssttuuuuuunyyczzz"; | ||
|
||
test('#cleanDiacritics', function() { | ||
|
||
equal(cleanDiacritics(from), to); | ||
equal(cleanDiacritics(from.toUpperCase()), to.toUpperCase()); | ||
|
||
|
||
equal(cleanDiacritics('ä'), 'a'); | ||
equal(cleanDiacritics('Ä Ø'), 'A O'); | ||
equal(cleanDiacritics('1 foo ääkkönen'), '1 foo aakkonen'); | ||
equal(cleanDiacritics('Äöö ÖÖ'), 'Aoo OO'); | ||
equal(cleanDiacritics(' ä '), ' a '); | ||
equal(cleanDiacritics('- " , £ $ ä'), '- " , £ $ a'); | ||
}); | ||
|