UNPKG

hd-utils

Version:

A handy utils for modern JS developers

26 lines (21 loc) 833 B
/** Function that count occurrences count of a substring in a string; * @param {String} string The string * @param {String} subString The sub string to search for * @param {Boolean} [allowOverlapping] Optional. (Default:false) * * @example ` * occurrencesCount("foofoofoo", "bar"); //0 occurrencesCount("foofoofoo", "foo"); //3 occurrencesCount("foofoofoo", "foofoo"); //1 //allowOverlapping:true occurrencesCount("foofoofoo", "foofoo", true); //2 foofoofoo 1`----´ 2 `----´ * ` * * @author Vitim.us https://gist.github.com/victornpb/7736865 * @see Unit Test https://jsfiddle.net/Victornpb/5axuh96u/ * @see https://stackoverflow.com/a/7924240/938822 */ export default function occurrencesCount(string: string, subString: string, allowOverlapping?: boolean): number;