UNPKG

@technobuddha/library

Version:
25 lines (24 loc) 738 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.count = void 0; /** * Compute the number of times a substring occors within a string * * @param input The string * @param supstring The substring to look for * @param __namedParameters see {@link Options} * @return number of times *substring* occurs within *input* */ function count(input, substring, _a) { var _b = _a === void 0 ? {} : _a, _c = _b.overlap, overlap = _c === void 0 ? false : _c; var step = overlap ? 1 : substring.length; var cnt = 0; var pos = 0; while ((pos = input.indexOf(substring, pos)) >= 0) { cnt++; pos += step; } return cnt; } exports.count = count; exports.default = count;