UNPKG

@unitio-code/url-shortener

Version:
32 lines (31 loc) 1.39 kB
import { ShortUrlOptions, StorageInterface } from "./utils"; /** * Options for creating a short URL * @property hashAlgorithm - Hash algorithm to use (default: 'djb2') * @property customHashFn - Custom hash function * @property storage - Storage instance to use (default: MemoryStorage) * @property ttl - Time to live in seconds * @property maxRetries - Maximum retries for collision handling (default: 10) */ export interface CreateShortUrlOptions extends ShortUrlOptions { hashAlgorithm?: "djb2" | "sdbm" | "custom"; customHashFn?: (url: string) => number; storage?: StorageInterface; ttl?: number; maxRetries?: number; } /** * Creates a short URL from a long URL with customizable options * @param longUrl - The original long URL to shorten * @param domain - Domain name for the short URL * @param options - Optional configuration options * @returns The shortened URL */ export declare function createShortUrl(longUrl: string, domain: string, options?: Partial<Omit<CreateShortUrlOptions, "domain">>): Promise<string>; /** * Decodes a short URL back to its original URL * @param shortUrl - The shortened URL to decode * @param storage - Storage instance to use (optional) * @returns The original URL if found, or undefined if not found */ export declare function decodeUrl(shortUrl: string, storage?: StorageInterface): Promise<string | undefined>;