mirror of
https://github.com/rowyio/rowy.git
synced 2026-02-24 12:10:18 +01:00
feat(utils): add the utils functionalities
This commit is contained in:
27
src/components/TableToolbar/Filters/utils.tsx
Normal file
27
src/components/TableToolbar/Filters/utils.tsx
Normal 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) || [];
|
||||
}
|
||||
Reference in New Issue
Block a user