util

parasql. Namespace

util

Miscellaneous utility functions.

Description:
  • Miscellaneous utility functions.

Methods

(static) formatDate(num, fmtStr) → {string}

The fmtStr parameter may include the following characters:

YYYY - four digit year
YY - two digit year
MM - two digit month (with leading zero as needed)
DD - two digit day (with leading zero as needed)
 
HH - two digit hours - 24 hour format
hh - two digit hours - 12 hour format
AM - two letters - either AM or PM
mm - two digit minutes
ss - two digit seconds
ms - three digit milliseconds - 000 to 999
 
DOW - three letter day of week - e.g.

Description:
  • The fmtStr parameter may include the following characters:

    YYYY - four digit year
    YY - two digit year
    MM - two digit month (with leading zero as needed)
    DD - two digit day (with leading zero as needed)
     
    HH - two digit hours - 24 hour format
    hh - two digit hours - 12 hour format
    AM - two letters - either AM or PM
    mm - two digit minutes
    ss - two digit seconds
    ms - three digit milliseconds - 000 to 999
     
    DOW - three letter day of week - e.g. Sun, Mon
    MONTH - long month name - e.g. January, February
    
Example
parasql.util.formatDate(@value(MyTable.MyDateField), 'YYYY/MM/DD')
Parameters:
Name Type Description
num number

A number representing the primitive value of a Date object e.g. new Date().valueOf()

fmtStr string

A date format string

Returns:

The date formatted into a string as specified by fmtStr

Type
string

(static) formatNumber(num, fmtStr) → {string}

Parameters:
Name Type Description
num number
fmtStr string

A valid format string

Returns:

The number formatted into a string as specified by fmtStr

Type
string

(static) formatPhoneNumber(charFieldWidget)

This function can be used to reformat user entered phone numbers into a consistent style for North America.

Description:
  • This function can be used to reformat user entered phone numbers into a consistent style for North America. Phone numbers will be reformatted into ###-###-#### and extensions (if any) will be appended in the style x###. International phone numbers starting with a '+' symbol will not be reformatted.

Since:
  • v147
Example
// example of a 'change' event on a character field used to store phone numbers
function (event) {
   parasql.util.formatPhoneNumber(event.target);
}
Parameters:
Name Type Description
charFieldWidget parasql.widget.TextFieldWidget

A field containing a phone number to be formatted

(static) getMachineId() → {string}

Returns a pseudo machine id that should be stable across a given browser/machine combination.

Description:
  • Returns a pseudo machine id that should be stable across a given browser/machine combination.

Since:
  • v124
Returns:

A 36 character string in UUID format.

Type
string

(static) newRandomKeyAsHex(lengthInBits) → {string}

Uses strong crypto to generate a new random key represented in Hex string format.

Description:
  • Uses strong crypto to generate a new random key represented in Hex string format. 128 bits yields 32 chars, 256 bits yields 64 chars.

Since:
  • v78
Parameters:
Name Type Description
lengthInBits number

The length of the key in bits.

Returns:

Returns the new random key as a hex string.

Type
string

(static) newRandomUUID() → {string}

Generates a new random UUID.

Description:
  • Generates a new random UUID. The UUID is RFC4122 v4 compliant and uses a cryptographically secure random number generator.

Returns:

A new random UUID as a 36 character string.

Type
string

(static) round(num, decimalPlacesopt) → {number}

Rounds positive and negative numbers correctly to the specified number of decimal places.

Description:
  • Rounds positive and negative numbers correctly to the specified number of decimal places.

Since:
  • v122
Parameters:
Name Type Attributes Default Description
num number

The number to round.

decimalPlaces number <optional>
0

The number of decimal places to round to.

Returns:
Type
number