Bin
2025-12-17 2b99d77d73ba568beff0a549534017caaad8a6de
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
interface Formatter {
  [key: string]: (operator: string, value: any) => any;
}
 
const filterFormatters: Formatter = {
  Number: (op, value) => {
    if (op.match(/^in|not_in$/)) {
      const result = Object.entries(value).map(([key, value]) => {
        return [key, Number(value)];
      });
 
      return Object.fromEntries(result);
    }
 
    return Number(value);
  },
  String: (op, value) => {
    if (op.match(/^in|not_in$/)) {
      const result = Object.entries(value).map(([key, value]) => {
        return [key, String(value)];
      });
 
      return Object.fromEntries(result);
    }
 
    return String(value);
  },
};
 
export const normalizeFilterValue = (type: string, op: string, value: any) => {
  const formatter = filterFormatters[type];
 
  return formatter ? formatter(op, value) : value;
};