UNPKG

safelinkify

Version:

NodeJS anonymizer external links into outbound page. Anonymize external links to outbound page redirector for SEO.

104 lines (98 loc) 2.96 kB
type parseQueryResult = { [key: string]: any; } | string; /** * Parse Query URL and Hash * @param query query key, null = return all objects * @param url target query, ex: {@link location.href} or {@link location.search} */ declare function parseQuery$1(query: Nullable<string>, url: Nullable<string>): Nullable<parseQueryResult>; /** * Auto resolve url * * parse base64, aes * @param url url string or instance, null = {@link window.location.search} * @param passphrase aes password * @returns */ declare function resolveQueryUrl$1(url?: string | URL, passphrase?: string, debug?: boolean): any; type HTMLElement = globalThis.HTMLElement; declare class safelink$1 { options: Required<SafelinkOptions>; constructor(opt?: Partial<SafelinkOptions>); parseQuery: typeof parseQuery$1; /** * is url excluded * @param url * @returns */ isExcluded(url: string | URL): boolean; /** * parse html string or element to anonymize urls * @param target * @returns */ parse(target: Nullable<string> | HTMLElement | Buffer | NodeJS.ReadStream): Promise<string | null>; /** * parse single url * @param url * @returns return redirect url or original url * * when redirect not set, will return encoded URL only */ parseUrl(url: string): string | null; /** * anonymize url directly * @param href */ encodeURL(href: string): any; /** * Resolve query url to decrypt anonymized urls (page redirector) * @param search * @returns */ resolveQueryUrl(search?: string): any; } /** * safelink options */ interface SafelinkOptions { exclude: string[] | RegExp[] | (string | RegExp)[]; redirect?: string[] | string; password: string; verbose?: boolean; type: string | 'base64' | 'aes'; } type Nullable<T> = T | null | undefined; interface encryptionURLResult { aes: { encode: Nullable<string>; encode_redirector: Nullable<string>; decode: Nullable<string>; passphrase: string; }; base64: { encode_redirector: Nullable<string>; encode: Nullable<string>; decode: Nullable<string>; }; value: Nullable<string>; } interface resolveQueryResult { [key: string]: encryptionURLResult; } declare const vars: { safelink: typeof safelink$1; parseQuery: typeof parseQuery$1; resolveQueryUrl: typeof resolveQueryUrl$1; }; declare const resolveQueryUrl: typeof resolveQueryUrl$1; declare const parseQuery: typeof parseQuery$1; declare const safelink: typeof safelink$1; declare global { interface Window { safelink: typeof vars.safelink; parseQuery: (typeof vars)['parseQuery']; resolveQueryUrl: (typeof vars)['resolveQueryUrl']; } } export { vars as default, parseQuery, resolveQueryUrl, safelink }; export type { Nullable, SafelinkOptions, encryptionURLResult, resolveQueryResult };