1.3.0 • Published 3 years ago

@tyah/count-words v1.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Count Words

A lightweight vanilla javascript app to count the occurance of a word or a phrase in a string.

Installation

npm i @tyah/count-words
  • Cloning repository
git clone https://github.com/gumbol/count-words

Usage

  • CommonJS:
const countWords = require("path/to/count-words")
  • ES modules for the browser: You'd need to comment module.exports in count-words.js and uncomment exports default.
//module.exports = (string, word) =>
export default (string, word) =>
<script type="module">
import countWords from "./path/to/count-words/count-words.js"
</script>

example

console.log(countWords("fooBarFOobazBar fOo f   oo   F   oO", "fobar"))
// -> No match

console.log(countWords("fooBarFOobazBar fOo f   oo   F   oO", "f   oo"))
// -> 2

console.log(countWords("fooBarFOobazBar fOo f   oo   F   oO", "fooBaz"))
// -> 1

Acknowledgement

Inspired by exercises from Eloquent Javascript book by Marijn Haverbeke