Skip to content

Commit 4683a12

Browse files
committed
adding basic documentation generation
1 parent 8ff1f4d commit 4683a12

File tree

4 files changed

+154
-8
lines changed

4 files changed

+154
-8
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
.idea
22
.sonarlint
33

4+
# Docs
5+
docs
6+
47
# Logs
58
logs
69
*.log

lib/rating.js

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
#!/usr/bin/env node
22
"use strict";
33

4+
/**
5+
* @typedef {Object} Player
6+
* @property {string} username Username
7+
* @property {number} score Score
8+
* @property {number} oldRating Previous rating
9+
* @property {number} [newRating] New rating
10+
*/
11+
12+
/**
13+
* @typedef {Object} Rating
14+
* @property {number} bula The game bula
15+
* @property {Player} p1 The 1st Player
16+
* @property {Player} p2 The 2nd Player
17+
* @property {Player} p3 The 3rd Player
18+
*/
19+
420
const _ = require("lodash");
521
const math = require("mathjs");
622
const Ajv = require("ajv");
@@ -13,6 +29,10 @@ const _validatePlayer = ajv.compile({
1329
required: ["username", "score"]
1430
});
1531

32+
/** @constant
33+
* @type {number}
34+
* @default
35+
*/
1636
const MAGIC = 2.8;
1737

1838
const _d = (p1, p2, bula) => math.round(math.chain(p1.score).subtract(p2.score).divide(bula).done(), 3);
@@ -53,22 +73,35 @@ const _calculateChanges = (p1, p2, p3, bula) => {
5373
};
5474
};
5575

56-
const _fixRating = (p) => {
76+
/** Adjust the players rating.
77+
* @private
78+
* @memberof PrefRating
79+
* @param {Player} p - The player object
80+
*/
81+
const _fixRatingAttributes = (p) => {
5782
p.oldRating = p.rating || p.oldRating;
5883
delete p.rating;
5984
return p;
6085
};
6186

87+
/** This is the Preferans Rating main class. */
6288
class PrefRating {
89+
/** @constructor
90+
* @param {Player} p1 - 1st player object
91+
* @param {Player} p2 - 2nd player object
92+
* @param {Player} p3 - 3rd player object
93+
* @param {number} bula - Game bula
94+
* @returns {object} PrefRating instance
95+
*/
6396
constructor(p1, p2, p3, bula) {
6497
_validatePlayer(p1);
6598
_validatePlayer(p2);
6699
_validatePlayer(p3);
67100
if (!bula || !_.isNumber(bula)) throw new Error("PrefRating::constructor:No bula defined " + bula);
68101

69-
p1 = _fixRating(p1);
70-
p2 = _fixRating(p2);
71-
p3 = _fixRating(p3);
102+
p1 = _fixRatingAttributes(p1);
103+
p2 = _fixRatingAttributes(p2);
104+
p3 = _fixRatingAttributes(p3);
72105

73106
this.bula = bula;
74107
this.p1 = p1;
@@ -86,6 +119,9 @@ class PrefRating {
86119
return this;
87120
}
88121

122+
/** Getter.
123+
* @returns {Rating} Rating object
124+
*/
89125
getRatings() {
90126
return {
91127
bula: this.bula,
@@ -96,4 +132,4 @@ class PrefRating {
96132
}
97133
}
98134

99-
module.exports = PrefRating;
135+
module.exports = PrefRating;

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
22
"name": "preferans-rating-js",
3-
"version": "1.2.1",
3+
"version": "1.2.2",
44
"description": "nodejs rating for preferans",
55
"engines": {
66
"node": ">=8.9"
77
},
88
"main": "lib/rating.js",
99
"scripts": {
10+
"docs": "jsdoc README.md ./lib/ -r -a all -d docs",
1011
"test": "nyc --reporter=lcov --reporter=html mocha",
1112
"coveralls": "cat ./coverage/lcov.info | node node_modules/.bin/coveralls",
1213
"sonar": "sonarjs -e .sonarlint/**,node_modules/**,coverage/**,.nyc_output/**"
@@ -28,6 +29,8 @@
2829
"homepage": "https://github.com/cope/preferans-rating-js#readme",
2930
"dependencies": {
3031
"ajv": "^6.5.2",
32+
"global": "^4.3.2",
33+
"jsdoc": "^3.5.5",
3134
"lodash": "^4.17.10",
3235
"mathjs": "^5.1.0"
3336
},

yarn.lock

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ aws4@^1.8.0:
204204
version "1.8.0"
205205
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f"
206206

207+
208+
version "7.0.0-beta.19"
209+
resolved "https://registry.yarnpkg.com/babylon/-/babylon-7.0.0-beta.19.tgz#e928c7e807e970e0536b078ab3e0c48f9e052503"
210+
207211
balanced-match@^1.0.0:
208212
version "1.0.0"
209213
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
@@ -240,6 +244,10 @@ bl@^1.0.0:
240244
readable-stream "^2.3.5"
241245
safe-buffer "^5.1.1"
242246

247+
bluebird@~3.5.0:
248+
version "3.5.3"
249+
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.3.tgz#7d01c6f9616c9a51ab0f8c549a79dfe6ec33efa7"
250+
243251
brace-expansion@^1.1.7:
244252
version "1.1.11"
245253
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
@@ -323,6 +331,12 @@ caseless@~0.12.0:
323331
version "0.12.0"
324332
resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc"
325333

334+
catharsis@~0.8.9:
335+
version "0.8.9"
336+
resolved "https://registry.yarnpkg.com/catharsis/-/catharsis-0.8.9.tgz#98cc890ca652dd2ef0e70b37925310ff9e90fc8b"
337+
dependencies:
338+
underscore-contrib "~0.3.0"
339+
326340
center-align@^0.1.1:
327341
version "0.1.3"
328342
resolved "https://registry.yarnpkg.com/center-align/-/center-align-0.1.3.tgz#aa0d32629b6ee972200411cbd4461c907bc2b7ad"
@@ -550,6 +564,10 @@ [email protected]:
550564
version "3.5.0"
551565
resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12"
552566

567+
dom-walk@^0.1.0:
568+
version "0.1.1"
569+
resolved "https://registry.yarnpkg.com/dom-walk/-/dom-walk-0.1.1.tgz#672226dc74c8f799ad35307df936aba11acd6018"
570+
553571
ecc-jsbn@~0.1.1:
554572
version "0.1.2"
555573
resolved "https://registry.yarnpkg.com/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz#3a83a904e54353287874c564b7549386849a98c9"
@@ -573,7 +591,7 @@ [email protected]:
573591
version "1.1.0"
574592
resolved "https://registry.yarnpkg.com/escape-latex/-/escape-latex-1.1.0.tgz#c0a94a51eb8c73c3a67a95cc90fbb626cef54539"
575593

576-
[email protected], escape-string-regexp@^1.0.5:
594+
[email protected], escape-string-regexp@^1.0.5, escape-string-regexp@~1.0.5:
577595
version "1.0.5"
578596
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
579597

@@ -763,6 +781,13 @@ [email protected], glob@^7.0.5, glob@^7.0.6:
763781
once "^1.3.0"
764782
path-is-absolute "^1.0.0"
765783

784+
global@^4.3.2:
785+
version "4.3.2"
786+
resolved "https://registry.yarnpkg.com/global/-/global-4.3.2.tgz#e76989268a6c74c38908b1305b10fc0e394e9d0f"
787+
dependencies:
788+
min-document "^2.19.0"
789+
process "~0.5.1"
790+
766791
globals@^11.1.0:
767792
version "11.7.0"
768793
resolved "https://registry.yarnpkg.com/globals/-/globals-11.7.0.tgz#a583faa43055b1aca771914bf68258e2fc125673"
@@ -771,6 +796,10 @@ graceful-fs@^4.1.11, graceful-fs@^4.1.2:
771796
version "4.1.11"
772797
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"
773798

799+
graceful-fs@^4.1.9:
800+
version "4.1.15"
801+
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.15.tgz#ffb703e1066e8a0eeaa4c8b80ba9253eeefbfb00"
802+
774803
[email protected], "growl@~> 1.10.0":
775804
version "1.10.5"
776805
resolved "https://registry.yarnpkg.com/growl/-/growl-1.10.5.tgz#f2735dc2283674fa67478b10181059355c369e5e"
@@ -1066,10 +1095,33 @@ js-yaml@^3.11.0:
10661095
argparse "^1.0.7"
10671096
esprima "^4.0.0"
10681097

1098+
js2xmlparser@~3.0.0:
1099+
version "3.0.0"
1100+
resolved "https://registry.yarnpkg.com/js2xmlparser/-/js2xmlparser-3.0.0.tgz#3fb60eaa089c5440f9319f51760ccd07e2499733"
1101+
dependencies:
1102+
xmlcreate "^1.0.1"
1103+
10691104
jsbn@~0.1.0:
10701105
version "0.1.1"
10711106
resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513"
10721107

1108+
jsdoc@^3.5.5:
1109+
version "3.5.5"
1110+
resolved "https://registry.yarnpkg.com/jsdoc/-/jsdoc-3.5.5.tgz#484521b126e81904d632ff83ec9aaa096708fa4d"
1111+
dependencies:
1112+
babylon "7.0.0-beta.19"
1113+
bluebird "~3.5.0"
1114+
catharsis "~0.8.9"
1115+
escape-string-regexp "~1.0.5"
1116+
js2xmlparser "~3.0.0"
1117+
klaw "~2.0.0"
1118+
marked "~0.3.6"
1119+
mkdirp "~0.5.1"
1120+
requizzle "~0.2.1"
1121+
strip-json-comments "~2.0.1"
1122+
taffydb "2.6.2"
1123+
underscore "~1.8.3"
1124+
10731125
jsesc@^2.5.1:
10741126
version "2.5.1"
10751127
resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-2.5.1.tgz#e421a2a8e20d6b0819df28908f782526b96dd1fe"
@@ -1119,6 +1171,12 @@ kind-of@^6.0.0, kind-of@^6.0.2:
11191171
version "6.0.2"
11201172
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.2.tgz#01146b36a6218e64e58f3a8d66de5d7fc6f6d051"
11211173

1174+
klaw@~2.0.0:
1175+
version "2.0.0"
1176+
resolved "https://registry.yarnpkg.com/klaw/-/klaw-2.0.0.tgz#59c128e0dc5ce410201151194eeb9cbf858650f6"
1177+
dependencies:
1178+
graceful-fs "^4.1.9"
1179+
11221180
lazy-cache@^1.0.3:
11231181
version "1.0.4"
11241182
resolved "https://registry.yarnpkg.com/lazy-cache/-/lazy-cache-1.0.4.tgz#a1d78fc3a50474cb80845d3b3b6e1da49a446e8e"
@@ -1185,6 +1243,10 @@ map-visit@^1.0.0:
11851243
dependencies:
11861244
object-visit "^1.0.0"
11871245

1246+
marked@~0.3.6:
1247+
version "0.3.19"
1248+
resolved "http://registry.npmjs.org/marked/-/marked-0.3.19.tgz#5d47f709c4c9fc3c216b6d46127280f40b39d790"
1249+
11881250
mathjs@^5.1.0:
11891251
version "5.1.0"
11901252
resolved "https://registry.yarnpkg.com/mathjs/-/mathjs-5.1.0.tgz#e25543e0ba6ce806250d71cee8400f513924e7cd"
@@ -1252,6 +1314,12 @@ mimic-fn@^1.0.0:
12521314
version "1.2.0"
12531315
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022"
12541316

1317+
min-document@^2.19.0:
1318+
version "2.19.0"
1319+
resolved "https://registry.yarnpkg.com/min-document/-/min-document-2.19.0.tgz#7bd282e3f5842ed295bb748cdd9f1ffa2c824685"
1320+
dependencies:
1321+
dom-walk "^0.1.0"
1322+
12551323
[email protected], minimatch@^3.0.4:
12561324
version "3.0.4"
12571325
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
@@ -1277,7 +1345,7 @@ mixin-deep@^1.2.0:
12771345
for-in "^1.0.2"
12781346
is-extendable "^1.0.1"
12791347

1280-
[email protected], mkdirp@^0.5.0, mkdirp@^0.5.1:
1348+
[email protected], mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.1:
12811349
version "0.5.1"
12821350
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
12831351
dependencies:
@@ -1519,6 +1587,10 @@ process-nextick-args@~2.0.0:
15191587
version "2.0.0"
15201588
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.0.tgz#a37d732f4271b4ab1ad070d35508e8290788ffaa"
15211589

1590+
process@~0.5.1:
1591+
version "0.5.2"
1592+
resolved "https://registry.yarnpkg.com/process/-/process-0.5.2.tgz#1638d8a8e34c2f440a91db95ab9aeb677fc185cf"
1593+
15221594
progress@^2.0.0:
15231595
version "2.0.0"
15241596
resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.0.tgz#8a1be366bf8fc23db2bd23f10c6fe920b4389d1f"
@@ -1625,6 +1697,12 @@ require-main-filename@^1.0.1:
16251697
version "1.0.1"
16261698
resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-1.0.1.tgz#97f717b69d48784f5f526a6c5aa8ffdda055a4d1"
16271699

1700+
requizzle@~0.2.1:
1701+
version "0.2.1"
1702+
resolved "https://registry.yarnpkg.com/requizzle/-/requizzle-0.2.1.tgz#6943c3530c4d9a7e46f1cddd51c158fc670cdbde"
1703+
dependencies:
1704+
underscore "~1.6.0"
1705+
16281706
resolve-from@^2.0.0:
16291707
version "2.0.0"
16301708
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-2.0.0.tgz#9480ab20e94ffa1d9e80a804c7ea147611966b57"
@@ -1886,6 +1964,10 @@ strip-eof@^1.0.0:
18861964
version "1.0.0"
18871965
resolved "https://registry.yarnpkg.com/strip-eof/-/strip-eof-1.0.0.tgz#bb43ff5598a6eb05d89b59fcd129c983313606bf"
18881966

1967+
strip-json-comments@~2.0.1:
1968+
version "2.0.1"
1969+
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"
1970+
18891971
[email protected], supports-color@^5.3.0:
18901972
version "5.4.0"
18911973
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.4.0.tgz#1c6b337402c2137605efe19f10fec390f6faab54"
@@ -1898,6 +1980,10 @@ supports-color@^3.1.2:
18981980
dependencies:
18991981
has-flag "^1.0.0"
19001982

1983+
1984+
version "2.6.2"
1985+
resolved "https://registry.yarnpkg.com/taffydb/-/taffydb-2.6.2.tgz#7cbcb64b5a141b6a2efc2c5d2c67b4e150b2a268"
1986+
19011987
tar-fs@^1.16.0:
19021988
version "1.16.3"
19031989
resolved "https://registry.yarnpkg.com/tar-fs/-/tar-fs-1.16.3.tgz#966a628841da2c4010406a82167cbd5e0c72d509"
@@ -2009,6 +2095,20 @@ uglify-to-browserify@~1.0.0:
20092095
version "1.0.2"
20102096
resolved "https://registry.yarnpkg.com/uglify-to-browserify/-/uglify-to-browserify-1.0.2.tgz#6e0924d6bda6b5afe349e39a6d632850a0f882b7"
20112097

2098+
underscore-contrib@~0.3.0:
2099+
version "0.3.0"
2100+
resolved "https://registry.yarnpkg.com/underscore-contrib/-/underscore-contrib-0.3.0.tgz#665b66c24783f8fa2b18c9f8cbb0e2c7d48c26c7"
2101+
dependencies:
2102+
underscore "1.6.0"
2103+
2104+
[email protected], underscore@~1.6.0:
2105+
version "1.6.0"
2106+
resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.6.0.tgz#8b38b10cacdef63337b8b24e4ff86d45aea529a8"
2107+
2108+
underscore@~1.8.3:
2109+
version "1.8.3"
2110+
resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.8.3.tgz#4f3fb53b106e6097fcf9cb4109f2a5e9bdfa5022"
2111+
20122112
union-value@^1.0.0:
20132113
version "1.0.0"
20142114
resolved "https://registry.yarnpkg.com/union-value/-/union-value-1.0.0.tgz#5c71c34cb5bad5dcebe3ea0cd08207ba5aa1aea4"
@@ -2110,6 +2210,10 @@ write-file-atomic@^1.1.4:
21102210
imurmurhash "^0.1.4"
21112211
slide "^1.1.5"
21122212

2213+
xmlcreate@^1.0.1:
2214+
version "1.0.2"
2215+
resolved "https://registry.yarnpkg.com/xmlcreate/-/xmlcreate-1.0.2.tgz#fa6bf762a60a413fb3dd8f4b03c5b269238d308f"
2216+
21132217
xtend@^4.0.0:
21142218
version "4.0.1"
21152219
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af"

0 commit comments

Comments
 (0)