UNPKG

@socketsecurity/lib

Version:

Core utilities and infrastructure for Socket.dev security tools

66 lines (65 loc) 2.03 kB
import type { Theme } from '../themes/types'; import type { ThemeName } from '../themes/themes'; /** * Options for creating themed links. */ export type LinkOptions = { /** Theme to use (overrides global) */ theme?: Theme | ThemeName | undefined; /** Show URL as fallback if terminal doesn't support links */ fallback?: boolean | undefined; }; /** * Create a themed hyperlink for terminal output. * The link text is colored using the theme's link color. * * Note: Most terminals support ANSI color codes but not clickable links. * This function colors the text but does not create clickable hyperlinks. * For clickable links, use a library like 'terminal-link' separately. * * @param text - Link text to display * @param url - URL (included in fallback mode) * @param options - Link configuration options * @returns Colored link text * * @example * ```ts * import { link } from '@socketsecurity/lib/links' * * // Use current theme * console.log(link('Documentation', 'https://socket.dev')) * * // Override theme * console.log(link('API Docs', 'https://api.socket.dev', { * theme: 'coana' * })) * * // Show URL as fallback * console.log(link('GitHub', 'https://github.com', { * fallback: true * })) * // Output: "GitHub (https://github.com)" * ``` */ export declare function link(text: string, url: string, options?: LinkOptions): string; /** * Create multiple themed links from an array of link specifications. * * @param links - Array of [text, url] pairs * @param options - Link configuration options * @returns Array of colored link texts * * @example * ```ts * import { links } from '@socketsecurity/lib/links' * * const formatted = links([ * ['Documentation', 'https://socket.dev'], * ['API Reference', 'https://api.socket.dev'], * ['GitHub', 'https://github.com/SocketDev'] * ]) * * formatted.forEach(link => console.log(link)) * ``` */ export declare function links(linkSpecs: Array<[text: string, url: string]>, options?: LinkOptions): string[];