advanced-search-query
Version:
Another parser for advanced search query syntax.
53 lines (52 loc) • 1.69 kB
TypeScript
declare type Value = string;
declare type Keyword = {
name: string;
value: Value;
isNegated: boolean;
};
declare type Text = {
value: string;
isNegated: boolean;
};
declare type TransformTextToKeyword = (text: string) => Keyword | null;
declare type ParsedQuery = {
text: {
include: Value[];
exclude: Value[];
};
keywords: Record<string, {
include: Value[];
exclude: Value[];
}>;
};
export declare class AdvancedSearchQuery {
keywords: Keyword[];
texts: Text[];
input: string;
output: string | undefined;
isDirty: boolean;
/**
* Not intended for public use. API could change.
*/
constructor(keywords: Keyword[], texts: Text[]);
getText(): string;
getTexts(): Text[];
getKeywords(): Record<string, Omit<Keyword, 'name'>[]>;
getKeyword(name: string): Pick<Keyword, "value" | "isNegated">[];
toObject(): ParsedQuery;
addKeyword(name: string, value: Value, isNegated?: boolean): this;
removeKeywords(): this;
removeKeyword(name: string, value?: Value, isNegated?: boolean): this;
addText(value: Value, isNegated?: boolean): this;
removeText(value: Value, isNegated?: boolean): this;
removeTexts(): this;
clone(): AdvancedSearchQuery;
toString(): string;
}
/**
* @param {String} string to parse e.g. 'to:me -from:joe@acme.com foobar'.
* @param {Array} transformTextToConditions Array of functions to transform text into conditions
* @returns {AdvancedSearchQuery} An instance of class AdvancedSearchQuery.
*/
export default function (input?: string, transformTextToKeywords?: TransformTextToKeyword[]): AdvancedSearchQuery;
export {};