-
Notifications
You must be signed in to change notification settings - Fork 6
/
attributes.ts
36 lines (31 loc) · 914 Bytes
/
attributes.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
export type PageAttributes = Record<string, unknown>;
export const hasKey = (data: PageAttributes, keys: Array<string>): boolean => {
for (const key of Object.keys(data)) {
const keyTyped = key as keyof typeof data;
if (keys.includes(keyTyped) && data[keyTyped] === true) {
return true;
}
}
return false;
};
export const getTitle = (data: PageAttributes): string | undefined => {
if (typeof data.title === "string") {
return data.title;
}
};
export const getDescription = (data: PageAttributes): string | undefined => {
if (typeof data.description === "string") {
return data.description;
}
};
export const getTags = (data: PageAttributes): Array<string> => {
if (Array.isArray(data.tags)) {
return data.tags;
}
return [];
};
export const getDate = (data: PageAttributes): Date | undefined => {
if (data.date instanceof Date) {
return data.date;
}
};