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

use-text-analyzer

v2.1.2

Published

A React hook for analyzing text.

Downloads

87

Readme

Installation 🛠️

npm

npm install use-text-analyzer

yarn

yarn add use-text-analyzer

Features ✨

  • Lightweight 🪶: 1KB in size, making it lightweight and efficient.
  • TypeScript Support 🇹🇸: Works seamlessly with both JavaScript and TypeScript projects.
  • Advanced Reading Time Estimation 🕒: Provides detailed reading time estimates in minutes and seconds, along with a human-readable format for immediate use in interfaces.
  • Efficient Algorithms ⚡: Utilizes efficient algorithms for finding the most and least frequent words/characters.
  • CJK Support 📜: Enhanced support for texts in Chinese, Japanese, and Korean, ensuring accurate analysis across these languages.
  • SSR Compatible 🌐: Fully compatible with server-side rendering, ensuring reliable performance across server and client environments.

Usage 📝

import React from 'react';
import useTextAnalyzer from 'use-text-analyzer';

function TextAnalyzerExample() {
  const text =
    'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.';
  const searchTerm = 'Lorem';

  const {
    wordCount,
    charCount,
    sentenceCount,
    paragraphCount,
    searchFrequency,
    readingTime,
    mostFrequentWord,
    leastFrequentWord,
    mostFrequentCharacter,
    leastFrequentCharacter,
  } = useTextAnalyzer({ text, searchTerm });

  return (
    <div>
      <h2>Text Analysis Result</h2>
      <p>
        Estimated reading time: {readingTime.minutes}m {readingTime.seconds}s
      </p>
      <p>Total reading time in seconds: {readingTime.total}</p>
      <p>Human-readable reading time: {readingTime.text}</p>
      <p>
        Search frequency of '{searchTerm}': {searchFrequency}
      </p>
      <p>Word count: {wordCount}</p>
      <p>Character count: {charCount}</p>
      <p>Sentence count: {sentenceCount}</p>
      <p>Paragraph count: {paragraphCount}</p>
      <p>Most frequent word: {mostFrequentWord}</p>
      <p>Least frequent word: {leastFrequentWord}</p>
      <p>Most frequent character: {mostFrequentCharacter}</p>
      <p>Least frequent character: {leastFrequentCharacter}</p>
    </div>
  );
}

export default TextAnalyzerExample;

API ⚙️

useTextAnalyzer(options: TextAnalyzerOptions): TextAnalysisResult

A React hook that analyzes the given text and returns various statistics about it.

Parameters

  • options (TextAnalyzerOptions, required): An object containing options for text analysis.
    • text (string, required): The text to analyze.
    • searchTerm (string, optional): The term to search for in the text.
    • ignoreCase (boolean, optional, default: true): Whether to ignore case when searching for the term and calculating word and character frequencies.
    • trimText (boolean, optional, default: true): Whether to trim the text before analysis.
    • wordsPerMinute (number, optional, default: 250 or 500 for CJK): Custom reading speed in words per minute, automatically adjusted for CJK text if not specified.

Returns

A TextAnalysisResult object containing various statistics about the text.

  • readingTime (object):
    • minutes (number): The total estimated reading time expressed in whole minutes.
    • seconds (number): Remaining seconds beyond the counted minutes.
    • total (number): The total estimated reading time expressed in total seconds.
    • text (string): A human-readable summary of the reading time.
  • searchFrequency (number): The frequency of the search term in the text.
  • wordCount (number): The number of words in the text.
  • charCount (number): The number of characters in the text.
  • sentenceCount (number): The number of sentences in the text.
  • paragraphCount (number): The number of paragraphs in the text.
  • mostFrequentWord (string): The most frequent word in the text.
  • leastFrequentWord (string): The least frequent word in the text.
  • mostFrequentCharacter (string): The most frequent character in the text.
  • leastFrequentCharacter (string): The least frequent character in the text.