-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
62 lines (50 loc) · 1.38 KB
/
index.d.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
53
54
55
56
57
58
59
60
61
62
declare module 'js-data-model' {
export const DataModel: Model.DataModelConstructor
export const parserTypes: ParserTypes
}
declare interface ParserTypes {
Array: ArrayConstructor
Object: ObjectConstructor
String: StringConstructor
Number: NumberConstructor
Boolean: BooleanConstructor
}
declare namespace Model {
interface CustomParser {
(
val: any,
options: {
data: any
model: OptionsMap
option: Options
helperData: any
}
): any
}
type OptionsMap = Record<string, Options | CustomParser>
interface Options {
type?: any
subModel?: OptionsMap
default?: any
parser?: CustomParser
fromKey?: string
}
type Parser = (val: any, model: OptionsMap, helperData?: any) => any
interface DataModelInterface {
/** 转换数据为 model 对应结构 */
parse(data: Record<string, any>, helperData?: any): Record<string, any>
}
interface DataModelConstructor {
new (model: OptionsMap): DataModelInterface
/** 添加 parserTypes 的枚举*/
addParserTypes(types: Record<string, any>): void
addParser(type: any, parser: Parser): void
use(plugin: DataModelPlugin, options?: any): void
}
interface DataModelPluginFunction {
(DataModel: DataModelConstructor, options?: any): void
}
type DataModelPlugin =
| DataModelPluginFunction
| { install: DataModelPluginFunction }
}