Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

polarity

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

polarity - npm Package Compare versions

Comparing version 3.0.4 to 4.0.0

emoji.js

66

index.js

@@ -1,25 +0,41 @@

'use strict'
/**
* @typedef {Object} Polarity
* @property {number} polarity
* @property {number} positivity
* @property {number} negativity
* @property {Array.<string>} positive
* @property {Array.<string>} negative
*
* @typedef {Object.<string, number>} Inject
*/
var afinn = require('afinn-165')
var emoji = require('./emoji')
import {afinn165} from 'afinn-165'
import {emoji} from './emoji.js'
module.exports = polarity
polarity.inject = inject
polarity.polarities = {}
export var polarities = {}
var polarities = polarity.polarities
var own = {}.hasOwnProperty
inject(afinn)
inject(afinn165)
inject(emoji)
function polarity(values, inject) {
/**
* Get a polarity result from given values, optionally with one time injections.
*
* @param {Array.<string>} values
* @param {Inject} inject
* @returns {Polarity}
*/
export function polarity(values, inject) {
var words = values || []
var index = words.length || 1
var index = words.length === 0 ? 1 : words.length
var positivity = 0
var negativity = 0
/** @type {Array.<string>} */
var positive = []
/** @type {Array.<string>} */
var negative = []
/** @type {string} */
var value
/** @type {number} */
var weight

@@ -46,19 +62,31 @@

polarity: positivity + negativity,
positivity: positivity,
negativity: negativity,
positive: positive,
negative: negative
positivity,
negativity,
positive,
negative
}
}
// Inject values on the `polarities` object.
function inject(values) {
/**
* Inject values on the `polarities` object.
*
* @param {Inject} values
*/
export function inject(values) {
/** @type {string} */
var value
for (value in values) {
polarities[value] = values[value]
if (own.call(values, value)) {
polarities[value] = values[value]
}
}
}
// Get the polarity of a word.
/**
* Get the polarity of a word.
*
* @param {string} value
* @param {Inject} inject
*/
function getPolarity(value, inject) {

@@ -65,0 +93,0 @@ if (own.call(polarities, value)) {

{
"name": "polarity",
"version": "3.0.4",
"version": "4.0.0",
"description": "Detect the polarity (sentiment) of text",

@@ -29,37 +29,39 @@ "license": "MIT",

],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.d.ts",
"index.js",
"emoji.json"
"emoji.js"
],
"dependencies": {
"afinn-165": "^1.0.0"
"afinn-165": "^2.0.0"
},
"devDependencies": {
"browserify": "^16.0.0",
"emoji-emotion": "^2.0.0",
"gemoji": "^5.0.0",
"@types/tape": "^4.0.0",
"c8": "^7.0.0",
"emoji-emotion": "^3.0.0",
"gemoji": "^7.0.0",
"nyc": "^15.0.0",
"prettier": "^1.0.0",
"remark-cli": "^7.0.0",
"remark-preset-wooorm": "^6.0.0",
"tape": "^4.0.0",
"tinyify": "^2.0.0",
"xo": "^0.25.0"
"prettier": "^2.0.0",
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"rimraf": "^3.0.0",
"tape": "^5.0.0",
"tinyify": "^3.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"xo": "^0.38.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
"generate": "node build",
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix",
"build-bundle": "browserify . -s polarity > polarity.js",
"build-mangle": "browserify . -s polarity -p tinyify > polarity.min.js",
"build": "npm run build-bundle && npm run build-mangle",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test/index.js",
"test": "npm run generate && npm run format && npm run build && npm run test-coverage"
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node test/index.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test/index.js",
"test": "npm run generate && npm run build && npm run format && npm run test-coverage"
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
},
"prettier": {

@@ -75,9 +77,7 @@ "tabWidth": 2,

"prettier": true,
"esnext": false,
"rules": {
"guard-for-in": "off"
},
"ignores": [
"polarity.js"
]
"import/no-mutable-exports": "off",
"no-var": "off",
"prefer-arrow-callback": "off"
}
},

@@ -88,3 +88,8 @@ "remarkConfig": {

]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true
}
}

@@ -13,2 +13,5 @@ # polarity

This package is ESM only: Node 12+ is needed to use it and it must be `import`ed
instead of `require`d.
[npm][]:

@@ -23,3 +26,3 @@

```js
var polarity = require('polarity')
import {polarity} from 'polarity'

@@ -59,2 +62,6 @@ polarity(['some', 'positive', 'happy', 'cats'])

This package exports the following identifiers: `polarity`, `inject`,
`polarities`.
There is no default export.
### `polarity(words[, inject])`

@@ -89,7 +96,7 @@

### `polarity.inject(words)`
### `inject(words)`
Insert custom values.
### `polarity.polarities`
### `polarities`

@@ -115,5 +122,5 @@ Direct access to the internal values.

[build-badge]: https://img.shields.io/travis/words/polarity.svg
[build-badge]: https://github.com/words/polarity/workflows/main/badge.svg
[build]: https://travis-ci.org/words/polarity
[build]: https://github.com/words/polarity/actions

@@ -120,0 +127,0 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/words/polarity.svg

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc