data_generation

Utilities for generating random or mock data.

data_generation

getRandomInt

Generates a random integer between min and max (inclusive).

getRandomInt(min: number, max: number): number
Parameters
min (number) Minimum value (inclusive).
max (number) Maximum value (inclusive).
Returns
number: A random integer between min and max.

getRandomString

Generates a random string of specified length using alphanumeric characters.

getRandomString(length: number): string
Parameters
length (number) Length of the string.
Returns
string: A random alphanumeric string.

generateBSN

Generates a valid 9-digit Dutch BSN using elfproef. No retries or brute force.

generateBSN(): string
Returns
string:

getRandomDate

Generates a random date between two dates.

getRandomDate(start: (Date | string | number), end: (Date | string | number)): Date
Parameters
start ((Date | string | number)) Start date.
end ((Date | string | number)) End date.
Returns
Date: Random date between start and end.

getRandomIntArray

Generates an array filled with random integers.

getRandomIntArray(length: number, min: number, max: number): Array<number>
Parameters
length (number) Number of elements.
min (number) Minimum value.
max (number) Maximum value.
Returns
Array<number>: Array of random integers.

createWord

Creates a random string will have a random size between 5 and 10 characters. It uses getRandomString and getRndInt as auxiliary functions.

createWord(): string
Returns
string: A string that simulates a word with 5 to 10 characters.

createSentence

Creates a sentence with a given amount of words. It uses createWord as auxiliary functions. Each word is separated with a blank space.

createSentence(numberOfWord: number): string
Parameters
numberOfWord (number) The number of requested words.
Returns
string: A string that simulates a sentence with a given number of words.

createParagraph

Creates a random number of sentences with a given amount of words. It uses createSentence as auxiliary functions. Each word is separated with a blank space, while sentences are separated with a dot and blank space.

createParagraph(numberOfWord: number, numberOfSentence: number): string
Parameters
numberOfWord (number) The number of requested words per sentence.
numberOfSentence (number) The number of requested sentences.
Returns
string: A string that simulates a word with 5 to 10 characters.

createDoc

Creates a random document comprised of paragraphs. It uses createParagraph as auxiliary functions. Each paragraph is separated with a new line.

createDoc(numberOfSentence: number, numberOfWord: number, numberOfPararaph: number): string
Parameters
numberOfSentence (number) The number of requested sentences.
numberOfWord (number) The number of requested words.
numberOfPararaph (number) The number of requested paragraphs.
Returns
string: A string that simulates a word with 5 to 10 characters.

string_utils

String utility functions including UTF-8 encoding/decoding.

string_utils

encodeUtf8

Encodes a string into UTF-8.

encodeUtf8(str: string): Uint8Array
Parameters
str (string) The input string.
Returns
Uint8Array: The UTF-8 encoded byte array.

decodeUtf8

Decodes a UTF-8 encoded byte array back into a string.

decodeUtf8(bytes: Uint8Array): string
Parameters
bytes (Uint8Array) The UTF-8 byte array.
Returns
string: The decoded string.

safeTrim

Trims a string and returns an empty string if input is null or undefined.

safeTrim(str: (string | null | undefined)): string
Parameters
str ((string | null | undefined)) The input string.
Returns
string: A trimmed string or an empty string.

capitalizeFirst

Capitalizes the first letter of a string.

capitalizeFirst(str: string): string
Parameters
str (string) The input string.
Returns
string: The capitalized string.

date_helpers

Date and time utility functions.

date_helpers

unixToJsDate

Converts a Unix timestamp (in seconds) to a JavaScript Date object.

unixToJsDate(unixSeconds: number): Date
Parameters
unixSeconds (number) The Unix timestamp in seconds.
Returns
Date: The corresponding JavaScript Date object.

jsDateToUnix

Converts a JavaScript Date object to a Unix timestamp (in seconds).

jsDateToUnix(date: Date): number
Parameters
date (Date) The JavaScript Date object.
Returns
number: The Unix timestamp in seconds.

formatDate

Formats a date to a YYYY-MM-DD string.

formatDate(input: (Date | string | number)): string
Parameters
input ((Date | string | number)) The date input.
Returns
string: The formatted date string.

isBefore

Checks if dateA is before dateB.

isBefore(dateA: (Date | string | number), dateB: (Date | string | number)): boolean
Parameters
dateA ((Date | string | number))
dateB ((Date | string | number))
Returns
boolean: True if dateA is before dateB.

isAfter

Checks if dateA is after dateB.

isAfter(dateA: (Date | string | number), dateB: (Date | string | number)): boolean
Parameters
dateA ((Date | string | number))
dateB ((Date | string | number))
Returns
boolean: True if dateA is after dateB.

convertNativeDateToTWDate

Convert a native date to a object TWDate.

convertNativeDateToTWDate(nativeDate: date): date
Parameters
nativeDate (date) The number of requested words.
Returns
date: A TWDate with the same timestamp as the entry.

addXDays

Adds a given amount of days into a given date.

addXDays(theDate: date, days: integer): date
Parameters
theDate (date) The date where the days will be added.
days (integer) Amount of days to add to a date.
Returns
date: A date in where the amount of days were added.

subtractXDays

Subtract a given amount of days from a given date.

subtractXDays(theDate: date, days: integer): date
Parameters
theDate (date) The date where the days will be subtracted.
days (integer) Amount of days to add to a date.
Returns
date: A date in where the amount of days were subtracted.

isLessNowPlusXDays

Checks if the given date is smaller than the time it is when the function is executed plus the amount of days given as input. This makes sure that the date we have is smaller than 'days' in the future. This function is precise to milliseconds.

isLessNowPlusXDays(theDate: date, days: integer): boolean
Parameters
theDate (date) The date which will be compared to the future date.
days (integer) Amount of days in the future to where we will compare our date.
Returns
boolean: Returns true if the date given as input is sooner than the time this function ran plus the given amount of days as input.

isLessEqNowPlusXDays

Checks if the given date is smaller or equal than the time it is when the function is executed plus the amount of days given as input. This makes sure that the date we have is smaller or equal than 'days' in the future. This function is precise to milliseconds.

isLessEqNowPlusXDays(theDate: date, days: integer): boolean
Parameters
theDate (date) The date which will be compared to the future date.
days (integer) Amount of days in the future to where we will compare our date.
Returns
boolean: Returns true if the date given as input is sooner or equal than the time this function ran plus the given amount of days as input.

isMoreNowPlusXDays

Checks if the given date is bigger than the time it is when the function is executed plus the amount of days given as input. This makes sure that the date we have is bigger than 'days' in the future. This function is precise to milliseconds.

isMoreNowPlusXDays(theDate: date, days: integer): boolean
Parameters
theDate (date) The date which will be compared to the future date.
days (integer) Amount of days in the future to where we will compare our date.
Returns
boolean: Returns true if the date given as input is later than the time this function ran plus the given amount of days as input.

isMoreEqNowPlusXDays

Checks if the given date is bigger or equal than the time it is when the function is executed plus the amount of days given as input. This makes sure that the date we have is bigger or equal than 'days' in the future. This function is precise to milliseconds.

isMoreEqNowPlusXDays(theDate: date, days: integer): boolean
Parameters
theDate (date) The date which will be compared to the future date.
days (integer) Amount of days in the future to where we will compare our date.
Returns
boolean: Returns true if the date given as input is later or equal than the time this function ran plus the given amount of days as input.

isEqNowPlusXDays

Checks if the given date is equal than the time it is when the function is executed plus the amount of days given as input. This makes sure that the date we have is equal than 'days' in the future. This function is precise to milliseconds.

isEqNowPlusXDays(theDate: date, days: integer): boolean
Parameters
theDate (date) The date which will be compared to the future date.
days (integer) Amount of days in the future to where we will compare our date.
Returns
boolean: Returns true if the date given as input is equal than the time this function ran plus the given amount of days as input.

checkMaxDaysBetweenDates

Checks if the amount of time between two dates is less that the limit we define. This function ignores time, making calculations only regarding days.

checkMaxDaysBetweenDates(dateEarliest: date, dateOldest: date, limitDays: integer): boolean
Parameters
dateEarliest (date) The date which is newest.
dateOldest (date) The date which is oldest.
limitDays (integer) Number of days which the two dates can't be bigger.
Returns
boolean: Returns true if the amount of time between the two dates is less that our limit of days.

dayDifference

Calculates the difference of days between two dates. Ignores time.

dayDifference(dateA: date, dateB: date): integer
Parameters
dateA (date) The first date to compare, must be the bigger date or else the result will be negative.
dateB (date) The second date to compare, must be the smaller date or else the result will be negative.
Returns
integer: Returns the amount of days that separate the two dates.

calculateBusinessDate

Calculates the next business date after a given amount of days to wait.

calculateBusinessDate(originalDate: date, daysToAdd: integer, timeScheduleName: string, holidayScheduleName: string, timeZoneName: string): date
Parameters
originalDate (date) The original date where we will base our calculations.
daysToAdd (integer) Amount of days in the future we need.
timeScheduleName (string) The timeSchedule is the business hours our application uses.
holidayScheduleName (string) The days of the calendar that are not business days.
timeZoneName (string) The timezone where the application is working.
Returns
date: Returns what is the business day we need according to the business calendar and the amount of days in the future we want.

_prependMessage

Adds mandatory prefixes to custom message. It prepends triple-angle-bracket marker ('>>>') then caller application acronym and then caller service (or process-level inline JS script) where this JS runs inside. Example. When application 'ABC' logs from 'Heavy Crunching' service a message 'some message', then following string is written to log file: '>>> [ABC][Heavy Crunching]: some message'

_prependMessage(message: String): any
Parameters
message (String) target message
Returns
any: message with mandatory prefixes.

_getCaller

Retrieves loghelper function caller name.

_getCaller(): any
Returns
any: Process step or service name.

_getContext

Retrieves runtime context details like process instance ID, task ID and user ID. Retrieved data is formatted using "UWVLog_contextTemplate" environment variable replacing specific placeholders: {pid}, {tid} or {uid}. If template string is empty returned context is empty.

_getContext(): any
Returns
any: Runtime context data formatted as string.

format

Formats message with extra parameters. Curly-braced placeholders in message are replaced with further arguments of function. Unmatched placeholders are filled with 'undefined'.

format(message: String): String
Parameters
message (String) message template with placeholders in curly braces.
Returns
String: formatted message with replaced placeholders.

_navigateObject

Navigates object to get nested attribute value, or subobject, using dot-notation. Other JS navigation syntax (square brackets etc) is not supported. Undefined value is returned for non-existent path or wrong syntax. Example:

_navigateObject(obj: Object, path: String)
Parameters
obj (Object) object to browse
path (String) dots-separated path to nested attribute in object.

info

This will log a message in info level if info is enabled on websphere.

info(message: (String | Object))
Parameters
message ((String | Object)) A message to be formatted and logged.

debug

This will log a message in debug level if debug is enabled on websphere.

debug(message: (String | Object))
Parameters
message ((String | Object)) A message to be formatted and logged.

error

This will log a message in error level.

error(message: (String | Object))
Parameters
message ((String | Object)) A message to be formatted and logged.

warn

This will log a message in warn level.

warn(message: (String | Object))
Parameters
message ((String | Object)) A message to be formatted and logged.

validation

Validation utilities for strings, numbers, arrays, dates, and objects.

validation

isNonEmptyString

Checks if a value is a non-empty string.

isNonEmptyString(value: any): boolean
Parameters
value (any) The value to validate.
Returns
boolean: True if the value is a non-empty string.

isInvalid

Checks if a value is undefined, null, or the strings "undefined" / "null".

isInvalid(value: any): boolean
Parameters
value (any) The value to validate.
Returns
boolean: True if the value is considered invalid.

isValidString

Checks if a value is a valid non-empty string.

isValidString(value: any): boolean
Parameters
value (any) The value to validate.
Returns
boolean: True if the value is a valid non-empty string.

isValidNumber

Checks if a value is a finite number.

isValidNumber(value: any): boolean
Parameters
value (any) The value to validate.
Returns
boolean: True if the value is a valid number.

isValidArray

Checks if a value is an array with at least one item.

isValidArray(value: any): boolean
Parameters
value (any) The value to validate.
Returns
boolean: True if the value is a non-empty array.

isValidDate

Checks if a value is a valid Date object or parseable date string.

isValidDate(value: any): boolean
Parameters
value (any) The value to validate.
Returns
boolean: True if the value is a valid date.

isDateInFuture

Checks if a given date is in the future.

isDateInFuture(inputDate: (Date | string | number)): boolean
Parameters
inputDate ((Date | string | number)) The date to validate.
Returns
boolean: True if the date is in the future.

isDateInPast

Checks if a given date is in the past.

isDateInPast(inputDate: (Date | string | number)): boolean
Parameters
inputDate ((Date | string | number)) The date to validate.
Returns
boolean: True if the date is in the past.

hasRequiredFields

Validates that an object contains all specified required fields.

hasRequiredFields(obj: Object, requiredFields: Array<string>): boolean
Parameters
obj (Object) The object to check.
requiredFields (Array<string>) List of required property names.
Returns
boolean: True if all required fields exist and are not null/undefined.

compareObjects

Recursively compares two objects and returns an object indicating key-wise equality.

compareObjects(obj1: Object, obj2: Object): Object
Parameters
obj1 (Object) First object.
obj2 (Object) Second object.
Returns
Object: Object with boolean values for each key indicating equality.

basicValueCheckString

Checks if a string is initialized and is different than a empty string.

basicValueCheckString(value: ANY): boolean
Parameters
value (ANY) The value to be checked if it's a string .
Returns
boolean: Returns true if the input is initialized and has as a value a string different than "".

validationElfProef

Checks if the source is a BSN. The algorithm to check if a string is a valid BSN is (9xA)+(8xB)+(7xC)+(6xD)+(5xE)+(4xF)+(3xG)+(2xH)+(-1xI) and then divide everything by 11, if the integer division returns 0 it's valid.

validationElfProef(source: string): boolean
Parameters
source (string) The BSN to be validated.
Returns
boolean: Returns true if the source is a valid BSN.

matchExact

Checks if a string is matched by a regex.

matchExact(regex: RegEx, str: string): boolean
Parameters
regex (RegEx) The regular expression to test a string.
str (string) The string to be tested.
Returns
boolean: Returns true if the regex matches the whole string

testStringIsInRange

Checks if the length of a string is between a given interval.

testStringIsInRange(source: string, min: integer, max: integer): boolean
Parameters
source (string) The string to be tested.
min (integer) The minimum amount of character the string can have.
max (integer) The maximum amount of character the string can have.
Returns
boolean: Returns true if the length of the source if between max and min characters.