Socket
Socket
Sign inDemoInstall

word-frequency-basic

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    word-frequency-basic

Finding the number of repeating words in a text


Version published
Maintainers
1
Install size
3.17 kB
Created

Readme

Source

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
}
*/

Keywords

FAQs

Last updated on 18 Jan 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc