feat(utils): add the utils functionalities

This commit is contained in:
staticGuru
2023-05-11 17:31:04 +05:30
parent b7759a1dd1
commit a4cb064bee

View File

@@ -0,0 +1,27 @@
export const URL =
window.location.protocol +
"//" +
window.location.host +
window.location.pathname;
export function separateOperands(str: string): {
operators: any[];
operands: string[];
} {
const operators = findOperators(str);
const operands = str.split(
new RegExp(operators.map((op) => `\\${op}`).join("|"), "g")
);
return { operators, operands };
}
export function changePageUrl(newURL: string | undefined = URL) {
if (newURL !== URL) {
newURL = URL + newURL;
}
window.history.pushState({ path: newURL }, "", newURL);
}
function findOperators(str: string) {
const operators = [">=", "<=", ">", "<", "==", "!=", "=", "-is-"];
const regex = new RegExp(operators.map((op) => `\\${op}`).join("|"), "g");
return str.match(regex) || [];
}