UnicodeTextFormat.mjs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * @author Matt C [me@mitt.dev]
  3. * @copyright Crown Copyright 2020
  4. * @license Apache-2.0
  5. */
  6. import Operation from "../Operation.mjs";
  7. import Utils from "../Utils.mjs";
  8. /**
  9. * Unicode Text Format operation
  10. */
  11. class UnicodeTextFormat extends Operation {
  12. /**
  13. * UnicodeTextFormat constructor
  14. */
  15. constructor() {
  16. super();
  17. this.name = "Unicode Text Format";
  18. this.module = "Default";
  19. this.description = "Adds Unicode combining characters to change formatting of plaintext.";
  20. this.infoURL = "https://en.wikipedia.org/wiki/Combining_character";
  21. this.inputType = "byteArray";
  22. this.outputType = "byteArray";
  23. this.args = [
  24. {
  25. name: "Underline",
  26. type: "boolean",
  27. value: "false"
  28. },
  29. {
  30. name: "Strikethrough",
  31. type: "boolean",
  32. value: "false"
  33. }
  34. ];
  35. }
  36. /**
  37. * @param {byteArray} input
  38. * @param {Object[]} args
  39. * @returns {byteArray}
  40. */
  41. run(input, args) {
  42. const [underline, strikethrough] = args;
  43. let output = input.map(char => [char]);
  44. console.dir(output);
  45. if (strikethrough) {
  46. output = output.map(charFormat => {
  47. charFormat.push(...Utils.strToUtf8ByteArray("\u0336"));
  48. return charFormat;
  49. });
  50. }
  51. if (underline) {
  52. output = output.map(charFormat => {
  53. charFormat.push(...Utils.strToUtf8ByteArray("\u0332"));
  54. return charFormat;
  55. });
  56. }
  57. console.dir(output);
  58. return output.flat();
  59. }
  60. }
  61. export default UnicodeTextFormat;