UNPKG

@humanwhocodes/crosspost

Version:

A utility to post across multiple social networks.

230 lines (229 loc) 5.1 kB
/** * A strategy for posting articles to Dev.to. */ export class DevtoStrategy { /** * Creates a new instance. * @param {DevtoOptions} options Options for the instance. * @throws {Error} When options are missing. */ constructor(options: DevtoOptions); /** * Maximum length of a Dev.to article (no strict limit). * @type {number} * @const */ MAX_MESSAGE_LENGTH: number; /** * The ID of the strategy. * @type {string} * @readonly */ readonly id: string; /** * The display name of the strategy. * @type {string} * @readonly */ readonly name: string; /** * Posts an article to Dev.to. * @param {string} message The message to post. * @param {PostOptions} [postOptions] Additional options for the post. * @returns {Promise<DevtoArticle>} A promise that resolves with the article data. */ post(message: string, postOptions?: PostOptions): Promise<DevtoArticle>; /** * Extracts a URL from a Dev.to API response. * @param {DevToPostResponse} response The response from the Dev.to API post request. * @returns {string} The URL for the Dev.to article. */ getUrlFromResponse(response: DevToPostResponse): string; /** * Calculates the length of a message for Dev.to. * Dev.to has no strict character limit for articles, but this returns the character count. * @param {string} message The message to calculate the length of. * @returns {number} The calculated length of the message. */ calculateMessageLength(message: string): number; #private; } export type DevtoOptions = { /** * The Dev.to API key. */ apiKey: string; }; export type DevtoArticle = { /** * The title of the article. */ title: string; /** * The markdown content of the article. */ body_markdown: string; /** * Whether the article is published. */ published: boolean; /** * The tags for the article. */ tags: string[]; }; export type DevToUser = { /** * The name of the user. */ name: string; /** * The username of the user. */ username: string; /** * The Twitter username of the user. */ twitter_username: string | null; /** * The GitHub username of the user. */ github_username: string | null; /** * The ID of the user. */ user_id: number; /** * The website URL of the user. */ website_url: string | null; /** * The profile image URL of the user. */ profile_image: string; /** * The profile image URL of the user (90px). */ profile_image_90: string; }; export type DevToPostResponse = { /** * The type of post (e.g., "article"). */ type_of: string; /** * The ID of the article. */ id: number; /** * The title of the article. */ title: string; /** * The description of the article. */ description: string; /** * The human-readable publish date. */ readable_publish_date: string; /** * The slug of the article. */ slug: string; /** * The path of the article. */ path: string; /** * The full URL of the article. */ url: string; /** * The number of comments. */ comments_count: number; /** * The number of public reactions. */ public_reactions_count: number; /** * The collection ID of the article. */ collection_id: number; /** * The publish timestamp. */ published_timestamp: string; /** * The number of positive reactions. */ positive_reactions_count: number; /** * The cover image URL. */ cover_image: string | null; /** * The social image URL. */ social_image: string | null; /** * The canonical URL. */ canonical_url: string | null; /** * The creation timestamp. */ created_at: string; /** * The last edit timestamp. */ edited_at: string | null; /** * The crosspost timestamp. */ crossposted_at: string | null; /** * The publish timestamp. */ published_at: string; /** * The last comment timestamp. */ last_comment_at: string; /** * The reading time in minutes. */ reading_time_minutes: number; /** * The comma-separated list of tags. */ tag_list: string; /** * The array of tags. */ tags: string[]; /** * The HTML content of the article. */ body_html: string; /** * The markdown content of the article. */ body_markdown: string; /** * The user who created the article. */ user: DevToUser; }; export type DevtoErrorResponse = { /** * The error message. */ error: string; /** * The error status. */ status: string; }; export type PostOptions = import("../types.js").PostOptions;