Options
All
  • Public
  • Public/Protected
  • All
Menu

Word counting

styled with prettier Commitizen friendly All Contributors

NPM Version License Stats Downloads Stats Github stars Github issues Github Actions workflow codecov Dev Dependencies

Donate

A very powerful words counter that supports plain text and html.

nodei.co

Why this project

  • Support node and browser environment.
  • Support html formated text. (Won't count tags)
  • Well typed

Installation

# Using npm
npm install --save word-counting

# Using yarn
yarn add word-counting

Basic Usage

Inject the library in your file:

// javascript
var wordsCounter = require('word-counting')
// typescript
import wordsCounter from 'word-counting'

Count the words for plain text:

const mockedText = 'These are some mocked words.'
console.log(wordsCounter(mockedText).wordsCount) // 5

Count the words for html:

const mockedText = '<p>These are some mocked words with html format</p>'
console.log(wordsCounter(mockedText, { isHtml: true }).wordsCount) // 8

Contributing

Feel free to make any improvements or changes. Any changes will be appreciated and I'll add you to the contributors list below. :)

  1. Fork it (https://github.com/nerdmax/word-counting/fork)
  2. Create your feature branch. (git checkout -b feature/fooBar)
  3. Make some changes.
  4. State your changes. (git add .)
  5. Commit your changes (yarn commit). NOTE: This repo is following the conventional commits, and yarn commit is the easiest way to construct the commit message.
  6. Push to the branch. (git push origin feature/fooBar)
  7. Create a new Pull Request.

Contributors


Max Liu

💻 📖 🚇 ⚠️

Pepe Sosa

🐛

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

Index

Interfaces

Variables

Functions

Variables

Const htmlToText

htmlToText: any = require('html-to-text')

Const regex

regex: any = require('word-regex')

Functions

Const wordsCounter

  • The function that can count the words occurrence in text

    Parameters

    • text: string

      The string that you want to count words

    • Optional config: Config

      The config settings for the wordsCounter function

    Returns Result

    an object that has the words occurrence information

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc