npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

text-count

v1.1.0

Published

information of string(text)

Downloads

41

Readme

text-count

This is a simple JavaScript utility for analyzing text. It provides functions to count characters, words, sentences, and lines in a given text.

Table of Contents

  1. Introduction
  2. Installation
  3. Features
  4. Usage

Introduction:

This is a simple JavaScript utility for analyzing text. It provides functions to count characters, words, sentences, and lines in a given text.

Installation:

  •   npm install text-count

Features:

  • count number of lines in a given text or in a file.
  • count number of words.
  • count total characters.
  • count sentences in given text.
  • count most common words.
  • most common characters.

Usage:

You can use this package in both Command Line Interface (CLI) mode and non-CLI mode.

CLI Mode

In CLI mode, you can use the following commands:

  • char <text>: Count characters in the provided text.
  • word <text>: Count words in the provided text.
  • sen <text>: Count sentences in the provided text.
  • line <text>: Count lines in the provided text.
  • most-common-char <text> [limit]: Find the most common characters in the provided text (optional: specify limit, default is 5).
  • most-common-words <text> [limit]: Find the most common words in the provided text (optional: specify limit, default is 5).
  • -f <option> <filepath> [limit]: Read text from a file and perform the specified operation: word, char, line, sen, most-common-word, or most-common-char.

For Example:

    count char "Hello, World!"
# Output: 13

    count word "Hello, World!"
# Output: 2

    count sen "Hello. World!"
# Output: 2

    count line "Hello,\nWorld!"
# Output: 2

    count most-common-char "Hello, World!"
# Output: { 'l': 3, 'o': 2, 'H': 1, 'e': 1, ',': 1 }


    count most-common-char "Hello, World!" 2
# Output: { 'l': 3, 'o': 2}

    count most-common-words "Hello, World!" 1
# Output: { 'Hello': 1 }

    count -f word file.txt
# Output: [word count from the file]

    count -f most-common-char file.txt
# Output: { 'l': 3, 'o': 2, 'H': 1, 'e': 1, ',': 1 }

    count -f most-common-char file.txt 2
# Output: { 'l': 3, 'o': 2 }

Non-CLI Mode

You can also use the functions directly in your Node.js code:

    const count= require('text-count');

// Example usage:
console.log(count.charCount("Hello, World!")); // Output: 13
console.log(count.wordCount("Hello, World!")); // Output: 2
console.log(count.mostCommonChar("Hello, World!",3)); // Output: { 'l': 3, 'o': 2, 'H': 1}
console.log(count.mostCommonWords("Hello, World!")); // Output: { 'Hello': 1, 'World': 1 }
console.log(count.lineCount("Hello,\nWorld!\n")); // Output: 2
console.log(count.senCount("Hello. World!")); // Output: 2