@automattic/social-previews
Version:
A suite of components to generate previews for a post for both social and search engines.
37 lines • 1.99 kB
TypeScript
export type Formatter<Options = unknown> = (text: string, options?: Options) => string;
type AugmentFormatterReturnType<T extends Formatter, TNewReturn> = (...a: Parameters<T>) => ReturnType<T> | TNewReturn;
type ConditionalFormatter = AugmentFormatterReturnType<Formatter, boolean>;
type NullableFormatter = AugmentFormatterReturnType<Formatter, undefined>;
export declare const baseDomain: (url: string) => string;
export declare const shortEnough: (n: number) => ConditionalFormatter;
export declare const truncatedAtSpace: (a: number, b: number) => ConditionalFormatter;
export declare const hardTruncation: (n: number) => Formatter;
export declare const firstValid: (...args: ConditionalFormatter[]) => NullableFormatter;
export declare const stripHtmlTags: Formatter<Array<string>>;
/**
* For social note posts we use the first 50 characters of the description.
* @param description The post description.
* @returns The first 50 characters of the description.
*/
export declare const getTitleFromDescription: (description: string) => string;
export declare const hasTag: (text: string, tag: string) => boolean;
export declare const formatNextdoorDate: (date?: Date | number) => string;
export declare const formatThreadsDate: (date?: Date | number) => string;
export declare const formatTweetDate: (date?: Date | number) => string;
export declare const formatMastodonDate: (date?: Date | number) => string;
export type Platform = 'bluesky' | 'facebook' | 'instagram' | 'linkedin' | 'mastodon' | 'nextdoor' | 'threads' | 'twitter';
type PreviewTextOptions = {
platform: Platform;
maxChars?: number;
maxLines?: number;
hyperlinkUrls?: boolean;
hyperlinkHashtags?: boolean;
hashtagDomain?: string;
};
export declare const hashtagUrlMap: Record<Platform, string>;
/**
* Prepares the text for the preview.
*/
export declare function preparePreviewText(text: string, options: PreviewTextOptions): React.ReactNode;
export {};
//# sourceMappingURL=helpers.d.ts.map