custom-string-formatter
Version:
Customizable String Formatter
55 lines (54 loc) • 1.42 kB
TypeScript
import { IFormatter } from './protocol';
/**
* Returns a function that formats a string from an object-parameter, and according to the specified configurator.
*
* @returns
* A function to format strings from object-parameter.
*/
export declare function createFormatter(base: IFormatter): (text: string, params: {
[key: string]: any;
}) => string;
/**
* A fast check if a string has variables in it.
*
* @returns
* Boolean flag, indicating if the string has variables in it.
*/
export declare function hasVariables(text: string): boolean;
/**
* A fast count of variables in a string.
*
* @returns
* Number of variables in the string.
*/
export declare function countVariables(text: string): number;
/**
* Variable descriptor, as returned from {@link enumVariables} function.
*/
export interface IVariable {
/**
* Exact enumeration match for the variable.
*/
match: string;
/**
* Extracted property name.
*/
property: string;
/**
* Extracted filters with raw arguments (not decoded).
*/
filters: Array<{
name: string;
args: string[];
}>;
}
/**
* Enumerates and parses variables from a string, for any kind of reference analysis.
*
* @param text
* Text string with variables.
*
* @returns IVariable[]
* An array of matched variables (as descriptors)
*/
export declare function enumVariables(text: string): IVariable[];