
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
sentiment-analyze
Advanced tools
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.
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
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!
📦 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:
For emotion detection:
🔧 Methods
analyze(text: string)
Analyzes the sentiment of the given text.
Parameters:
Returns:
An object containing:
batchAnalyze(texts: string[])
Analyzes an array of text strings in batch.
Parameters:
Returns:
An array of sentiment results for each text, each containing:
detectEmotion(text: string)
Detects the emotion of the given text based on positive and negative word lists.
Parameters:
Returns:
An object containing:
📝 License
This project is licensed under the MIT License. See the LICENSE file for details.
FAQs
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.
The npm package sentiment-analyze receives a total of 2 weekly downloads. As such, sentiment-analyze popularity was classified as not popular.
We found that sentiment-analyze demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.