Skip to content

gumbol/count-words

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

count the occurance of a word in a string

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published