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

word-freq-list

v1.0.1

Published

A CLI tool to count word frequencies in a text file.

Downloads

146

Readme

word-freq-list

word-freq-list is a Node.js command-line tool that helps you quickly analyze the word frequency in a text file. Designed with simplicity and efficiency in mind, word-freq-list can count the occurrences of each word or focus on a specific word of interest. This tool provides an example of Node.js file handling and string manipulation and is useful for anyone working with text analysis, data processing, or learning Node.js.

Features

  • Count All Words: Calculate the frequency of every unique word in a file.
  • Targeted Word Count: Specify a word to get its count, ignoring all other words.
  • Case Insensitive: Counts words in a case-insensitive manner to ensure accurate results.
  • Easy to Use: Simple CLI tool that can be installed and run in seconds.

Installation

To use word-freq-list, you have two options: using npx directly, or installing it globally.

Option 1: Run with npx

npx word-freq-list <filename> [targetWord]

Option 2: Install Globally

  • Install it globally to use as a regular command:
npm install -g word-freq-list
  • Then you can run:
word-freq-list <filename> [targetWord]

Usage

  • The command-line tool expects a file path and, optionally, a word to look for:
word-freq-list <filename> [targetWord]
  • filename : (Required) Path to the text file you want to analyze.
  • targetWord: (Optional) Specify a word to count its occurrences. If omitted, word-freq-list will display a frequency map of all words in the file.

Examples

  • Example 1: Count All Words
  • Count all words in a text file called sample.txt:
npx word-freq-list sample.txt
  • Output
{
  "node": 3,
  "javascript": 5,
  "cli": 2,
  "tool": 4
}
  • Example 2: Count a Specific Word
  • To count how many times the word "javascript" appears in sample.txt:
npx word-freq-list sample.txt example
  • Output
{
  "example": 7
}

How It Works

  1. The tool reads the file provided in the arguments using Node.js’s fs/promises module.

  2. It splits the text into words based on non-word characters, making it easy to handle punctuation.

  3. If a targetWord is provided, it counts only that word (case insensitive). Otherwise, it returns a frequency count of each unique word in the file.

Contributing

  • Contributions are welcome! If you have ideas for improving this tool, feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License. See LICENSE for more information.

Be sure to name the file `README.md` and place it in your project root folder for the formatting to be rendered correctly. GitHub and most Markdown editors should automatically recognize and display the formatting once it’s in a `.md` file.