From ac2466a304cf23d523c59b9da42b5f207176981a Mon Sep 17 00:00:00 2001 From: Klaxon Date: Wed, 3 Oct 2018 13:11:22 +1000 Subject: [PATCH 1/4] create operation from npm run newop --- src/core/config/Categories.json | 1 + src/core/operations/RemoveLetterAccents.mjs | 56 +++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 src/core/operations/RemoveLetterAccents.mjs diff --git a/src/core/config/Categories.json b/src/core/config/Categories.json index ca762f1d..83998739 100755 --- a/src/core/config/Categories.json +++ b/src/core/config/Categories.json @@ -166,6 +166,7 @@ "ops": [ "Encode text", "Decode text", + "Remove Letter Accents", "Unescape Unicode Characters" ] }, diff --git a/src/core/operations/RemoveLetterAccents.mjs b/src/core/operations/RemoveLetterAccents.mjs new file mode 100644 index 00000000..cb8cad55 --- /dev/null +++ b/src/core/operations/RemoveLetterAccents.mjs @@ -0,0 +1,56 @@ +/** + * @author Klaxon [klaxon@veyr.com] + * @copyright Crown Copyright 2018 + * @license Apache-2.0 + */ + +import Operation from "../Operation"; +import OperationError from "../errors/OperationError"; + +/** + * 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 = [ + /* Example arguments. See the project wiki for full details. + { + name: "First arg", + type: "string", + value: "Don't Panic" + }, + { + name: "Second arg", + type: "number", + value: 42 + } + */ + ]; + } + + /** + * @param {string} input + * @param {Object[]} args + * @returns {string} + */ + run(input, args) { + // const [firstArg, secondArg] = args; + + throw new OperationError("Test"); + } + +} + +export default RemoveLetterAccents; From 04ee2fb3e4a64c8a5d5b1f40f2880e72185ad5ee Mon Sep 17 00:00:00 2001 From: Klaxon Date: Wed, 3 Oct 2018 13:26:01 +1000 Subject: [PATCH 2/4] add function to replace accent chars with latin chars --- src/core/operations/RemoveLetterAccents.mjs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/core/operations/RemoveLetterAccents.mjs b/src/core/operations/RemoveLetterAccents.mjs index cb8cad55..b8abf02c 100644 --- a/src/core/operations/RemoveLetterAccents.mjs +++ b/src/core/operations/RemoveLetterAccents.mjs @@ -46,9 +46,8 @@ class RemoveLetterAccents extends Operation { * @returns {string} */ run(input, args) { - // const [firstArg, secondArg] = args; - - throw new OperationError("Test"); + return input.normalize("NFD").replace(/[\u0300-\u036f]/g, ""); + //reference: https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript/37511463 } } From 54793f2b7884ed072ee15d453eb0a2d5f0f0afea Mon Sep 17 00:00:00 2001 From: Klaxon Date: Thu, 11 Oct 2018 21:52:49 +1000 Subject: [PATCH 3/4] update operation --- src/core/operations/RemoveLetterAccents.mjs | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/core/operations/RemoveLetterAccents.mjs b/src/core/operations/RemoveLetterAccents.mjs index b8abf02c..a8fdb6e4 100644 --- a/src/core/operations/RemoveLetterAccents.mjs +++ b/src/core/operations/RemoveLetterAccents.mjs @@ -5,7 +5,6 @@ */ import Operation from "../Operation"; -import OperationError from "../errors/OperationError"; /** * Remove Letter Accents operation @@ -25,18 +24,6 @@ class RemoveLetterAccents extends Operation { this.inputType = "string"; this.outputType = "string"; this.args = [ - /* Example arguments. See the project wiki for full details. - { - name: "First arg", - type: "string", - value: "Don't Panic" - }, - { - name: "Second arg", - type: "number", - value: 42 - } - */ ]; } @@ -46,8 +33,8 @@ class RemoveLetterAccents extends Operation { * @returns {string} */ run(input, args) { - return input.normalize("NFD").replace(/[\u0300-\u036f]/g, ""); //reference: https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript/37511463 + return input.normalize("NFD").replace(/[\u0300-\u036f]/g, ""); } } From 3089c39369e4cc43e82ab1f99c647b4efce183df Mon Sep 17 00:00:00 2001 From: Klaxon Date: Thu, 11 Oct 2018 22:26:44 +1000 Subject: [PATCH 4/4] add test --- test/index.mjs | 1 + test/tests/operations/RemoveLetterAccents.mjs | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 test/tests/operations/RemoveLetterAccents.mjs diff --git a/test/index.mjs b/test/index.mjs index 9bb93a60..9517816f 100644 --- a/test/index.mjs +++ b/test/index.mjs @@ -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"; diff --git a/test/tests/operations/RemoveLetterAccents.mjs b/test/tests/operations/RemoveLetterAccents.mjs new file mode 100644 index 00000000..638cbea1 --- /dev/null +++ b/test/tests/operations/RemoveLetterAccents.mjs @@ -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": [] + }, + ], + }, +]);