/*jslint browser devel:true, for:true, es6:true */ /*global alert, confirm, console, prompt, jQuery, window, webapi, Promise, async */ (function (disrSharedUtils, $, undef) { 'use strict'; // Private Property // Public Property disrSharedUtils.sanitizeInputPattern = /[<>]|(\bscript\b|javascript:)|([a-zA-Z]:\\)|(\.\.[\\/])|[^a-zA-Z0-9$%().\-+,:?'\/\s]/gi; // Sanitization error message for user input fields // Disallowed: < > ! @ # ^ & * { } [ ] " ~ = ; | ` \ // Public Methods // Long Date format AU - dd mm yyyy (eg: 25 November 2024) disrSharedUtils.formatDateAuLong = function (theDate) { const months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; const date = new Date(theDate); var day = String(date.getDate()).padStart(2, '0'); var month = months[date.getMonth()]; var year = date.getFullYear(); return `${day}/${month}/${year}`; }; // Short Date format AU - dd/mm/yyyy (eg: 25/11/2024) disrSharedUtils.formatDateAuShort = function (theDate) { const date = new Date(theDate); var day = String(date.getDate()).padStart(2, '0'); var month = String(date.getMonth() + 1).padStart(2, '0'); var year = date.getFullYear(); return `${day}/${month}/${year}`; }; // Format numeric filesize to KB/MB, etc. disrSharedUtils.formatFileSize = function (bytes) { const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']; if (bytes === 0) { return '0 Byte'; } const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i]; }; // Generate new GUID disrSharedUtils.generateGUID = function () { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); }; // Check if the value is null or blank disrSharedUtils.isNullOrBlank = function (value) { return value === null || value === undefined || (typeof value === "string" && value.trim() === ""); }; // Get the local date part from a Date object or string in ISO format disrSharedUtils.getLocalISODatePart = function(date) { if (!(date instanceof Date)) { date = new Date(date); } const year = date.getFullYear(); const month = String(date.getMonth() + 1).padStart(2, '0'); const day = String(date.getDate()).padStart(2, '0'); return new Date(`${year}-${month}-${day}`).toISOString(); }; // Private Method }(window.disrSharedUtils = window.disrSharedUtils || {}, jQuery));