occurrences

Count the occurrences of a substring within a string and keep track of each occurrence's position.

Occurrences

Count the occurrences of a substring within a string and keep track of each occurrence's position.

$ npm install occurrences
var occurrences = require('occurrences');
 
occurrences('foobar', 'o', function(result) {
  console.log('Occurrences: ' + result.count);
  console.log('Positions of each occurrence: ' + result.positions);
});
$ cd example
$ node demo.js
$ npm install
$ make test