-
Notifications
You must be signed in to change notification settings - Fork 3
/
preferences.ts
52 lines (49 loc) · 1.6 KB
/
preferences.ts
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import {
BooleanPreference,
IntegerRangePreference,
PreferenceManager,
StringPreference,
} from "ts-preferences";
import { loggingResponseHandler } from "userscripter/run-time/preferences";
import U from "~src/userscript";
import T from "~src/text";
export const P = {
foobars: {
label: T.preferences.foobars.label,
_: {
insert: new BooleanPreference({
key: "insert_foobars",
label: T.preferences.foobars.insert.label,
description: T.preferences.foobars.insert.description,
default: true,
}),
number: new IntegerRangePreference({
key: "number_of_foobars",
label: T.preferences.foobars.number.label,
description: T.preferences.foobars.number.description,
min: 0,
max: 100,
default: 5,
}),
},
},
username: new StringPreference({
key: "username",
label: T.preferences.username.label,
description: T.preferences.username.description,
default: "John Smith",
multiline: false,
maxLength: 50,
constraints: [
{
requirement: v => !/^\s/.test(v),
message: _ => `Leading whitespace not allowed.`,
},
{
requirement: v => !/\s$/.test(v),
message: _ => `Trailing whitespace not allowed.`,
},
],
}),
} as const;
export const Preferences = new PreferenceManager(P, U.id + "-preference-", loggingResponseHandler);