JSONtoStr

This commit is contained in:
n1073645 2020-04-06 16:06:48 +01:00
parent 4c3324aea1
commit 829c07b134
2 changed files with 48 additions and 0 deletions

View file

@ -354,6 +354,7 @@
"JavaScript Minify",
"JSON Beautify",
"JSON Minify",
"JSON Stringify",
"XML Beautify",
"XML Minify",
"SQL Beautify",

View file

@ -0,0 +1,47 @@
/**
* @author n1073645 [n1073645@gmail.com]
* @copyright Crown Copyright 2020
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
/**
* JSON Stringify operation
*/
class JSONStringify extends Operation {
/**
* JSONStringify constructor
*/
constructor() {
super();
this.name = "JSON Stringify";
this.module = "Default";
this.description = "The JSON.stringify() method converts a JavaScript object or value to a JSON string.";
this.infoURL = "https://w3schools.com/js/js_json_stringify.asp";
this.inputType = "string";
this.outputType = "string";
this.args = [];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
let result;
try {
result = JSON.parse(input);
} catch (err) {
throw new OperationError(err);
}
return JSON.stringify(result);
}
}
export default JSONStringify;