Module: utils

Methods

(static) createMd5Hash(data) → {string}

Convenient function to create md5 hash from string.

Parameters:
Name Type Description
data *
Source:
Returns:

md5 hash

Type
string

(static) hashHmac(algorithm, data, secret) → {string}

Equivalent to PHP's hash_hmac function.

Parameters:
Name Type Description
algorithm string

hashing algorithm

data *

data string to be hashed

secret Buffer

Secret key used to hash data, generated with pack method

Source:
Returns:

digested hash

Type
string

(static) pack(data, encoding) → {Buffer}

Equivalent to PHP's pack function, using Node native Buffer
Note: PHP

    pack('H*', data)
is equivalent to Node:
    Buffer.from(data, 'hex')
Parameters:
Name Type Description
data *
encoding *
Source:
Returns:

Buffer of data encoded with encoding method

Type
Buffer

(static) to2DigitNumber(number) → {string}

Convenient function to convert number to 2 digit number string

Parameters:
Name Type Description
number *
Source:
Returns:

formatted number

Type
string

(static) toUpperCase(s) → {string}

Global function to convert String to upper case, with type checking

Parameters:
Name Type Description
s string
Source:
Returns:

all upper case string

Type
string

(static) vnPayDateFormat(date) → {string}

Convenient function to convert date to format yyyyMMddHHmmss

Parameters:
Name Type Description
date Date

Date object that need to be formatted

Source:
Returns:

date string formatted in yyyyMMddHHmmss

Type
string