UNPKG

@google-translate-select/utils

Version:

🚀 The package offer utils for @google-translate-select!

184 lines (173 loc) • 7.01 kB
interface CreateGoogleTranslateJsonpCallbackOptions { pageLanguage: string; /** * google translate auto display original dom * * @default false */ autoDisplay?: boolean; } declare function createGoogleTranslateJsonpCallback(options: CreateGoogleTranslateJsonpCallbackOptions, cb: (...args: any[]) => any): { jsonpCallbackName: string; }; type CreateGoogleTranslateJsonpCallbackReturn = ReturnType<typeof createGoogleTranslateJsonpCallback>; declare function GoogleTranslateFireEvent(GOOGLE_TRANSLATE_ORIGINAL_SELECT_DOM: HTMLElement, eventName?: string): void; interface ConfigurableWindow { window?: Window; } interface ConfigurableDocument { document?: Document; } interface ConfigurableNavigator { navigator?: Navigator; } interface ConfigurableLocation { location?: Location; } declare const defaultWindow: (Window & typeof globalThis) | undefined; declare const defaultDocument: Document | undefined; declare const defaultNavigator: Navigator | undefined; declare const defaultLocation: Location | undefined; declare function setCookie(name: string, val: string | number, expires: number, domain: string): void; declare function getCookie(name: string): string | undefined; interface UseMutationObserverOptions extends MutationObserverInit, ConfigurableWindow { } /** * Watch for changes being made to the DOM tree. * * @see https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver MutationObserver MDN * @param target * @param callback * @param options */ declare function useMutationObserver(target: HTMLElement, callback: MutationCallback, options?: UseMutationObserverOptions): { isSupported: boolean; start: () => void; stop: () => void; }; type UseMutationObserverReturn = ReturnType<typeof useMutationObserver>; interface CreateScriptTagOptions extends ConfigurableDocument { /** * Load the script immediately * * @default true */ immediate?: boolean; /** * Script type * * @default 'text/javascript' */ type?: string; /** * Add `async` attribute to the script tag * */ async?: boolean; /** * Add `defer` attribute to the script tag * */ defer?: boolean; crossOrigin?: 'anonymous' | 'use-credentials'; /** * Add custom attribute to the script tag * */ attrs?: Record<string, string>; } /** * Inject <script> element in body. * * @param src * @param onLoaded * @param options */ declare function createScriptTag(src: string, onLoaded?: (el: HTMLScriptElement) => void, options?: CreateScriptTagOptions): { scriptTag: null; load: (waitForScriptLoad?: boolean) => Promise<HTMLScriptElement | boolean>; unload: () => void; }; type CreateScriptTagReturn = ReturnType<typeof createScriptTag>; declare function removeIcon(): void; interface CreateStyleTagOptions extends ConfigurableDocument { /** * Load the style immediately * * @default true */ immediate?: boolean; /** * DOM id of the style tag * * @default auto-incremented */ id?: string; } interface CreateStyleTagReturn { id: string; css: string; isLoaded: Readonly<boolean>; load: () => void; unload: () => void; } /** * Inject <style> element in head. * * @param css * @param options */ declare function createStyleTag(css: string, options?: CreateStyleTagOptions): CreateStyleTagReturn; declare function throwError(scope: string, m: string): never; declare function throwWarn(err: Error): void; declare function throwWarn(scope: string, message: string): void; declare const createNamespace: (block: string) => { namespace: string; n: string; b: (blockSuffix?: string) => string; e: (element?: string) => string; m: (modifier?: string) => string; be: (blockSuffix?: string, element?: string) => string; em: (element?: string, modifier?: string) => string; bm: (blockSuffix?: string, modifier?: string) => string; bem: (blockSuffix?: string, element?: string, modifier?: string) => string; is: { (name: string, state: boolean | undefined): string; (name: string): string; }; cssVar: (object: Record<string, string>) => Record<string, string>; cssVarName: (name: string) => string; cssVarBlock: (object: Record<string, string>) => Record<string, string>; cssVarBlockName: (name: string) => string; }; type CreateNamespaceReturn = ReturnType<typeof createNamespace>; declare const camelize: (str: string) => string; declare const capitalize: <T extends string>(str: T) => Capitalize<T>; declare const escapeStringRegexp: (string?: string) => string; declare const hyphenate: (str: string) => string; declare const objectToString: () => string; declare const is: (value: unknown, type: string) => boolean; declare const isArray: (arg: any) => arg is any[]; declare const isMap: (val: unknown) => val is Map<any, any>; declare const isSet: (val: unknown) => val is Set<any>; declare const isBoolean: (val: unknown) => val is Boolean; declare const isNumber: (val: unknown) => val is Number; declare const isDate: (val: unknown) => val is Date; declare const isFunction: (val: unknown) => val is Function; declare const isString: (val: unknown) => val is string; declare const isSymbol: (val: unknown) => val is symbol; declare const isObject: (val: unknown) => val is Record<any, any>; declare const isPlainObject: (val: unknown) => val is object; declare const isPromise: <T = any>(val: unknown) => val is Promise<T>; declare const isDef: (val: any) => val is undefined; declare const isUndef: (val: any) => val is undefined; declare const isRegExp: (val: unknown) => val is RegExp; declare const isEmpty: (val: unknown) => boolean; declare const isElement: (e: unknown) => e is Element; declare function isUrl(path: string): boolean; declare const isWindow: (val: any) => val is Window; declare const isServer: boolean; declare const isClient: boolean; declare const noop: () => void; declare const isSupport: (callback: () => unknown) => boolean; export { ConfigurableDocument, ConfigurableLocation, ConfigurableNavigator, ConfigurableWindow, CreateGoogleTranslateJsonpCallbackOptions, CreateGoogleTranslateJsonpCallbackReturn, CreateNamespaceReturn, CreateScriptTagOptions, CreateScriptTagReturn, CreateStyleTagOptions, CreateStyleTagReturn, GoogleTranslateFireEvent, UseMutationObserverOptions, UseMutationObserverReturn, camelize, capitalize, createGoogleTranslateJsonpCallback, createNamespace, createScriptTag, createStyleTag, defaultDocument, defaultLocation, defaultNavigator, defaultWindow, escapeStringRegexp, getCookie, hyphenate, is, isArray, isBoolean, isClient, isDate, isDef, isElement, isEmpty, isFunction, isMap, isNumber, isObject, isPlainObject, isPromise, isRegExp, isServer, isSet, isString, isSupport, isSymbol, isUndef, isUrl, isWindow, noop, objectToString, removeIcon, setCookie, throwError, throwWarn, useMutationObserver };