utils.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { SortOrder } from "antd/lib/table/interface";
  2. export function fullUrl(url: string): string {
  3. return window.location.origin + process.env.PUBLIC_URL + url;
  4. }
  5. export function PaliToEn(pali: string): string {
  6. let output: string = pali.toLowerCase();
  7. output = output.replaceAll("ā", "a");
  8. output = output.replaceAll("ī", "i");
  9. output = output.replaceAll("ū", "u");
  10. output = output.replaceAll("ḍ", "d");
  11. output = output.replaceAll("ṭ", "t");
  12. output = output.replaceAll("ḷ", "l");
  13. output = output.replaceAll("ṅ", "n");
  14. output = output.replaceAll("ṇ", "n");
  15. output = output.replaceAll("ñ", "n");
  16. output = output.replaceAll("ṃ", "m");
  17. return output;
  18. }
  19. export function PaliReal(inStr: string | undefined | null): string {
  20. if (typeof inStr !== "string") {
  21. return "";
  22. }
  23. const paliLetter = "abcdefghijklmnoprstuvyāīūṅñṭḍṇḷṃ";
  24. let output: string = "";
  25. inStr = inStr.toLowerCase();
  26. inStr = inStr.replace(/ṁ/g, "ṃ");
  27. inStr = inStr.replace(/ŋ/g, "ṃ");
  28. for (const iterator of inStr) {
  29. if (paliLetter.includes(iterator)) {
  30. output += iterator;
  31. }
  32. }
  33. return output;
  34. }
  35. export const getSorterUrl = (sorter?: Record<string, SortOrder>): string => {
  36. let url: string = "";
  37. for (const key in sorter) {
  38. if (Object.prototype.hasOwnProperty.call(sorter, key)) {
  39. const element = sorter[key];
  40. const dir = element === "ascend" ? "asc" : "desc";
  41. let orderby = key;
  42. if (orderby === "updatedAt") {
  43. orderby = "updated_at";
  44. }
  45. url = `&order=${orderby}&dir=${dir}`;
  46. }
  47. }
  48. return url;
  49. };
  50. export const convertToPlain = (html: string): string => {
  51. // Create a new div element
  52. var tempDivElement = document.createElement("div");
  53. // Set the HTML content with the given value
  54. tempDivElement.innerHTML = html;
  55. // Retrieve the text property of the element
  56. return tempDivElement.textContent || tempDivElement.innerText || "";
  57. };