UNPKG

@unicef-polymer/etools-unicef

Version:
121 lines (120 loc) 3.24 kB
import { ITranslateConfig, Values, ValuesCallback } from './types'; /** * A factory function that wraps get, translate and translateUnsafeHTML to make the keys typesafe. */ export declare function typedKeysFactory<Keys extends Record<string, unknown>>(): { get<T extends ObjectLookupString<Keys, 10, ".">>(key: T, values?: Values | ValuesCallback | null, config?: ITranslateConfig): string; translate<T_1 extends ObjectLookupString<Keys, 10, ".">>(key: T_1, values?: Values | ValuesCallback | null, config?: ITranslateConfig): import("lit-html/directive").DirectiveResult<typeof import("./directives/translate").TranslateDirective>; translateUnsafeHTML<T_2 extends ObjectLookupString<Keys, 10, ".">>(key: T_2, values?: Values | ValuesCallback | null, config?: ITranslateConfig): import("lit-html/directive").DirectiveResult<typeof import("./directives/translate-unsafe-html").TranslateUnsafeHTMLDirective>; }; export type ObjectLookupString<T, MaxDepth extends number = 10, Separator extends string = '.'> = ObjectLookupStringHelper<T, ``, MaxDepth, 0, Separator>; type SimpleValue = string | number | bigint | boolean | symbol | RegExp | Date | null | undefined; type IgnoredLookupValue = SimpleValue | CallableFunction | Set<unknown> | WeakSet<never> | Map<unknown, unknown> | WeakMap<never, unknown>; type MaybeSuffixWithSeparator<T extends string, Separator extends string = '.'> = T extends `` ? T : `${T}${Separator}`; type ObjectLookupStringHelper<T, Acc extends string, MaxDepth extends number, CurrentDepth extends number = 0, Separator extends string = '.'> = { [Key in keyof T]: Key extends string ? CurrentDepth extends MaxDepth ? `${MaybeSuffixWithSeparator<Acc, Separator>}${Key}` : T[Key] extends IgnoredLookupValue ? `${MaybeSuffixWithSeparator<Acc, Separator>}${Key}` : T[Key] extends (infer El)[] | readonly (infer El)[] ? `${MaybeSuffixWithSeparator<Acc, Separator>}${Key}${Separator}${number}` | El extends IgnoredLookupValue ? `${MaybeSuffixWithSeparator<Acc, Separator>}${Key}${Separator}${number}` : ObjectLookupStringHelper<El, `${MaybeSuffixWithSeparator<Acc, Separator>}${Key}${Separator}${number}`, MaxDepth, Next<CurrentDepth>> : `${MaybeSuffixWithSeparator<Acc, Separator>}${Key}` | ObjectLookupStringHelper<NonNullable<T[Key]>, `${MaybeSuffixWithSeparator<Acc, Separator>}${Key}`, MaxDepth, Next<CurrentDepth>> : never; }[keyof T]; export type Next<T extends number> = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101 ][T]; export {};