| Server IP : 13.235.167.51 / Your IP : 216.73.217.116 Web Server : Apache System : Linux machinox-server 6.17.0-1013-aws #13~24.04.1-Ubuntu SMP Fri Apr 24 21:36:58 UTC 2026 aarch64 User : root ( 0) PHP Version : 8.2.29 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/control.machinox.in/src/Services/ |
Upload File : |
import HelperService from "./HelperService";
const CommonFunction = {
sortArrayBasedOnkey(array: any, key: any) {
return array.sort(function (a: any, b: any) {
var x = a[key];
var y = b[key];
// It compares these two values (x and y). If x is less than y, it returns -1 which means a should come before b. If x is greater than y,
// It returns 1 which means a should come after b. If they are equal, it returns 0 which means their order does not matter.
return x < y ? -1 : x > y ? 1 : 0;
});
},
checkFormEmptyFields(obj: any, excludedKeys: any = []) {
let emptyKeyFlag = false;
const excludedKeysSet = new Set(excludedKeys);
Object.keys(obj).forEach((key) => {
if (
!excludedKeysSet.has(key) &&
(obj[key] === undefined || !obj[key] || obj[key] === "")
) {
console.log("key", key);
emptyKeyFlag = true;
}
});
console.log(emptyKeyFlag);
return emptyKeyFlag;
},
addBadgesBasedOnStatus(status: string) {
if (status === "INACTIVE" || status === "PENDING" || status === "DEBIT" || status === "REJECTED") {
return `badge badge-pill badge-danger`;
} else if (status === "ACTIVE" || status === "ACCEPTED" || status === "CREDIT") {
return `badge badge-pill badge-primary`;
}
},
getPaymentStatus(status: string) {
if (status === "SUCCESS") {
return `badge badge-pill badge-green`;
} else {
return `badge badge-pill badge-danger`;
}
},
passwordValidation(value: string) {
if (value && !/(?=^.{8,}$)((?=.*\d)(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/.test(value)) {
return false
}
return true;
}
};
export default CommonFunction;