UNPKG

@humanwhocodes/crosspost

Version:

A utility to post across multiple social networks.

141 lines (140 loc) 3.64 kB
/** * Truncates a URL to 27 characters, ensuring the last three characters are '...'. * If the provided URL is 27 characters or shorter, it's returned unchanged. * @param {string} url The URL to truncate. * @returns {string} The truncated URL (27 chars) or the original if shorter. */ export function truncateUrl(url: string): string; /** * Detects rich text facets in the given text. * This function first detects URLs and replaces them with truncated * representations for further detection of tags and mentions. It returns an * object containing the detected facets (with byte ranges calculated against * the original text) and the updated text where URLs are truncated. * @param {string} text The text to search. * @returns {{facets: Array<BlueSkyFacet>, text: string}} An object with `facets` (array of BlueSkyFacet) * and `text` (the text with URLs replaced by truncated versions). */ export function detectFacets(text: string): { facets: Array<BlueSkyFacet>; text: string; }; export const BLUESKY_URL_FACET: "app.bsky.richtext.facet#link"; export const BLUESKY_TAG_FACET: "app.bsky.richtext.facet#tag"; export const BLUESKY_MENTION_FACET: "app.bsky.richtext.facet#mention"; export type ByteRange = { /** * The byte offset of the start of the range. */ byteStart: number; /** * The byte offset of the end of */ byteEnd: number; }; export type URIDetails = { /** * The URI of the facet. */ uri: string; /** * The byte range of the facet in the text. */ byteRange: ByteRange; }; export type TagDetails = { /** * The tag of the facet. */ tag: string; /** * The byte range of the facet in the text. */ byteRange: ByteRange; }; export type MentionDetails = { /** * The handle of the mentioned user. */ handle: string; /** * The byte range of the facet in the text. */ byteRange: ByteRange; }; export type BlueSkyFacet = { /** * The byte range of the facet in the text. */ index: ByteRange; /** * The features of the facet. */ features: Array<BlueSkyURIFacetFeature | BlueSkyTagFacetFeature | BlueSkyMentionFacetFeature>; }; /** * A Bluesky URI facet feature. */ declare class BlueSkyURIFacetFeature { /** * Creates a new instance. * @param {string} uri The URI of the facet. */ constructor(uri: string); /** * The URI of the facet. * @type {string} */ uri: string; /** * The type of facet. * @type {string} * @const */ $type: string; } /** * A Bluesky tag facet feature. */ declare class BlueSkyTagFacetFeature { /** * Creates a new instance. * @param {string} tag The tag of the facet. */ constructor(tag: string); /** * The tag of the facet. * @type {string} */ tag: string; /** * The type of facet. * @type {string} * @const */ $type: string; } /** * A Bluesky mention facet feature. */ declare class BlueSkyMentionFacetFeature { /** * Creates a new instance. * @param {string} did The DID of the mentioned user (initially the handle, resolved by the strategy). */ constructor(did: string); /** * The DID of the mentioned user. * Note: When created by detectMentions(), this initially contains the handle. * The BlueSky strategy resolves handles to actual DIDs before posting. * @type {string} */ did: string; /** * The type of facet. * @type {string} * @const */ $type: string; } export {};