Comparing version 3.0.1 to 3.0.2
62
index.js
@@ -1,42 +0,42 @@ | ||
'use strict'; | ||
'use strict' | ||
var afinn = require('afinn-165'); | ||
var emoji = require('./emoji'); | ||
var afinn = require('afinn-165') | ||
var emoji = require('./emoji') | ||
module.exports = polarity; | ||
polarity.inject = inject; | ||
polarity.polarities = {}; | ||
module.exports = polarity | ||
polarity.inject = inject | ||
polarity.polarities = {} | ||
var polarities = polarity.polarities; | ||
var polarities = polarity.polarities | ||
var own = {}.hasOwnProperty; | ||
var own = {}.hasOwnProperty | ||
inject(afinn); | ||
inject(emoji); | ||
inject(afinn) | ||
inject(emoji) | ||
/* Define `polarity` */ | ||
function polarity(values, inject) { | ||
var words = values || []; | ||
var index = words.length || 1; | ||
var positivity = 0; | ||
var negativity = 0; | ||
var positive = []; | ||
var negative = []; | ||
var value; | ||
var weight; | ||
var words = values || [] | ||
var index = words.length || 1 | ||
var positivity = 0 | ||
var negativity = 0 | ||
var positive = [] | ||
var negative = [] | ||
var value | ||
var weight | ||
while (index--) { | ||
value = words[index]; | ||
weight = getPolarity(value, inject); | ||
value = words[index] | ||
weight = getPolarity(value, inject) | ||
if (!weight) { | ||
continue; | ||
continue | ||
} | ||
if (weight > 0) { | ||
positive.push(value); | ||
positivity += weight; | ||
positive.push(value) | ||
positivity += weight | ||
} else { | ||
negative.push(value); | ||
negativity += weight; | ||
negative.push(value) | ||
negativity += weight | ||
} | ||
@@ -51,3 +51,3 @@ } | ||
negative: negative | ||
}; | ||
} | ||
} | ||
@@ -57,6 +57,6 @@ | ||
function inject(values) { | ||
var value; | ||
var value | ||
for (value in values) { | ||
polarities[value] = values[value]; | ||
polarities[value] = values[value] | ||
} | ||
@@ -68,10 +68,10 @@ } | ||
if (own.call(polarities, value)) { | ||
return polarities[value]; | ||
return polarities[value] | ||
} | ||
if (inject && own.call(inject, value)) { | ||
return inject[value]; | ||
return inject[value] | ||
} | ||
return 0; | ||
return 0 | ||
} |
{ | ||
"name": "polarity", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"description": "Detect the polarity (sentiment) of text", | ||
@@ -33,22 +33,22 @@ "license": "MIT", | ||
"devDependencies": { | ||
"browserify": "^14.0.0", | ||
"browserify": "^16.0.0", | ||
"emoji-emotion": "^2.0.0", | ||
"esmangle": "^1.0.1", | ||
"gemoji": "^4.0.0", | ||
"nyc": "^11.0.0", | ||
"remark-cli": "^4.0.0", | ||
"remark-preset-wooorm": "^3.0.0", | ||
"tape": "^4.6.3", | ||
"xo": "^0.18.0" | ||
"nyc": "^13.0.0", | ||
"prettier": "^1.14.2", | ||
"remark-cli": "^5.0.0", | ||
"remark-preset-wooorm": "^4.0.0", | ||
"tape": "^4.0.0", | ||
"tinyify": "^2.4.3", | ||
"xo": "^0.22.0" | ||
}, | ||
"scripts": { | ||
"build-md": "remark . -qfo", | ||
"build-emoji": "node build", | ||
"build-bundle": "browserify index.js --bare -s polarity > polarity.js", | ||
"build-mangle": "esmangle polarity.js > polarity.min.js", | ||
"build": "npm run build-md && npm run build-emoji && npm run build-bundle && npm run build-mangle", | ||
"lint": "xo", | ||
"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 build && npm run lint && npm run test-api" | ||
"test": "npm run generate && npm run format && npm run build && npm run test-api" | ||
}, | ||
@@ -61,4 +61,12 @@ "nyc": { | ||
}, | ||
"prettier": { | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"singleQuote": true, | ||
"bracketSpacing": false, | ||
"semi": false, | ||
"trailingComma": "none" | ||
}, | ||
"xo": { | ||
"space": true, | ||
"prettier": true, | ||
"esnext": false, | ||
@@ -65,0 +73,0 @@ "rules": { |
@@ -17,5 +17,5 @@ # polarity [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] | ||
```js | ||
var polarity = require('polarity'); | ||
var polarity = require('polarity') | ||
polarity(['some', 'positive', 'happy', 'cats']); | ||
polarity(['some', 'positive', 'happy', 'cats']) | ||
``` | ||
@@ -36,3 +36,3 @@ | ||
```js | ||
polarity(['darn', 'self-deluded', 'abandoned', 'dogs']); | ||
polarity(['darn', 'self-deluded', 'abandoned', 'dogs']) | ||
``` | ||
@@ -63,3 +63,3 @@ | ||
function tokenize(value) { | ||
return value.toLowerCase().match(/\S+/g); | ||
return value.toLowerCase().match(/\S+/g) | ||
} | ||
@@ -118,3 +118,3 @@ ``` | ||
[license]: LICENSE | ||
[license]: license | ||
@@ -121,0 +121,0 @@ [author]: http://wooorm.com |
11070
10