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 🙏

© 2026 – Pkg Stats / Ryan Hefner

sentiment-analyze

v2.0.3

Published

A lightweight and easy-to-use npm package for performing sentiment analysis on text. Analyze the positivity, negativity, or neutrality of any string input with ease, and process multiple texts in batch for more efficient analysis.

Readme

A lightweight and easy-to-use npm package for performing sentiment analysis on text. Analyze the positivity, negativity, or neutrality of any string input with ease, and process multiple texts in batch for more efficient analysis.

🌟 Features

  • Simple and intuitive API for sentiment analysis.
  • Returns detailed sentiment results (score, comparative, positive words, negative words).
  • Batch analysis for processing multiple texts at once.
  • Emotion detection that categorizes sentiment as happiness, sadness, or neutral.
  • Lightweight and efficient, with minimal dependencies.

❤️ Support My Work!

Maintaining this package requires effort and dedication. If this project helped you, consider buying me a coffee or supporting me via PayPal. Every donation helps keep this project alive!

Support via PayPal

📦 Installation

Install the package via npm:

npm install sentiment-analyze

🚀 Usage

Here's how to use the sentiment-analyze package in your Node.js project:

Example 1: Basic Sentiment Analysis

// Import the SentimentAnalyze
const { SentimentAnalyze } = require('sentiment-analyze');

// Create an instance of SentimentAnalyzer
const analyzer = new SentimentAnalyze();

// Analyze a text string
const result = analyzer.analyze('I love programming but hate bugs.');

console.log(result);
// Output:
// {
//   score: 0,
//   comparative: 0,
//   positive: ['love'],
//   negative: ['hate']
// }

Example 2: Batch Sentiment Analysis

// Create an instance of SentimentAnalyzer
const analyzer = new SentimentAnalyze();

// Analyze multiple texts in batch
const batchResult = analyzer.batchAnalyze([
  'I am happy with my work.',
  'This is such a terrible day.',
  'I feel neutral about this.'
]);

console.log(batchResult);
// Output:
// [
//   { score: 2, comparative: 0.4, positive: ['happy'], negative: [] },
//   { score: -2, comparative: -0.4, positive: [], negative: ['terrible'] },
//   { score: 0, comparative: 0, positive: [], negative: [] }
// ]

Example 3: Emotion Detection

// Create an instance of SentimentAnalyzer
const analyzer = new SentimentAnalyze();

// Detect emotion in a sentence
const emotionResult = analyzer.detectEmotion('I am feeling great today!');
console.log(emotionResult);
// Output:
// {
//   emotion: 'happiness',
//   score: 2
// }

📊 Output Format

The result object contains the following fields:

  • score: Overall sentiment score (positive or negative)
  • comparative: Comparative score relative to the text length.
  • positive: Array of positive words detected.
  • negative: Array of negative words detected.

For emotion detection:

  • emotion: The detected emotion (happiness, sadness, or neutral).
  • score: A numeric score that indicates the overall sentiment intensity.

🔧 Methods

analyze(text: string)

Analyzes the sentiment of the given text.

Parameters:

  • text (string): The text to analyze.

Returns:

An object containing:

  • score: Sentiment score (number).
  • comparative: Comparative sentiment score (number).
  • positive: Array of positive words (string[]).
  • negative: Array of negative words (string[]).
batchAnalyze(texts: string[])

Analyzes an array of text strings in batch.

Parameters:

  • texts (string[]): An array of texts to analyze.

Returns:

An array of sentiment results for each text, each containing:

  • score: Sentiment score (number).
  • comparative: Comparative sentiment score (number).
  • positive: Array of positive words (string[]).
  • negative: Array of negative words (string[]).
detectEmotion(text: string)

Detects the emotion of the given text based on positive and negative word lists.

Parameters:

  • text (string): The text to analyze.

Returns:

An object containing:

  • emotion: The detected emotion (happiness, sadness, or neutral).
  • score: A numeric score indicating the overall sentiment intensity.

📝 License

This project is licensed under the MIT License. See the LICENSE file for details.