-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoverageNode.ts
35 lines (30 loc) · 1.05 KB
/
CoverageNode.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
import { Element } from '../Element';
import { isBoolean, isEnum, isNonZeroInteger, isObject, isUuid } from '../validation';
export interface CoverageNode extends Element<typeof CoverageNode.TYPE> {
uuid: string;
coverage: { id: number };
layout: `${CoverageNode.Layout}`;
new_tab: boolean;
show_thumbnail: boolean;
}
export namespace CoverageNode {
export const TYPE = 'coverage';
export enum Layout {
VERTICAL = 'vertical',
HORIZONTAL = 'horizontal',
}
export function isCoverageNode(value: any): value is CoverageNode {
return Element.isElement(value, TYPE);
}
export function validateCoverageNode(value: any): CoverageNode | null {
const isValid =
isCoverageNode(value) &&
isUuid(value.uuid) &&
isEnum(value.layout, Layout) &&
isBoolean(value.new_tab) &&
isBoolean(value.show_thumbnail) &&
isObject(value.coverage) &&
isNonZeroInteger(value.coverage.id);
return isValid ? value : null;
}
}