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) |
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 con = { despatchDateTime: '2022-07-20T00:00:00' } // Example only | |
const dateInDDMMYYYFormat = DateTime.fromISO(con.despatchDateTime).isValid ? DateTime.fromISO(con.despatchDateTime).toFormat('dd/MM/yyyy') : '' |
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 getDgClasses = (item) => { | |
if (!item.isDgItem || !item.dgItems) return '' | |
const dgClasses = item.dgItems.map(dg => { | |
let dgClassDisplay = dg.dgClass | |
if (dg.hasSubRisk && dg.subDgClasses && dg.subDgClasses.length > 0) { | |
const subDgClassesString = dg.subDgClasses.map(subDg => subDg.class).join(',') | |
dgClassDisplay += `/${subDgClassesString}` | |
} |