Skip to content

Commit 944cb36

Browse files
authored
Docs fixes for proper JSDoc formatting (#131)
1 parent ad71ac5 commit 944cb36

31 files changed

+634
-185
lines changed

entrypoints/chs.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
export { default as Console } from '../src/console/index.js';
2-
export { default as Queue } from '../src/datastructures/queue.js';
3-
export { default as Stack } from '../src/datastructures/stack.js';
42
export { default as Grid } from '../src/datastructures/grid.js';
3+
export { default as Queue } from '../src/datastructures/queue.js';
54
export { default as ExtendedSet } from '../src/datastructures/set.js';
5+
export { default as Stack } from '../src/datastructures/stack.js';
66
export { default as Vector } from '../src/datastructures/vector.js';
77
export { default as Arc } from '../src/graphics/arc.js';
88
export { default as Circle } from '../src/graphics/circle.js';
99
export { default as Color } from '../src/graphics/color.js';
10-
export { map, getDistance } from '../src/graphics/graphics-utils.js';
10+
export { getDistance, map } from '../src/graphics/graphics-utils.js';
1111
export { default as Group } from '../src/graphics/group.js';
12+
export { default as ImageLibrary } from '../src/graphics/imagelibrary.js';
1213
export { default as Graphics } from '../src/graphics/index.js';
13-
export { default as Keyboard } from '../src/graphics/keyboard.js';
14+
export * as Keyboard from '../src/graphics/keyboard.js';
1415
export { default as Line } from '../src/graphics/line.js';
1516
export { default as Oval } from '../src/graphics/oval.js';
1617
export { default as Polygon } from '../src/graphics/polygon.js';
@@ -19,7 +20,6 @@ export { default as Text } from '../src/graphics/text.js';
1920
export { default as Thing } from '../src/graphics/thing.js';
2021
export { default as WebImage } from '../src/graphics/webimage.js';
2122
export { default as WebVideo } from '../src/graphics/webvideo.js';
22-
export { default as ImageLibrary } from '../src/graphics/imagelibrary.js';
2323
export * as Randomizer from '../src/randomizer.js';
2424
export { default as AudioManager } from '../src/sound/';
2525
export { default as Audio } from '../src/sound/audio.js';

entrypoints/windowBinder.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { default as Console } from '../src/console/index.js';
2-
import { default as Queue } from '../src/datastructures/queue.js';
3-
import { default as Stack } from '../src/datastructures/stack.js';
42
import { default as Grid } from '../src/datastructures/grid.js';
3+
import { default as Queue } from '../src/datastructures/queue.js';
54
import { default as ExtendedSet } from '../src/datastructures/set.js';
5+
import { default as Stack } from '../src/datastructures/stack.js';
66
import { default as Vector } from '../src/datastructures/vector.js';
77
import { default as Arc } from '../src/graphics/arc.js';
88
import { default as Circle } from '../src/graphics/circle.js';
99
import { default as Color } from '../src/graphics/color.js';
10-
import { map, getDistance } from '../src/graphics/graphics-utils.js';
10+
import { getDistance, map } from '../src/graphics/graphics-utils.js';
1111
import { default as Group } from '../src/graphics/group.js';
12+
import { default as ImageLibrary } from '../src/graphics/imagelibrary.js';
1213
import { default as GraphicsManager } from '../src/graphics/index.js';
13-
import { default as Keyboard } from '../src/graphics/keyboard.js';
14+
import * as Keyboard from '../src/graphics/keyboard.js';
1415
import { default as Line } from '../src/graphics/line.js';
1516
import { default as Oval } from '../src/graphics/oval.js';
1617
import { default as Polygon } from '../src/graphics/polygon.js';
@@ -19,7 +20,6 @@ import { default as Text } from '../src/graphics/text.js';
1920
import { default as Thing } from '../src/graphics/thing.js';
2021
import { default as WebImage } from '../src/graphics/webimage.js';
2122
import { default as WebVideo } from '../src/graphics/webvideo.js';
22-
import { default as ImageLibrary } from '../src/graphics/imagelibrary.js';
2323
import * as Randomizer from '../src/randomizer.js';
2424
import { default as Audio } from '../src/sound/audio.js';
2525
import { default as AudioManager } from '../src/sound/index.js';
@@ -60,6 +60,7 @@ window.mouseDownMethod = GraphicsInstance.mouseDownMethod.bind(GraphicsInstance)
6060
window.mouseDragMethod = GraphicsInstance.mouseDragMethod.bind(GraphicsInstance);
6161
window.mouseUpMethod = GraphicsInstance.mouseUpMethod.bind(GraphicsInstance);
6262
window.mouseMoveMethod = GraphicsInstance.mouseMoveMethod.bind(GraphicsInstance);
63+
window.waitForClick = GraphicsInstance.waitForClick.bind(GraphicsInstance);
6364
window.stopAllTimers = GraphicsInstance.stopAllTimers.bind(GraphicsInstance);
6465
window.setMainTimer = GraphicsInstance.setMainTimer.bind(GraphicsInstance);
6566
window.stopTimer = GraphicsInstance.stopTimer.bind(GraphicsInstance);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"build": "node build.js",
2020
"dev": "node build.js watch",
2121
"dist": "tsc && node build.js dist",
22-
"docs": "npm run build && cp -r dist/* ./site/assets/ && jsdoc src/**/*.js --template node_modules/docdash --destination _site/docs",
22+
"docs": "npm run build && cp -r dist/* ./site/assets/ && jsdoc --readme src/DOCSREADME.md src/**/*.js src/*.js --template node_modules/docdash --destination _site/docs",
2323
"prepare": "husky install",
2424
"site": "npm run docs && npx @11ty/eleventy",
2525
"site:watch": "npm run docs && npx @11ty/eleventy --watch"

src/DOCSREADME.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# CodeHS JavaScript Library
2+
3+
Welcome! This is documentation for the CodeHS JavaScript Library.
4+
5+
## Graphics
6+
7+
- [Color]{@link module:Color~Color}
8+
- [Keyboard]{@link module:Keyboard}
9+
10+
### Shapes
11+
12+
- {@link Arc}
13+
- {@link Circle}
14+
- {@link Group}
15+
- {@link Line}
16+
- {@link Oval}
17+
- {@link Polygon}
18+
- {@link Rectangle}
19+
- {@link Text}
20+
- {@link Thing}
21+
- {@link WebImage}
22+
- {@link WebVideo}
23+
24+
## Console
25+
26+
- {@link readInt}
27+
- {@link readLine}
28+
- {@link readFloat}
29+
- {@link readBoolean}
30+
- {@link print}
31+
- {@link println}
32+
33+
## Data Structures
34+
35+
- {@link Grid}
36+
- {@link Queue}
37+
- {@link ExtendedSet}
38+
- {@link Stack}
39+
- {@link Vector}
40+
41+
## Audio
42+
43+
- {@link Audio}
44+
- {@link Sound}

src/console/index.js

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,36 @@
1-
/* Console
2-
*
3-
* A console represents a text console that allows the user to print, println,
4-
* and read an integer using readInt, and read a float using readFloat. These
5-
* functions pop up prompt dialogs and make sure that the results are actually
6-
* of the desired type.
7-
*
8-
* @author Jeremy Keeshin July 9, 2012
9-
* @author Andy Bayer Fall 2021
1+
/**
2+
* Console provides utilities for interacting with a text console.
3+
* {@link Console#readInt}, {@link Console#readFloat}, {@link Console#readBoolean}, and {@link Console#readLine}
4+
* prompt the user for input and parse it to the corresponding type. This prompt will use the blocking
5+
* browser prompt by default, but can be configured using {@link Console#onPrompt}.
106
*
7+
* Console also exposes {@link Console#print} and {@link Console#println}, which are used for
8+
* emitting output. By default the output will print to the console, but can be configured using
9+
* {@link Console#onPrint}.
1110
*/
11+
class Console {
12+
/**
13+
* Function invoked when asking for user input.
14+
* This function is invoked with the string of the prompt, i.e. readInt('give me an int!').
15+
* The result of invoking onPrompt will be subjected to parsing functions for confirming
16+
* it's an appropriate data type (a float, in the case of readFloat, for example). If
17+
* onPrompt is undefined, window.prompt is used as a fallback.
18+
* @type {function}
19+
*/
20+
onPrompt = window.prompt.bind(window);
21+
/**
22+
* Function invoked when printing.
23+
* This function is invoked with any output, either in the case of explicit calls to `print`
24+
* or `println` or internal calls within the library. If onPrint is undefined, console.log
25+
* is used as a fallback.
26+
* @type {function}
27+
*/
28+
onPrint = window.console.log.bind(window.console);
29+
/**
30+
* Function invoked when {@link Console#clear} is called.
31+
*/
32+
onClear = window.console.clear.bind(window.console);
1233

13-
export default class Console {
1434
/**
1535
* Initialize the console class, additionally configuring any event handlers.
1636
* @constructor
@@ -28,7 +48,7 @@ export default class Console {
2848
constructor(options = {}) {
2949
this.onPrompt = options.onPrompt ?? window.prompt.bind(window);
3050
this.onPrint = options.onPrint ?? window.console.log.bind(window.console);
31-
this.onClear = options.onClear ?? (() => {});
51+
this.onClear = options.onClear ?? window.console.clear.bind(window.console);
3252
}
3353

3454
/**
@@ -63,6 +83,7 @@ export default class Console {
6383

6484
/**
6585
* Clear the console.
86+
* @global
6687
*/
6788
clear() {
6889
this.onClear();
@@ -71,6 +92,7 @@ export default class Console {
7192
/**
7293
* Print a value to the console.
7394
* @param {...any} args - Anything to print.
95+
* @global
7496
*/
7597
print(...args) {
7698
if (args.length < 1) {
@@ -82,6 +104,7 @@ export default class Console {
82104
/**
83105
* Print a value to the console, followed by a newline character.
84106
* @param {any} value - The value to print.
107+
* @global
85108
*/
86109
println(value) {
87110
if (arguments.length === 0) {
@@ -112,6 +135,7 @@ export default class Console {
112135
* why a given input was rejected. For example, the errorMsgType "an integer," would result in
113136
* printing "That was not an integer. Please try again." if parseFn failed.
114137
* @returns {number}
138+
* @global
115139
*/
116140
readNumber(str, parseFn, errorMsgType) {
117141
const DEFAULT = 0; // If we get into an infinite loop, return DEFAULT.
@@ -120,10 +144,10 @@ export default class Console {
120144
let promptString = str;
121145
let loopCount = 0;
122146
/**
123-
* @type {boolean}
124147
* indicates whether the parsing has been successful, meaning
125148
* it hasn't hit the INFINITE_LOOP_CHECK or null cases, and the input from the user has
126149
* satisfied parseFn. in this case, the input should be printed.
150+
* @type {boolean}
127151
* */
128152
let successful = false;
129153
let parsedResult;
@@ -163,6 +187,7 @@ export default class Console {
163187
* Read a line from the user.
164188
* @param {str} str - A message associated with the modal asking for input.
165189
* @returns {str} The result of the readLine prompt.
190+
* @global
166191
*/
167192
readLine(str) {
168193
if (arguments.length !== 1) {
@@ -179,6 +204,7 @@ export default class Console {
179204
* Read a bool from the user.
180205
* @param {str} str - A message associated with the modal asking for input.
181206
* @returns {str} The result of the readBoolean prompt.
207+
* @global
182208
*/
183209
readBoolean(str) {
184210
if (arguments.length !== 1) {
@@ -208,6 +234,7 @@ export default class Console {
208234
* though they are successfully parsed as ints.
209235
* @param {str} str - A message associated with the modal asking for input.
210236
* @returns {str} The result of the readInt prompt.
237+
* @global
211238
*/
212239
readInt(str) {
213240
if (arguments.length !== 1) {
@@ -233,6 +260,7 @@ export default class Console {
233260
* Read a float with our safe helper function.
234261
* @param {str} str - A message associated with the modal asking for input.
235262
* @returns {str} The result of the readFloat prompt.
263+
* @global
236264
*/
237265
readFloat(str) {
238266
if (arguments.length !== 1) {
@@ -242,3 +270,5 @@ export default class Console {
242270
return this.readNumber(str, parseFloat, 'a float');
243271
}
244272
}
273+
274+
export default Console;

src/datastructures/grid.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
/** @module Grid */
2-
31
/**
42
* A grid is an abstraction around a two-dimensional array.
3+
* @class
54
*/
65
class Grid {
76
type = 'Grid';
87

98
/**
109
* Constructs a grid.
10+
* @constructor
1111
* @param {number} rows
1212
* @param {number} cols
1313
*/

src/datastructures/queue.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
'use strict';
2-
3-
export default class Queue extends Array {
1+
/**
2+
* A Queue is an Array subclass that implements First In, First Out ordering
3+
* @class
4+
* @extends Array
5+
*/
6+
class Queue extends Array {
47
/**
58
* Get the number of objects in the queue.
69
* @returns {number} Number of elements in the queue.
@@ -52,3 +55,5 @@ export default class Queue extends Array {
5255
return this.length === 0;
5356
}
5457
}
58+
59+
export default Queue;

src/datastructures/set.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* The ExtendedSet extends the native Set implementation, adding some functionality.
3+
* @class
4+
* @extends Set
5+
*/
16
class ExtendedSet extends Set {
27
/**
38
* Returns whether the set is empty.

src/datastructures/stack.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
export default class Stack extends Array {
1+
/**
2+
* A Stack is a subclass of an Array that implements First In, Last Out ordering.
3+
* @class
4+
* @extends Array
5+
*/
6+
class Stack extends Array {
27
/**
38
* Get the number of objects in the stack.
49
* @returns {number} Number of elements in the stack.
@@ -38,3 +43,5 @@ export default class Stack extends Array {
3843
return this.length === 0;
3944
}
4045
}
46+
47+
export default Stack;

src/datastructures/vector.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { degreesToRadians, radiansToDegrees } from '../graphics/arc.js';
22

3+
/**
4+
* The Vector class is ued to model a 2 or 3 dimensional vector.
5+
* @class
6+
*/
37
class Vector {
48
/**
59
* @constructor
@@ -27,13 +31,10 @@ class Vector {
2731

2832
/**
2933
* Add a vector to this one, modifying this one.
30-
* @method add
31-
* @param {number} x the x component of the vector to be added
34+
* @param {number|Vector|number[]} x the x component of the vector to be added.
35+
* Alternatively, a Vector or list of numbers to add.
3236
* @param {number} [y] the y component of the vector to be added
3337
* @param {number} [z] the z component of the vector to be added
34-
*
35-
* @method add
36-
* @param {Vector|number[]} vector vector or array to add
3738
* @returns {Vector} this vector, modified
3839
*/
3940
add(x, y, z) {
@@ -57,13 +58,11 @@ class Vector {
5758

5859
/**
5960
* Subtract a vector from this one, modifying this one.
60-
* @method subtract
61-
* @param {number} x the x component of the vector to be subtracted
61+
* @param {number|Vector|number[]} x the x component of the vector to be subtracted
62+
* Alternatively, a Vector or list of numbers to substract.
6263
* @param {number} [y] the y component of the vector to be subtracted
6364
* @param {number} [z] the z component of the vector to be subtracted
6465
*
65-
* @method subtract
66-
* @param {Vector|number[]} vector vector or array to subtract
6766
* @returns {Vector} this vector, modified
6867
*/
6968
subtract(x, y, z) {
@@ -87,13 +86,12 @@ class Vector {
8786

8887
/**
8988
* Multiply this vector by a vector, scalar, or array, modifying it in place and returning it.
90-
* @method multiply
91-
* @param {number} x scalar to multiply the x component by
89+
* @param {number|Vector|number[]} x scalar to multiply the x component by
90+
* Alternatively, a Vector or list of numbers to multiply
9291
* @param {number} [y] scalar to multiply the y component by
9392
* @param {number} [z] scalar to multiply the z component by
9493
*
95-
* @method add
96-
* @param {Vector|number[]} vector vector or array to multiply
94+
k
9795
* @returns {Vector} this vector, modified
9896
*/
9997
multiply(x, y, z) {

0 commit comments

Comments
 (0)