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

average-rating

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

average-rating - npm Package Compare versions

Comparing version 1.1.1 to 1.1.3

reset.js

18

.eslintrc.json
{
"extends": "eslint-config-ggc"
"env": {
"es6": true,
"node": true,
"browser": true
},
"extends": ["eslint:recommended", "google"],
"rules": {
"max-len": [
"error",
{
"code": 120,
"ignoreTrailingComments": true,
"ignoreComments": true,
"ignoreUrls": true
}
]
}
}

6

index.js

@@ -5,3 +5,5 @@ /**

**/
exports = module.exports = require('./src/main');
exports.version = require('./package').version;
const main = require('./src/main');
main.version = require('./package').version;
module.exports = main;
{
"version": "1.1.1",
"version": "1.1.3",
"name": "average-rating",

@@ -17,18 +17,19 @@ "description": "Calculate average score and rating based on Wilson Score Equation",

"lint": "eslint .",
"snyk": "snyk test",
"nsp": "nsp check --output checkstyle",
"tape": "nyc tape test/start.js | tap-spec",
"report": "nyc report --reporter=lcov",
"pretest": "npm run lint && npm run snyk",
"tape:debug": "DEBUG=*:* nyc tape test/start.js | tap-spec",
"report": "nyc report --reporter=lcov > coverage.lcov && codecov",
"pretest": "npm run lint && npm run nsp",
"test": "npm run tape",
"posttest": "npm run report",
"coveralls": "npm test && cat ./coverage/lcov.info | coveralls"
"posttest": "CODECOV_TOKEN=47b63968-97ab-4ad1-8812-267ce37a3e5f npm run report",
"reset": "node reset"
},
"devDependencies": {
"coveralls": "latest",
"eslint": "latest",
"eslint-config-ggc": "latest",
"codecov": "^3.0.0",
"eslint": "^4.11.0",
"eslint-config-google": "^0.9.1",
"nsp": "^2.8.1",
"nyc": "latest",
"snyk": "latest",
"tap-spec": "latest",
"tape": "latest"
"tap-spec": "^4.1.1",
"tape": "^4.8.0"
},

@@ -35,0 +36,0 @@ "keywords": [

@@ -6,5 +6,5 @@ # average-rating

[![Build Status](https://travis-ci.org/ndaidong/average-rating.svg?branch=master)](https://travis-ci.org/ndaidong/average-rating)
[![Coverage Status](https://coveralls.io/repos/github/ndaidong/average-rating/badge.svg?branch=master)](https://coveralls.io/github/ndaidong/average-rating?branch=master)
[![dependencies Status](https://david-dm.org/ndaidong/average-rating/status.svg)](https://david-dm.org/ndaidong/average-rating)
[![Known Vulnerabilities](https://snyk.io/test/npm/average-rating/badge.svg)](https://snyk.io/test/npm/average-rating)
[![codecov](https://codecov.io/gh/ndaidong/average-rating/branch/master/graph/badge.svg)](https://codecov.io/gh/ndaidong/average-rating)
[![Dependency Status](https://gemnasium.com/badges/github.com/ndaidong/average-rating.svg)](https://gemnasium.com/github.com/ndaidong/average-rating)
[![NSP Status](https://nodesecurity.io/orgs/techpush/projects/ff38031c-c6ba-4606-92e9-ebe07d649fa7/badge)](https://nodesecurity.io/orgs/techpush/projects/ff38031c-c6ba-4606-92e9-ebe07d649fa7)

@@ -16,11 +16,8 @@ ![Google app on Google Play](http://i.imgur.com/NgQX5OW.png)

```
var av = require('average-rating');
var rate = av.rate;
var average = av.average;
var score = av.score;
const {
score,
rate,
average
} = require('average-rating');
// from 1 to 5 stars
let rating = [134055, 57472, 143135, 365957, 1448459];
rate(rating); // --> 0.84
average(rating); // --> 4.4

@@ -31,2 +28,9 @@ // get Winson score for a pair of (Positive, Negative) voting

score(1000, 1000); // --> 0.48
// from 1 to 5 stars
let rating = [134055, 57472, 143135, 365957, 1448459];
rate(rating); // --> 0.84
// calculate average
average(rating); // --> 4.4
```

@@ -33,0 +37,0 @@

@@ -7,3 +7,3 @@ /**

var getWilsonScore = (p, n) => {
const score = (p, n) => {
if (p === 0 && n === 0) {

@@ -16,35 +16,40 @@ return 0;

module.exports = {
score: getWilsonScore,
rate: (rating) => {
const rate = (rating) => {
let n = 0;
let p = 0;
n += rating[0];
n += rating[1] * 0.75;
p += rating[1] * 0.25;
n += rating[2] * 0.5;
p += rating[2] * 0.5;
n += rating[3] * 0.25;
p += rating[3] * 0.75;
p += rating[4];
let n = 0;
let p = 0;
n += rating[0];
n += rating[1] * 0.75;
p += rating[1] * 0.25;
n += rating[2] * 0.5;
p += rating[2] * 0.5;
n += rating[3] * 0.25;
p += rating[3] * 0.75;
p += rating[4];
return score(p, n);
};
return getWilsonScore(p, n);
},
average: (rating) => {
let total = rating.reduce((prev, current) => {
return prev + current;
});
if (total === 0) {
return 0;
}
let sum = 0;
let k = 1;
rating.forEach((item) => {
sum += item * k;
k++;
});
let r = sum / total;
return r.toFixed(1);
const average = (rating) => {
let total = rating.reduce((prev, current) => {
return prev + current;
}, 0);
if (total === 0) {
return 0;
}
let sum = 0;
let k = 1;
rating.forEach((item) => {
sum += item * k;
k++;
});
let r = sum / total;
return r.toFixed(1);
};
module.exports = {
score,
rate,
average,
};

@@ -6,10 +6,9 @@ /**

var test = require('tape');
const test = require('tape');
var AverageRating = require('../../../index');
const AverageRating = require('../../../index');
var samples = require('../samples');
const samples = require('../samples');
test('Testing "average" method', (assert) => {
samples.forEach((sample) => {

@@ -16,0 +15,0 @@ let rating = sample.rating;

@@ -6,10 +6,9 @@ /**

var test = require('tape');
const test = require('tape');
var AverageRating = require('../../../index');
const AverageRating = require('../../../index');
var samples = require('../samples');
const samples = require('../samples');
test('Testing "rate" method', (assert) => {
samples.forEach((sample) => {

@@ -16,0 +15,0 @@ let rating = sample.rating;

@@ -1,2 +0,2 @@

var samples = [
const samples = [
{

@@ -6,4 +6,4 @@ rating: [0, 0, 0, 0, 0],

average: 0,
score: 0
}
score: 0,
},
}, {

@@ -13,4 +13,4 @@ rating: [1, 1, 1, 1, 1],

average: 3.0,
score: 0.17
}
score: 0.17,
},
}, {

@@ -20,4 +20,4 @@ rating: [2, 2, 2, 2, 2],

average: 3.0,
score: 0.24
}
score: 0.24,
},
}, {

@@ -27,4 +27,4 @@ rating: [3, 3, 3, 3, 3],

average: 3.0,
score: 0.27
}
score: 0.27,
},
}, {

@@ -34,4 +34,4 @@ rating: [4, 4, 4, 4, 4],

average: 3.0,
score: 0.3
}
score: 0.3,
},
}, {

@@ -41,4 +41,4 @@ rating: [5, 5, 5, 5, 5],

average: 3.0,
score: 0.32
}
score: 0.32,
},
}, {

@@ -48,4 +48,4 @@ rating: [5, 4, 3, 2, 1],

average: 2.3,
score: 0.15
}
score: 0.15,
},
}, {

@@ -55,4 +55,4 @@ rating: [5, 0, 0, 0, 5],

average: 3.0,
score: 0.24
}
score: 0.24,
},
}, {

@@ -62,4 +62,4 @@ rating: [5, 0, 0, 4, 5],

average: 3.3,
score: 0.33
}
score: 0.33,
},
}, {

@@ -69,4 +69,4 @@ rating: [5, 4, 0, 0, 5],

average: 2.7,
score: 0.21
}
score: 0.21,
},
}, {

@@ -76,4 +76,4 @@ rating: [0, 0, 0, 0, 5],

average: 5,
score: 0.57
}
score: 0.57,
},
}, {

@@ -83,4 +83,4 @@ rating: [0, 0, 0, 4, 5],

average: 4.6,
score: 0.56
}
score: 0.56,
},
}, {

@@ -90,4 +90,4 @@ rating: [0, 0, 3, 4, 5],

average: 4.2,
score: 0.51
}
score: 0.51,
},
}, {

@@ -97,4 +97,4 @@ rating: [0, 2, 3, 4, 5],

average: 3.9,
score: 0.45
}
score: 0.45,
},
}, {

@@ -104,4 +104,4 @@ rating: [1, 2, 3, 4, 5],

average: 3.7,
score: 0.42
}
score: 0.42,
},
}, {

@@ -111,4 +111,4 @@ rating: [9524, 4158, 10177, 25971, 68669],

average: 4.2,
score: 0.79
}
score: 0.79,
},
}, {

@@ -118,7 +118,7 @@ rating: [134055, 57472, 143135, 365957, 1448459],

average: 4.4,
score: 0.84
}
}
score: 0.84,
},
},
];
module.exports = samples;

@@ -6,76 +6,75 @@ /**

var test = require('tape');
const test = require('tape');
var AverageRating = require('../../../index');
const AverageRating = require('../../../index');
let samples = [
const samples = [
{
p: 0,
n: 1,
e: 0
e: 0,
}, {
p: 0,
n: 5,
e: 0
e: 0,
}, {
p: 0,
n: 10,
e: 0
e: 0,
}, {
p: 0,
n: 20,
e: 0
e: 0,
}, {
p: 0,
n: 100,
e: 0
e: 0,
}, {
p: 0,
n: 1000,
e: 0
e: 0,
}, {
n: 0,
p: 1,
e: 0.21
e: 0.21,
}, {
n: 0,
p: 5,
e: 0.57
e: 0.57,
}, {
n: 0,
p: 10,
e: 0.72
e: 0.72,
}, {
n: 0,
p: 20,
e: 0.84
e: 0.84,
}, {
n: 0,
p: 100,
e: 0.96
e: 0.96,
}, {
n: 0,
p: 1000,
e: 1
e: 1,
}, {
n: 1,
p: 1,
e: 0.09
e: 0.09,
}, {
n: 5,
p: 5,
e: 0.24
e: 0.24,
}, {
n: 500,
p: 500,
e: 0.47
e: 0.47,
}, {
n: 1000,
p: 1000,
e: 0.48
}
e: 0.48,
},
];
test('Testing "score" method', (assert) => {
samples.forEach((sample) => {

@@ -86,4 +85,3 @@ let expect = sample.e;

});
assert.end();
});

@@ -1,4 +0,1 @@

var fs = require('fs');
var path = require('path');
/**

@@ -8,9 +5,19 @@ * Import specs

var dirs = ['average', 'rate', 'score'];
const {
existsSync,
readdirSync,
} = require('fs');
const {
extname,
join,
} = require('path');
const dirs = ['average', 'rate', 'score'];
dirs.forEach((dir) => {
let where = './test/specs/' + dir;
if (fs.existsSync(where)) {
fs.readdirSync(where).forEach((file) => {
if (path.extname(file) === '.js') {
require(path.join('.' + where, file));
if (existsSync(where)) {
readdirSync(where).forEach((file) => {
if (extname(file) === '.js') {
require(join('.' + where, file));
}

@@ -17,0 +24,0 @@ });

Sorry, the diff of this file is not supported yet

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