2018-05-14 15:55:17 +00:00
/**
* @author n1474335 [n1474335@gmail.com]
* @copyright Crown Copyright 2016
* @license Apache-2.0
*/
2019-07-09 12:23:59 +01:00
import Operation from "../Operation.mjs" ;
2018-05-14 15:55:17 +00:00
/**
* Remove whitespace operation
*/
class RemoveWhitespace extends Operation {
/**
* RemoveWhitespace constructor
*/
constructor () {
super ();
this . name = "Remove whitespace" ;
this . module = "Default" ;
this . description = "Optionally removes all spaces, carriage returns, line feeds, tabs and form feeds from the input data.<br><br>This operation also supports the removal of full stops which are sometimes used to represent non-printable bytes in ASCII output." ;
this . inputType = "string" ;
this . outputType = "string" ;
this . args = [
{
"name" : "Spaces" ,
"type" : "boolean" ,
"value" : true
},
{
"name" : "Carriage returns (\\r)" ,
"type" : "boolean" ,
"value" : true
},
{
"name" : "Line feeds (\\n)" ,
"type" : "boolean" ,
"value" : true
},
{
"name" : "Tabs" ,
"type" : "boolean" ,
"value" : true
},
{
"name" : "Form feeds (\\f)" ,
"type" : "boolean" ,
"value" : true
},
{
"name" : "Full stops" ,
"type" : "boolean" ,
"value" : false
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run ( input , args ) {
const [
removeSpaces ,
2019-10-16 15:38:20 +01:00
removeCarriageReturns ,
2018-05-14 15:55:17 +00:00
removeLineFeeds ,
removeTabs ,
removeFormFeeds ,
removeFullStops
] = args ;
let data = input ;
if ( removeSpaces ) data = data . replace ( / /g , "" );
2019-10-16 15:38:20 +01:00
if ( removeCarriageReturns ) data = data . replace ( /\r/g , "" );
2018-05-14 15:55:17 +00:00
if ( removeLineFeeds ) data = data . replace ( /\n/g , "" );
if ( removeTabs ) data = data . replace ( /\t/g , "" );
if ( removeFormFeeds ) data = data . replace ( /\f/g , "" );
if ( removeFullStops ) data = data . replace ( /\./g , "" );
return data ;
}
}
export default RemoveWhitespace ;