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 🙏

© 2025 – Pkg Stats / Ryan Hefner

sentiment-analysis-textblob

v1.0.3

Published

A Node.js library for sentiment analysis using TextBlob

Readme

Sentiment Analysis TextBlob 🎨

npm License Node.js Downloads


🌟 About the Author


🚀 Features

  • Simple API: Supports callbacks and Promises.
  • Sentiment Scores: Polarity (-1 to 1) & Subjectivity (0 to 1).
  • Cross-Platform: Works on all major OSes.
  • Practical Use: Perfect for social media or customer insights.

📦 Installation

npm install sentiment-analysis-textblob

Requirements

  • Node.js: v14.2+
  • Python: v3.6+, in PATH
  • TextBlob: NLP library

Verify Python:

python3 --version || python --version

Manual Install:

pip3 install textblob || pip install textblob

🎯 Quick Start

Promise Example

const { analyzeSentimentPromise } = require('sentiment-analysis-textblob');

(async () => {
  try {
    const result = await analyzeSentimentPromise('This is awesome!');
    console.log('Result:', result); // { polarity: 0.7, subjectivity: 0.85 }
  } catch (err) {
    console.error('Error:', err.message);
  }
})();

Callback Example

const { analyzeSentiment } = require('sentiment-analysis-textblob');

analyzeSentiment('Great experience!', (err, result) => {
  if (err) console.error('Error:', err.message);
  else console.log('Result:', result); // { polarity: 0.6, subjectivity: 0.8 }
});

📋 API

| Method | Description | Returns | |-------------------------|------------------------------------------|------------------| | analyzeSentiment(text, callback) | Analyze text via callback | void | | analyzeSentimentPromise(text) | Analyze text via Promise | Promise<Object>|

  • text: string - Text input.
  • callback: function(err, result) - Returns { polarity, subjectivity } or error.
  • Promise: Resolves to { polarity, subjectivity }.

📊 Output Details

| Property | Range | Meaning | |----------------|-------------|----------------------------------------------| | polarity | -1 to 1 | 😊 > 0: Positive (e.g., 'Great!' ~ 0.7) 😐 0: Neutral (e.g., 'A product' ~ 0) 😞 < 0: Negative (e.g., 'Bad!' ~ -0.6) | | subjectivity | 0 to 1 | 📝 0–0.3: Objective (e.g., '100 pages' ~ 0) 🤔 0.3–0.7: Mixed (e.g., 'Okay' ~ 0.5) 💭 0.7–1: Subjective (e.g., 'Love it!' ~ 0.9) |

Example:

// Input: 'Fantastic performance!'
// Output: { polarity: 0.8, subjectivity: 0.75 }
// Meaning: Strong positive, highly opinionated

ℹ️ Notes

  • Language: Optimized for English; non-English needs preprocessing.
  • Dependencies: Requires Python + TextBlob (auto-installed).
  • Performance: Suitable for small projects; use VADER for advanced cases.

🛠️ Troubleshooting

  • Python Not Found:

    • Install from python.org and add to PATH.
    • Check: python3 --version or python --version.
    • macOS/Linux: export PATH="/usr/local/bin:$PATH" in ~/.bashrc.
  • TextBlob Failed:

    • Run: pip3 install textblob or pip install textblob.
    • Test: python3 scripts/sentiment.py 'Test text' (Expected: {"polarity": 0.0, "subjectivity": 0.0}).
  • Custom Path (Rare):

    • Edit src/index.js:
      const options = {
        mode: 'text',
        pythonPath: '/usr/bin/python3', // e.g., 'C:\\Python39\\python.exe' on Windows
        pythonOptions: ['-u'],
        scriptPath: path.join(__dirname, '../scripts'),
        args: [text]
      };

🤝 Contribute

💡 Ideas or bugs?
👉 GitHub
📧 [email protected]


📜 License

MIT