@openrtb/macro-replacer
Version:
TypeScript macro replacer library compliant with OpenRTB 2.6/3.0
45 lines (42 loc) • 1.15 kB
text/typescript
type Version = "3" | "2" | "both";
type MacroReplacerFn = (context: MacroContext) => string;
interface MacroContext {
id?: string;
bidId?: string;
itemId?: string;
seatId?: string;
price?: number;
currency?: string;
mbr?: number;
loss?: number;
minToWin?: number;
mediaId?: string;
itemQty?: number;
adId?: string;
multiplier?: number;
impTs?: number;
}
declare class MacroReplacer {
private readonly macroMap;
private context;
private version;
constructor(initialContext?: Partial<MacroContext>, version?: "3" | "2" | "both");
private initializeMacroMap;
/**
* Update the context with new values
*/
updateContext(newContext: Partial<MacroContext>): void;
/**
* Replace macros in the input string
*/
replace(input: string, context?: Partial<MacroContext>): string;
/**
* Get supported macro names for current version
*/
getSupportedMacros(): string[];
/**
* Get current context values
*/
getContext(): MacroContext;
}
export { type MacroContext, MacroReplacer, type MacroReplacerFn, type Version };