eliza-core
Version:
A rendition of ELIZA program engine by Weizenbaum sharable for all javascript environments
87 lines (86 loc) • 2.24 kB
TypeScript
/**
* Look for a match between the string and the pattern.
* Return matchingLength of matching characters before * and #.
* Return -1 if strings do not match.
*
* e.g: `pre: dont don't` `*pre: * *` ==> 0
* e.g: `pre: dont don't` `pre: * *` ==> 5
*
* @export
* @param {string} str
* @param {string} pat Pattern
*/
export declare function amatch(str: string, pat: string): number;
/**
* Search in successive positions of the string,
* looking for a match to the pattern.
* Return the start position in str of the match,
* or -1 for no match.
*
* Learned from `EString#findPat(String str, String pat)`
*
* @export
* @param {string} str
* @param {string} pat
* @returns
*/
export declare function findWildString(str: string, pat: string): number;
/**
* Look for a number in the string.
*
* @export
* @param {string} str
* @returns the length of numerical digits from the beginning,
* or `0` if the string does not start with number.
*/
export declare function findNum(str: string): number;
/**
* Check if the script line read match the given pattern
*
* @export
* @param {string} str line
* @param {string} pat Pattern
* @returns Matched script lines stored here
*/
export declare function match(str: string, pat: string): string[] | null;
/**
* Translates corresponding characters in src to dest.
* Src and dest must have the same length.
*
* @export
* @param {string} str
* @param {string} src
* @param {string} dest
* @returns
*/
export declare function replaceAll(str: string, src: string, dest: string): string;
/**
* Compresses its input by:
* dropping space before space, comma, and period;
* adding space before question, if char before is not a space; and
* copying all others
*
* @export
* @param {string} s
* @returns
*/
export declare function compress(s: string): string;
/**
* Trim off leading spaces
*
* @export
* @param {string} s
*/
export declare function trim(s: string): string;
/**
* Pad by ensuring there are spaces before and after the sentence.
*
* @export
* @param {string} s
* @returns
*/
export declare function pad(s: string): string;
/**
* Count number of occurrances of c in str
*/
export declare function count(s: string, c: string): number;