zhongrj
2025-11-24 276323dce9613867abb3f58a4cc2abbfb2fd0dea
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
import { _ } from './gettext';
 
const dict = [
  {k: 'NO', v: 0, human: _("No")}, // Don't resize
  {k: 'YES', v: 1, human: _("Yes")} // Resize on server
];
 
const exp = {
  all: () => dict.map(d => d.v),
  fromString: (s) => {
    let v = parseInt(s);
    if (!isNaN(v) && v >= 0 && v <= 1) return v;
    else return 0;
  },
  toHuman: (v) => {
    for (let i in dict){
      if (dict[i].v === v) return dict[i].human;
    }
    throw new Error("Invalid value: " + v);
  }
};
dict.forEach(en => {
  exp[en.k] = en.v;
});
 
export default exp;