-
Notifications
You must be signed in to change notification settings - Fork 0
/
VideoNode.ts
37 lines (30 loc) · 1.01 KB
/
VideoNode.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
import { OEmbedInfo as OEmbed } from '../common';
import { Element } from '../Element';
import { isEnum, isNonEmptyString, isUuid } from '../validation';
export interface VideoNode extends Element<typeof VideoNode.TYPE> {
uuid: string;
url: string;
oembed: VideoNode.OEmbedInfo;
layout: `${VideoNode.Layout}`;
}
export namespace VideoNode {
export const TYPE = 'video';
export enum Layout {
CONTAINED = 'contained',
EXPANDED = 'expanded',
FULL_WIDTH = 'full-width',
}
export import OEmbedInfo = OEmbed;
export function isVideoNode(value: any): value is VideoNode {
return Element.isElement(value, VideoNode.TYPE);
}
export function validateVideoNode(value: any): VideoNode | null {
const isValid =
isVideoNode(value) &&
isNonEmptyString(value.url) &&
isUuid(value.uuid) &&
OEmbed.isOEmbedInfo(value.oembed) &&
isEnum(value.layout, Layout);
return isValid ? value : null;
}
}