JSONBeautify.mjs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * @author n1474335 [n1474335@gmail.com]
  3. * @copyright Crown Copyright 2016
  4. * @license Apache-2.0
  5. */
  6. import vkbeautify from "vkbeautify";
  7. import Operation from "../Operation";
  8. /**
  9. * JSON Beautify operation
  10. */
  11. class JSONBeautify extends Operation {
  12. /**
  13. * JSONBeautify constructor
  14. */
  15. constructor() {
  16. super();
  17. this.name = "JSON Beautify";
  18. this.module = "Code";
  19. this.description = "Indents and prettifies JavaScript Object Notation (JSON) code.";
  20. this.inputType = "string";
  21. this.outputType = "string";
  22. this.args = [
  23. {
  24. "name": "Indent string",
  25. "type": "binaryShortString",
  26. "value": "\\t"
  27. }
  28. ];
  29. }
  30. /**
  31. * @param {string} input
  32. * @param {Object[]} args
  33. * @returns {string}
  34. */
  35. run(input, args) {
  36. const indentStr = args[0];
  37. if (!input) return "";
  38. return vkbeautify.json(input, indentStr);
  39. }
  40. }
  41. export default JSONBeautify;