UNPKG

notion-helper

Version:

A library of functions for working more easily with the Notion API

146 lines 6.43 kB
/** * Builds a Rich Text Object. See: https://developers.notion.com/reference/rich-text * @param {(string|Object)} input - The text content or input object. If string, the input can be normal text or an equation. If object, it can be a text, equation, or mention object. * @param {Object} [options] - Options for configuring the rich text object * @param {Object} [options.annotations] - Options for the Annotation object * @param {boolean} [options.annotations.bold] - Bold text * @param {boolean} [options.annotations.italic] - Italic text * @param {boolean} [options.annotations.strikethrough] - Strikethrough text * @param {boolean} [options.annotations.underline] - Underlined text * @param {boolean} [options.annotations.code] - Code-style text * @param {string} [options.annotations.color] - String specifying the text's color or background color. Options: "blue", "brown", "default", "gray", "green", "orange", "pink", "purple", "red", "yellow". All except "default" can also be used as a background color with "[color]_background" - example: "blue_background". See: https://developers.notion.com/reference/rich-text#the-annotation-object * @param {string} [options.url] - The URL for this object, if any. Creates a clickable link. * @param {string} [options.type="text"] - An optional type for the Rich Text Object. Supports text, equation, and mention. * @returns {Array<Object>} - Array with a single Rich Text Object * * @example * // Simple text * buildRichTextObj("Hello World") * * // Text with URL * buildRichTextObj("Watch this very important video", { url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ" }) * * // Text with annotations * buildRichTextObj("Bold and brown", { * annotations: { bold: true, color: "brown" } * }) * * // Text with URL and annotations * buildRichTextObj("Bold blue link", { * url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ", * annotations: { bold: true, color: "blue" } * }) * * // Equation * buildRichTextObj("E = mc^2", { type: "equation" }) * * // Mention * buildRichTextObj({ type: "user", user: { id: "user_id" } }, { type: "mention" }) * buildRichTextObj({ type: "date", date: { start: "2025-01-01" } }, { type: "mention" }) * buildRichTextObj({ type: "database", database_id: "database_id" }, { type: "mention" }) * buildRichTextObj({ type: "page", page_id: "page_id" }, { type: "mention" }) */ export function buildRichTextObj(input: (string | Object), options?: { annotations?: { bold?: boolean | undefined; italic?: boolean | undefined; strikethrough?: boolean | undefined; underline?: boolean | undefined; code?: boolean | undefined; color?: string | undefined; } | undefined; url?: string | undefined; type?: string | undefined; }, ...args: any[]): Array<Object>; /** * Creates a user mention with shorthand syntax. * @param {string} userId - The user ID to mention * @param {Object} [options] - Additional options for the mention * @param {Object} [options.annotations] - Text annotations (bold, italic, etc.) * @param {string} [options.url] - URL for the mention * @returns {Array<Object>} - Array with a single Rich Text Object containing the user mention * * @example * // Simple user mention * mentionUser("user_123") * * // User mention with annotations * mentionUser("user_123", { annotations: { bold: true, color: "blue" } }) */ export function mentionUser(userId: string, options?: { annotations?: Object | undefined; url?: string | undefined; }): Array<Object>; /** * Creates a date mention with shorthand syntax. * @param {string|Object} date - The date string or date object * @param {Object} [options] - Additional options for the mention * @param {Object} [options.annotations] - Text annotations (bold, italic, etc.) * @param {string} [options.url] - URL for the mention * @returns {Array<Object>} - Array with a single Rich Text Object containing the date mention * * @example * // Simple date mention * mentionDate("2025-01-01") * * // Date mention with time range * mentionDate({ start: "2025-01-01", end: "2025-01-02" }) * * // Date mention with annotations * mentionDate("2025-01-01", { annotations: { bold: true } }) */ export function mentionDate(date: string | Object, options?: { annotations?: Object | undefined; url?: string | undefined; }): Array<Object>; /** * Creates a database mention with shorthand syntax. * @param {string} databaseId - The database ID to mention * @param {Object} [options] - Additional options for the mention * @param {Object} [options.annotations] - Text annotations (bold, italic, etc.) * @param {string} [options.url] - URL for the mention * @returns {Array<Object>} - Array with a single Rich Text Object containing the database mention * * @example * // Simple database mention * mentionDatabase("database_123") * * // Database mention with annotations * mentionDatabase("database_123", { annotations: { italic: true } }) */ export function mentionDatabase(databaseId: string, options?: { annotations?: Object | undefined; url?: string | undefined; }): Array<Object>; /** * Creates a page mention with shorthand syntax. * @param {string} pageId - The page ID to mention * @param {Object} [options] - Additional options for the mention * @param {Object} [options.annotations] - Text annotations (bold, italic, etc.) * @param {string} [options.url] - URL for the mention * @returns {Array<Object>} - Array with a single Rich Text Object containing the page mention * * @example * // Simple page mention * mentionPage("page_123") * * // Page mention with annotations * mentionPage("page_123", { annotations: { color: "green" } }) */ export function mentionPage(pageId: string, options?: { annotations?: Object | undefined; url?: string | undefined; }): Array<Object>; /** * Enforces Rich Text format for content. * @param {string|Object|Array} content - The content to be enforced as Rich Text. * @returns {Array} An array of Rich Text Objects. */ export function enforceRichText(content: string | Object | any[]): any[]; /** * Enforces a single Rich Text Object format. * @param {string|Object} obj - The object to be enforced as a Rich Text Object. * @returns {Object} A Rich Text Object. */ export function enforceRichTextObject(obj: string | Object): Object; //# sourceMappingURL=rich-text.d.mts.map