@tyah/count-words

1.3.0 • Public • Published

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

Package Sidebar

Install

npm i @tyah/count-words

Weekly Downloads

1

Version

1.3.0

License

MIT

Unpacked Size

4.27 kB

Total Files

7

Last publish

Collaborators

  • tyah