Built-in helper functions
Rapid Apps by default includes multiple helper functions for common tasks. The helper must be included for each page individually, since they are not imported globally.
The helper-functions are split between 3 files, dates.js, filesize.js and time-ago.js these files are stored in the /scripts directory. There are other .js files in this directory, as this is the encouraged directory for storing scripts, however the other files provide code for more specific apps.
To use helper functions, you must import them to the specific page. The recommended way to do this is via a head.html file.
dates.js
Includes helper functions for formatting dates.
| Function | Purpose | Example outout |
|---|---|---|
formatDate_dd_mm_yyyy() : Date
|
Outputs a string in the format dd/mm/yyyy. | 17/05/2025 |
formatDate_yyyy_mm_dd() : Date
|
Outputs a string in the format yyyy/mm/dd. | 2025/05/17 |
formatDate_long() : Date
|
Outputs a string in the W D M Y. | Tuesday 3 December 2024 |
formatDate_dd_mmm_yyyy() : Date
|
Outputs a string in the format dd mmm yyyy. | 17 Feb 2025 |
formatDate_D_dd() : Date
|
Outputs a string in the format D dd. E.g. 17 Mon |
filesize.js
Includes helper functions for calculating filesize.
| Function | Purpose | Example outout |
|---|---|---|
bytes_to_appropriate_unit() : Number
|
Takes a number of bytes and outputs an appropriate string to represent the number of bytes in the most relevant unit (Maxes out at MB). | 100 KB or 2 MB |
time-ago.js
Includes helper functions to generate strings to say how long ago something happened.
| Function | Purpose | Example outout |
|---|---|---|
timeAgo() : Date
|
Returns a string describing how many days ago something happened. | 15 days ago |
timeAgoLabel() : Date
|
Returns a string describing how long ago something happened in its appropriate unit. | 4 seconds ago, or 1 year ago |