This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const randomFloat = function (min, max, decimalPlaces = 2) { | |
return Number((Math.random() * (max - min) + min).toFixed(decimalPlaces)); | |
} | |
const randomNumbersWithDecimal = randomFloat(1, 1000, 2) | |
// Sample output: | |
// 816.27 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const randomAlphanumeric = function (length) { | |
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' | |
let output = '' | |
for (let i = 0; i < length; i++) { | |
const randomIndex = Math.floor(Math.random() * characters.length) | |
output += characters[randomIndex] | |
} | |
return output |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const randomLetters = function (length) { | |
const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | |
let output = '' | |
for (let i = 0; i < length; i++) { | |
const randomIndex = Math.floor(Math.random() * letters.length) | |
output += letters[randomIndex] | |
} | |
return output |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const randomDigits = function (length) { | |
let output = '' | |
for (let i = 0; i < length; i++) { | |
if (i === 0 && length > 1) { // Exclude 0 | |
output += Math.floor(Math.random() * 9) + 1 | |
} else { | |
output += Math.floor(Math.random() * 10) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// URL encoding with encodeURIComponent | |
const objectToQueryString = function (obj) { | |
return Object.entries(obj) | |
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`) | |
.join('&') | |
} | |
const input = { | |
routes: [ | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const uuidv4 = function() { | |
return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.replace(/[x]/g, function(c) { | |
let r = Math.random() * 16 | 0 | |
let v = c === 'x' ? r : (r & 0x3 | 0x8) | |
return v.toString(16) | |
}) | |
} | |
// Sample output: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const invoice = { invoiceDate: '22/6/2025 12:00:00 am' } | |
// Use 'MM' (uppercase) for 2-digit month, or 'M' for 1-digit/2-digit month | |
const dateFormatted = DateTime.fromFormat(invoice.invoiceDate, 'dd/M/yyyy hh:mm:ss a').toFormat('dd/MM/yyyy') | |
// Sample output: | |
// 22/06/2025 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getEmail = (input) => { | |
return ( | |
input?.consignment?.fromAddress?.email || | |
input?.userInformation?.email || | |
input?.company?.address?.email || | |
null | |
) | |
} | |
const getPhone = (input) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const truncateText = (str, maxLength) => { | |
if (str && str.length > maxLength) { | |
return str.substring(0, maxLength) | |
} | |
return str | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { DateTime } = luxon | |
const deliveryTimeZoneName = 'Australia/Sydney' // Example only | |
const utcNow = DateTime.utc() // eg. 2025-06-04T00:51:38.438Z | |
// Sets the time of the delivery location based on its timezone | |
// eg. 2025-06-04T10:51:38.438+10:00 | |
const deliveryLocationDateTime = utcNow.setZone(deliveryTimeZoneName) |
NewerOlder