-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathscope.ts
44 lines (40 loc) · 988 Bytes
/
scope.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
import { gray } from "chalk";
import { Field, IField, IMessage } from "../message";
/**
* Scope transformer
*/
export type ScopeTextTransformer = (scopes: string[]) => string;
/**
* Scope configuration
*/
export interface IScopeConfig {
name?: string;
scopes?: string[];
transformer?: ScopeTextTransformer;
}
/**
* Scope options
*/
export interface IScopeOptions {
scope?: string[];
}
/**
* Scope field
* @param config Field configuration
*/
export default function ({
name: defaultName = "scope",
scopes: defaultScopes = ["zoya"],
transformer: defaultTransformer = (scopeList) =>
gray(scopeList.map((scope) => `[${scope}]`).join("")),
}: IScopeConfig = {}): Field {
return function handler(message: IMessage): IField {
const options = message.type.options as IScopeOptions;
const scope = (options || {}).scope || defaultScopes;
return {
data: defaultScopes,
name: defaultName,
text: defaultTransformer(scope),
};
};
}