search-string
Version:
Another parser for advanced search query syntax.
88 lines • 3.16 kB
TypeScript
export interface Condition {
keyword: string;
value: string;
negated: boolean;
}
export interface TextSegment {
text: string;
negated: boolean;
}
export interface ParsedQuery {
[key: string]: any;
exclude: Record<string, string[]>;
}
/**
* **SearchString** is a parsed search string which allows you to fetch conditions
* and text being searched.
*/
export default class SearchString {
private conditionArray;
private textSegments;
private string;
private isStringDirty;
/**
* Not intended for public use. API could change.
*/
constructor(conditionArray: Condition[], textSegments: TextSegment[]);
/**
* @param str - String to parse e.g. `'to:me -from:joe@acme.com foobar'`.
* @param transformTextToConditions - Array of functions to transform text into conditions.
* @returns An instance of the **SearchString** class.
*/
static parse(str: string, transformTextToConditions?: Array<(text: string) => {
key: string;
value: string;
}>): SearchString;
/**
* @returns Conditions array, may contain multiple conditions for a particular key.
*/
getConditionArray(): Condition[];
/**
* @returns Map of conditions and includes a special key `'exclude'`.
* `'exclude'` itself is a map of conditions which were negated.
*/
getParsedQuery(): ParsedQuery;
/**
* @returns All text segments concatenated together joined by a space.
* If a text segment is negated, it is preceded by a `-`.
*/
getAllText(): string;
/**
* @returns All text segment objects, negative or positive.
* E.g., `{ text: 'foobar', negated: false }`
*/
getTextSegments(): TextSegment[];
/**
* Removes keyword-negated pair that matches inputted.
* Only removes if entry has same keyword/negated combo.
* @param keywordToRemove - Keyword to remove.
* @param negatedToRemove - Whether or not the keyword removed is negated.
*/
removeKeyword(keywordToRemove: string, negatedToRemove: boolean): void;
/**
* Adds a new entry to search string. Does not dedupe against existing entries.
* @param keyword - Keyword to add.
* @param value - Value for respective keyword.
* @param negated - Whether or not keyword/value pair should be negated.
*/
addEntry(keyword: string, value: string, negated: boolean): void;
/**
* Removes an entry from the search string. If more than one entry with the same settings is found,
* it removes the first entry matched.
*
* @param keyword - Keyword to remove.
* @param value - Value for respective keyword.
* @param negated - Whether or not keyword/value pair is negated.
*/
removeEntry(keyword: string, value: string, negated: boolean): void;
/**
* @returns A new instance of this class based on current data.
*/
clone(): SearchString;
/**
* @returns Returns this instance synthesized to a string format.
* Example string: `'to:me -from:joe@acme.com foobar'`
*/
toString(): string;
}
//# sourceMappingURL=searchString.d.ts.map