@enspirit/emb
Version:
A replacement for our Makefile-for-monorepos
38 lines (37 loc) • 1.15 kB
TypeScript
/**
* An async source is a function that returns a promise resolving to the value.
*/
type AsyncSource = (key: string) => Promise<unknown>;
/**
* A static source is a simple key-value record.
*/
type StaticSource = Record<string, unknown>;
/**
* A source can be either static or async.
*/
type Source = AsyncSource | StaticSource;
type ExpandOptions = {
default?: string;
sources?: Record<string, Source>;
};
export type ExpansionHistory = {
source: string;
value: unknown;
variable: string;
};
export type Expandable = readonly Expandable[] | string | {
readonly [k: string]: Expandable;
};
type ExpandResult<T> = T extends string ? string : T extends readonly (infer U)[] ? ReadonlyArray<ExpandResult<U>> : T extends {
readonly [K in keyof T]: Expandable;
} ? {
readonly [K in keyof T]: ExpandResult<T[K]>;
} : T;
export declare class TemplateExpander {
private expansions;
get expansionCount(): number;
expand(str: string, options?: ExpandOptions): Promise<string>;
expandRecord<T extends Expandable>(record: T, options: ExpandOptions): Promise<ExpandResult<T>>;
private track;
}
export {};