Turn on Jsdoc-based type checking

This commit is contained in:
n loewen 2023-08-03 16:24:51 +01:00
parent ea26f5d77b
commit 4f82cd9c9e
2 changed files with 23 additions and 1 deletions

6
jsconfig.json Normal file
View File

@ -0,0 +1,6 @@
{
"compilerOptions": {
"checkJs": true
},
"exclude": ["node_modules", "**/node_modules/*"]
}

View File

@ -1,3 +1,10 @@
/**
* Display a table of memory locations.
* Call with [start] and [end] indices to display a range.
* @param {Uint8Array} mem - Memory to display
* @param {number} [start] - A start-index, in decimal
* @param {number} [end] - An end-index, in decimal
**/
const logMemory = (mem, start=0, end=mem.length) => {
// This function can only handle
// an even number of array entries
@ -15,7 +22,7 @@ const logMemory = (mem, start=0, end=mem.length) => {
// Add a blank row every 4 lines:
if (((i + 2) % 8) === 0) {
if ((i < (mem.length - 2))) {
console.log(`│ │ │ │`);
console.log(`│ │ │ │`);
}
}
}
@ -30,7 +37,16 @@ const logRunningHeader = () => {
console.log( `└─────────────────────┘`);
}
/**
* @param {number} num
* @returns {string}
*/
const num2hex = (num) => num.toString(16).toUpperCase().padStart(2, "0");
/**
* @param {string} hex
* @returns {number}
*/
const hex2num = (hex) => parseInt(hex, 16);
module.exports = {