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