JSPM

quickly-count-substrings

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q49398F
  • License MIT

Fast module for counting the number of occurrences of a substring inside a string

Package Exports

  • quickly-count-substrings

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (quickly-count-substrings) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

quickly-count-substrings

Fast module for counting the number of occurrences of a substring inside a string.

Build status js-standard-style

Installation

npm install quickly-count-substrings --save

Usage

const count = require('quickly-count-substrings')

const str = 'The quick brown fox jumps over the lazy dog'

count(str, 'o') // => 4

API

result = count(str, substr[, options])

Returns number of occurrences of substr in str.

Arguments:

  • str - The string to search in
  • substr - The string to search for
  • options - Optional. If {overlap: true}, overlapping substrings will be counted (default: {overlap: false})

Benchmark

Counting substrings in a 24MB string:

# quickly-count-substrings
ok ~44 ms (0 s + 43676071 ns)

# count-substring
ok ~134 ms (0 s + 133563148 ns)

# string-occurrence
ok ~184 ms (0 s + 183978927 ns)

# needle-string
ok ~116 ms (0 s + 115521420 ns)

# regex-occurrence
ok ~169 ms (0 s + 169180879 ns)

# count-strings
ok ~491 ms (0 s + 490783663 ns)

License

MIT