bigbuffet-rw/app/soapbox/normalizers/card.ts

31 lines
666 B
TypeScript
Raw Normal View History

2022-03-12 13:54:28 -08:00
/**
* Card normalizer:
* Converts API cards into our internal format.
* @see {@link https://docs.joinmastodon.org/entities/card/}
*/
2022-03-16 19:33:09 -07:00
import { Record as ImmutableRecord, Map as ImmutableMap, fromJS } from 'immutable';
2022-03-12 13:54:28 -08:00
// https://docs.joinmastodon.org/entities/card/
2022-03-16 19:15:38 -07:00
export const CardRecord = ImmutableRecord({
2022-03-12 13:54:28 -08:00
author_name: '',
author_url: '',
blurhash: null,
description: '',
embed_url: '',
height: 0,
html: '',
image: null,
provider_name: '',
provider_url: '',
title: '',
type: 'link',
url: '',
width: 0,
});
2022-03-16 19:33:09 -07:00
export const normalizeCard = (card: Record<string, any>) => {
return CardRecord(
ImmutableMap(fromJS(card)),
);
2022-03-12 13:54:28 -08:00
};