Uname:Linux machinox-server 6.17.0-1013-aws #13~24.04.1-Ubuntu SMP Fri Apr 24 21:36:58 UTC 2026 aarch64

Base Dir : /var/www/machinox.in

User : root


403WebShell
403Webshell
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 :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/control.machinox.in/src/Services/HelperService.tsx
import moment from "moment";

const HelperService = {
  formatDate(date: string) {
    if (date) {
      return moment(date).format("DD-MM-YYYY");
    }
  },
  truncate(str: string, size: number) {
    return str.length > size ? str?.substring(0, size) + "..." : str;
  },
  removeDecimal(value: any) {
    return value ? Math.floor(value) : 0;
  },
  validateEmail(email: any) {
    const regex = /^[^\s@]+@[^\s@]+\.[a-zA-Z]{2,}$/;
    return regex.test(email);
  },
  removeUnderScore(str: any) {
    if ((str !== "" || str !== undefined) && str.includes("_")) {
      return this.titleCase(str.replace(/_/g, " "));
    } else {
      return this.titleCase(str);
    }
  },
  removeDialCodeFromMobile(mobileNumber: any, dialCode: any) {
    if (
      typeof mobileNumber === "string" &&
      typeof dialCode === "string" &&
      dialCode.length > 0
    ) {
      if (mobileNumber.startsWith(dialCode)) {
        return mobileNumber.slice(dialCode.length);
      }
    }
    return mobileNumber;
  },
  titleCase(str: any) {
    if (str !== "") {
      return str
        .toLowerCase()
        .split(" ")
        .map((word: any) => {
          return word.charAt(0).toUpperCase() + word.slice(1);
        })
        .join(" ");
    } else {
      return str;
    }
  },
  getDivHeight(id: any) {
    let div = document.getElementById(id);
    if (div) {
      return div.offsetHeight;
    }
  },

  decideBadgeClass(status: string) {
    if (status === "ACTIVE") return "badge badge-green";
    else if (status === "INACTIVE") return "badge badge-danger";
    else if (status === "In_Active") return "badge badge-danger";
    else if (status === "PUBLISHED") return "badge badge-green";
    else if (status === "Published") return "badge badge-green";
    else if (status === "UNPUBLISHED") return "badge badge-danger";
    else if (status === "PENDING") return "badge badge-light";
  },
  checkEmptyUndefinedNull(value: any) {
    if (value !== null && value !== undefined && value != "") {
      return true;
    }
    return false;
  },
  getFormattedDateOnly(dt: any) {
    if (dt) {
      return moment(dt).format("DD-MMM-YYYY");
    }
  },
  toProperCase(str: string) {
    if (!str) {
      return "";
    }
    const pattern = /_/gi;
    const replacement = " ";
    const result = str.replaceAll(pattern, replacement);

    return result.replace(/\w\S*/g, function (txt) {
      return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
    });
  },
  getFormattedCurrency(amount: any) {
    var fractionDigit = 0;
    if (amount % 1 > 0) {
      fractionDigit = 2;
    }
    if (amount === "" || amount === undefined) {
      return "";
    }
    if (amount === 0) {
      let value = Intl.NumberFormat("en-IN", {
        style: "currency",
        currency: localStorage.getItem("currency") ?? "GBP",
        minimumFractionDigits: fractionDigit,
      }).format(amount);
      return value;
    }

    if (!amount) {
      return "";
    }
    var inr = Intl.NumberFormat("en-IN", {
      style: "currency",
      currency: localStorage.getItem("currency") ?? "GBP",
      minimumFractionDigits: fractionDigit,
    }).format(amount);
    return inr;
  },
  maxNumber(e: any, maxNumber: number) {
    if (maxNumber && e.currentTarget.value.length > maxNumber) {
      e.preventDefault();
      return false;
    }
  },

  getFormatedDateWithYear(d: any) {
    return d ? moment.utc(d).format("YYYY-MM-DD") : "";
  },
  getInverseFormattedDateforScedule(d: any) {
    const regex = /^[A-Za-z]{3} [A-Za-z]{3} \d{2} \d{4} \d{2}:\d{2}:\d{2} GMT\+\d{4} \(.*\)$/;

    // Check if the input string matches the specified format
    if (regex.test(d)) {
      try {
        // Format the date if it matches the pattern
        return moment(d).format("HH:mm:ss");
      } catch (e) {
        // Fallback to UTC formatting if the above fails
        return moment.utc(d).format("HH:mm:ss");
      }
    } else {
      // Return the input as is if it doesn't match the pattern
      return d;
    }
  },
  getFormattedDateforScedule(dt: any) {
    try {
      const [hours, minutes, seconds] = dt.split(":").map(Number);

      // Get the current date
      const currentDate = new Date();

      // Set the time part based on the provided time string
      currentDate.setHours(hours, minutes + 1, seconds, 0);

      // Return the date string in the desired format
      return currentDate.toString();
    } catch {
      if (dt) {
        let date: any = moment(dt).add(1, "minutes");
        return new Date(date);
      }
      return "";
    }
  },
  getFormattedDate(dt: any) {
    if (dt) {
      return moment(dt).format("DD-MM-YYYY hh:mm A");
    }
  },
  toProperSeparatedString(a: any) {
    return a.join(", ").replace(/,(?!.*,)/gim, " and");
  },
  getFormatedStatusText(dt: string) {
    if (dt !== "" && dt !== undefined) {
      dt = dt.replaceAll("_", " ");
      dt = dt[0].toUpperCase() + dt.slice(1).toLowerCase();
      return dt;
    } else {
      return "";
    }
  },
};

export default HelperService;

Youez - 2016 - github.com/yon3zu
LinuXploit