1.0.0 • Published 3 years ago

word-frequency-basic v1.0.0

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

word-frequency-basic

NPM

Single function code block for finding the number of repeating words in a text.

Install

yarn add word-frequency-basic

or

npm i word-frequency-basic

Usage

ParametersTypeDefaultDescription
textstringnullThe text to be split into words
caseSensitivebooleantrueAllows you to count by paying attention to whether the letters are big or small.
letter"normal" / "upperCase" / "lowerCase""normal"Words can be output in uppercase, lowercase or normal letters.
noPunctuationbooleantrueDetermines whether to remove punctuation marks.
import numberOfWords from "word-frequency-basic"

numberOfWords(text, caseSensitive, letter, noPunctuation)

Examples

import numberOfWords from "word-frequency-basic"

const text = "Hello world, count my words, hello again."

// Example 1
console.log(numberOfWords(text))

/* Output 1
{
  "Hello": 1,
  "world": 1,
  "count": 1,
  "my": 1,
  "words": 1,
  "hello": 1,
  "again": 1
}
*/

// Example 2
console.log(numberOfWords(text, false))

/* Output 2
{
  "hello": 2,
  "world": 1,
  "count": 1,
  "my": 1,
  "words": 1,
  "again": 1
}
*/

// Example 3
console.log(numberOfWords(text, true, "upperCase"))

/* Output 3
{
  "HELLO": 1,
  "WORLD": 1,
  "COUNT": 1,
  "MY": 1,
  "WORDS": 1,
  "AGAIN": 1
}
*/

// Example 4
console.log(numberOfWords(text, true, "normal", false))

/* Output 4
{
  "hello": 1,
  "world,": 1,
  "count": 1,
  "my": 1,
  "words,": 1,
  "again.": 1
}
*/
1.0.0

3 years ago

0.0.2

5 years ago

0.0.1

5 years ago