Helper Functions
In this section, we will explore how to use Helper Functions effectively.
Helper Functions are referenced through template syntax. If you're not familiar with this, please first refer to the Template Syntax section.
Available Functions
Tapicker provides built-in helper functions accessible under the @funcs
scope. The currently available functions are:
- getPageURL()
- getPageVar(path)
- getTimestamp(value?)
- getDate(value?)
- getUUID(separator?)
- getRandomId(len?)
- getRandomNum(min, max)
Note that arguments followed by a ?
mark, such as value?
, are optional.
Next, we'll go through each function, explaining their purposes and how to use them.
getPageURL()
Retrieves the URL of the current page.
Arguments
- None
Returns
- String: The URL of the current page
Examples
-
If you are visiting Google, this will return:
{{@funcs.getPageURL()}} π https://www.google.com/
getPageVar(path)
Retrieves a variable from the current page.
Arguments
path
: String, required. It is the access path of the variable.
Returns
- Any: The value of the variable. If the variable cannot be accessed, it returns
undefined
.
Examples
-
Retrieve the page title:
{{@funcs.getPageVar("document.title")}} π βGoogleβ
-
Retrieve the host of the page URL:
{{@funcs.getPageVar("location.host")}} π βwww.google.comβ
-
Retrieve the language of the page:
{{@funcs.getPageVar("navigator.language")}} π "en-US"
getTimestamp(value?)
Gets the timestamp of the current time or a specific time, representing the number of milliseconds since 1970-01-01 00:00:00
to the target time.
Arguments
value
: String, optional. A date string. Refer to Date time string format for the format.
Returns
- Number: The number of milliseconds for the specified time.
Examples
-
Get the timestamp of the current time:
{{@funcs.getTimestamp()}} π 1725031203658
-
Get the timestamp of a specific date:
{{@funcs.getTimestamp('2024-08-28T18:18:28')}} π 1724840308000
getDate(value?)
Retrieves the date object for the current time or a specific time.
Arguments
value
: String | Number, optional. A date string or timestamp. Refer to Date time string format for the format.
Returns
- Date: The date object for the specified time.
Examples
-
Get the date object for the current time:
{{@funcs.getDate()}} π 2024-08-30T15:20:03.658Z
-
Get the date object for a specific date:
{{@funcs.getDate('2024-08-28T18:18:28')}} π 2024-08-28T10:18:28.000Z
-
Get a date object from a timestamp:
{{@funcs.getDate(1724840308000)}} π 2024-08-28T10:18:28.000Z
-
Format a date object into a specific format:
{{@funcs.getDate(1724840308000)|format("YYYY/MM/DD")}} π 2024/08/28
getUUID(separator?)
Generates a standard UUID or a UUID with a custom separator.
Arguments
separator
: String, optional. The separator character.
Returns
- String: The generated UUID.
Examples
-
Generate a standard UUID:
{{@funcs.getUUID()}} π "d58c8f4b-0375-41d0-adc2-f33f56c0e16c"
-
Generate a UUID with a custom separator:
{{@funcs.getUUID("#")}} π "d58c8f4b#0375#41d0#adc2#f33f56c0e16c"
-
Generate a UUID with no separator:
{{@funcs.getUUID("")}} π "d58c8f4b037541d0adc2f33f56c0e16c"
getRandomId(len?)
Generates a random ID of a specified length.
Arguments
len
: Number, optional. The length of the ID.
Returns
- String: A random string composed of digits and characters from
a
tof
.
Examples
-
Generate an ID with the default length of 8:
{{@funcs.getRandomId()}} π "dd9a7d68"
-
Generate an ID with a length of 24:
{{@funcs.getRandomId(24)}} π "45082a6f856340d3bfd342b9"
getRandomNum(min, max)
Generates a random number within a specified range, inclusive of min
and max
.
Arguments
min
: Number, required. The minimum value.max
: Number, required. The maximum value.
Returns
- String: A random number within the specified range.
Examples
-
Generate a random number between 1 and 10:
{{@funcs.getRandomNum(1, 10)}} π 6