Tumortisch-Dist/resources/app/node_modules/es5-ext/string/#/count.js

16 lines
399 B
JavaScript
Raw Permalink Normal View History

2021-06-15 16:00:08 +02:00
"use strict";
var ensureString = require("../../object/validate-stringifiable-value");
module.exports = function (search) {
var string = ensureString(this), count = 0, index = 0;
search = ensureString(search);
if (!search) throw new TypeError("Search string cannot be empty");
while ((index = string.indexOf(search, index)) !== -1) {
++count;
index += search.length;
}
return count;
};