Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/remove letter accents #387

Merged
merged 5 commits into from
Nov 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/core/config/Categories.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
"ops": [
"Encode text",
"Decode text",
"Remove Letter Accents",
"Unescape Unicode Characters"
]
},
Expand Down
42 changes: 42 additions & 0 deletions src/core/operations/RemoveLetterAccents.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @author Klaxon [klaxon@veyr.com]
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/

import Operation from "../Operation";

/**
* Remove Letter Accents operation
*/
class RemoveLetterAccents extends Operation {

/**
* RemoveLetterAccents constructor
*/
constructor() {
super();

this.name = "Remove Letter Accents";
this.module = "Default";
this.description = "Replaces accented characters with their latin character equivalent.";
this.infoURL = "";
this.inputType = "string";
this.outputType = "string";
this.args = [
];
}

/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
//reference: https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript/37511463
return input.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
}

}

export default RemoveLetterAccents;
1 change: 1 addition & 0 deletions test/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import "./tests/operations/ParseIPRange";
import "./tests/operations/PowerSet";
import "./tests/operations/Regex";
import "./tests/operations/Register";
import "./tests/operations/RemoveLetterAccents";
import "./tests/operations/Rotate";
import "./tests/operations/SeqUtils";
import "./tests/operations/SetDifference";
Expand Down
23 changes: 23 additions & 0 deletions test/tests/operations/RemoveLetterAccents.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

/**
* Remove Letter Accents tests.
*
* @author Klaxon [klaxon@veyr.com]
* @copyright Crown Copyright 2017
* @license Apache-2.0
*/
import TestRegister from "../../TestRegister";

TestRegister.addTests([
{
name: "Remove Letter Accents",
input: "\xe0, \xe8, \xec, \xf2, \xf9 \xc0, \xc8, \xcc, \xd2, \xd9\n\xe1, \xe9, \xed, \xf3, \xfa, \xfd \xc1, \xc9, \xcd, \xd3, \xda, \xdd\n\xe2, \xea, \xee, \xf4, \xfb \xc2, \xca, \xce, \xd4, \xdb\n\xe3, \xf1, \xf5 \xc3, \xd1, \xd5\n\xe4, \xeb, \xef, \xf6, \xfc, \xff \xc4, \xcb, \xcf, \xd6, \xdc, \u0178\n\xe5, \xc5",
expectedOutput: "a, e, i, o, u A, E, I, O, U\na, e, i, o, u, y A, E, I, O, U, Y\na, e, i, o, u A, E, I, O, U\na, n, o A, N, O\na, e, i, o, u, y A, E, I, O, U, Y\na, A",
recipeConfig: [
{
"op": "Remove Letter Accents",
"args": []
},
],
},
]);