2018-05-06 13:18:41 +01: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" ;
import { DELIM _OPTIONS } from "../lib/Delim.mjs" ;
import { fromDecimal } from "../lib/Decimal.mjs" ;
2018-05-06 13:18:41 +01:00
/ * *
* From Decimal operation
* /
class FromDecimal extends Operation {
/ * *
* FromDecimal constructor
* /
constructor ( ) {
super ( ) ;
this . name = "From Decimal" ;
this . module = "Default" ;
this . description = "Converts the data from an ordinal integer array back into its raw form.<br><br>e.g. <code>72 101 108 108 111</code> becomes <code>Hello</code>" ;
this . inputType = "string" ;
this . outputType = "byteArray" ;
this . args = [
{
"name" : "Delimiter" ,
"type" : "option" ,
"value" : DELIM _OPTIONS
2018-10-12 10:00:09 +02:00
} ,
{
2018-11-07 14:39:33 +00:00
"name" : "Support signed values" ,
2018-10-12 10:00:09 +02:00
"type" : "boolean" ,
"value" : false
2018-05-06 13:18:41 +01:00
}
] ;
2020-03-24 11:06:37 +00:00
this . checks = [
{
pattern : "^(?:\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5])(?: (?:\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5]))*$" ,
flags : "" ,
args : [ "Space" , false ]
} ,
{
pattern : "^(?:\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5])(?:,(?:\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5]))*$" ,
flags : "" ,
args : [ "Comma" , false ]
} ,
{
pattern : "^(?:\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5])(?:;(?:\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5]))*$" ,
flags : "" ,
args : [ "Semi-colon" , false ]
} ,
{
pattern : "^(?:\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5])(?::(?:\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5]))*$" ,
flags : "" ,
args : [ "Colon" , false ]
} ,
{
pattern : "^(?:\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5])(?:\\n(?:\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5]))*$" ,
flags : "" ,
args : [ "Line feed" , false ]
} ,
{
pattern : "^(?:\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5])(?:\\r\\n(?:\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5]))*$" ,
flags : "" ,
args : [ "CRLF" , false ]
2020-02-25 11:27:03 +00:00
}
2020-03-24 11:06:37 +00:00
] ;
2018-05-06 13:18:41 +01:00
}
/ * *
* @ param { string } input
* @ param { Object [ ] } args
* @ returns { byteArray }
* /
run ( input , args ) {
2018-10-12 10:00:09 +02:00
let data = fromDecimal ( input , args [ 0 ] ) ;
if ( args [ 1 ] ) { // Convert negatives
data = data . map ( v => v < 0 ? 0xFF + v + 1 : v ) ;
}
return data ;
2018-05-06 13:18:41 +01:00
}
}
export default FromDecimal ;