×

Please give details of the problem

Skip to content

Server-Side Javascript ES6 API Reference

RMPUtilities

Some useful Utilities

CSV To JSON

Converts an CSV input into JSON format.

Syntax : RMPUtilities.csvToJson(object, optionList);

Parameters :

Name Type Description
object String Input file
optionList Map Options to be used for defining the JSON parsing behavior

Returns : CSV in (JSON) String format.

Type : String

Call Example :

  
    <@script env="js">
      var result = RMPUtilities.csvToJson( '1,true,hello\n2,false,world', {});
      RMPData.setOutput(result);
    </@script>
   

JSON To CSV

Converts an array of either JSON objects or arrays to a CSV string. The contained JSON objects must only consist of simple types - no nested objects are allowed. Arrays also must only consist of simple types. The line end is CRLF.

Syntax : RMPUtilities.jsonToCsv(input, options);

Parameters :

Name Type Description
input Map User login/email. Current user by default
options Map Options to be used for defining the JSON parsing behavior

The "options" map can contain the following values (all optional):

Name Type Description
separator String Separator between two values (e.g. ; or ,). Default: ,
delimiter String Delimiter used to allow values containing the separator character (e.g. " or '), to include a delimiter in a value, use two delimiters (e.g. ""). Default: "
empty String Value to be used to represent an empty value (two separators in a row). Default: ""
charset String Character set to be used to read the file content. Default: UTF-8
parse_numbers Array Array of names or indices of columns containing numerical values to be stored as Double. Example: ["age",3] will parse columns header "age" and the 4th column
parse_longs Array Array of names or indices of columns containing long values to be stored as Long. Example: ["age",3] will parse column header "age" and the 4th column.
trim boolean Trim values before inserting them in the collection. Trimming also occurs before decoding numerical values.

Returns : The resulting CSV data as a string

Type : String

Call Example :

  
    <@script env="js">
      var result = RMPUtilities.jsonToCsv( [["1","true","hello"],["2","false","world"]], {});
      RMPData.setOutput(result);
    </@script>
   

Decrypt

Returns the decrypted version of the string provided in input. - This method can be used in a web interface.

Syntax :

  • RMPUtilities.decrypt(input, vector, keystring);
  • RMPUtilities.decrypt(input, vector, keystring, cipher);

Parameters :

Name Type Description
input String Encrypted text
vector String The initialization vector
keystring String Key to decrypt the ciphered text in AES format
cipher (optional) String Cipher

Returns : Decrypted String.

Type : String

Call Example :

  
    <@script env="js">
      var result = RMPUtilities.decrypt("HtcLaNk0xk/G+DjClefgdA==","LqME74+sChTIcYsaUMkBPw==","0ckdURPMf4P4ismngaFgZbX3CGzJCyuR6hTgEAL9RTc=");
      RMPData.setOutput(result);
    </@script>
   

Encrypt

Returns the encrypted version of the string provided in input. - This method can be used in a web interface.

Syntax :

  • RMPUtilities.encrypt(input, key);
  • RMPUtilities.encrypt(input, key, cipher);
  • Parameters :
Name Type Description
input String Input text to encrypt
key String A variable value to encrypt the text
cipher (optional) String Cipher

Returns : A result containing the initialization vector (iv field) and the encrypted version of input (encrypted field).

Type : Map

Data Structure :

  
    {"encrypted": "{Base64String}", "iv": "{Base64String}"}
   

Call Example :

  
    <@script env="js">
      var result = RMPUtilities.encrypt('hello world', 'c7ZOu5rr3fMHTOAAwwlFD049PBVAZ6SU8UJuU3A9lVM=');
      RMPData.setOutput(result);
    </@script>
   

RSA Hash

Generating RSA digital signature specifying the algorithm & encoding.

Syntax :

  • RMPUtilities.rsaHash(input, key);
  • RMPUtilities.rsaHash(input, key, algorithm);
  • RMPUtilities.rsaHash(input, key, algorithm, encoding);
  • Parameters :
Name Type Description
data String Data to be signed
key String The private key readers supports PEM files with PKCS#8 or PKCS#1 encodings. It doesn't support encrypted PEM files
algorithm (optional) String SHA256 (default), SHA1 or MD5. Default: SHA256
encoding (optional) String BASE64 (default), BASE64URL or HEXA. Default: BASE64

Returns : Data signed

Type : String

Call Example :

  
    <@script env="js">
      var key ='-----BEGIN RSA PRIVATE KEY-----\n' +

         '-----END RSA PRIVATE KEY-----';
      var j = RMPUtilities.rsaHash('hello world', key, 'SHA256', 'HEXA');
      RMPData.setOutput(j); 
    </@script>
   

UUID

Generate a universally unique identifier or UUID

Syntax : RMPUtilities.uuid();

Parameters : None

Returns : UUID value

Type : String

Call Example :

  
    <@script env="js">
      var result = RMPUtilities.uuid();  
      RMPData.setOutput(result);
    </@script>