chore(users/Profpatsch/lyric): add typescript linting rules

Change-Id: I9ab0336450519648f7a8edeec94bd64b78e2f05b
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12554
Tested-by: BuildkiteCI
Reviewed-by: Profpatsch <mail@profpatsch.de>
This commit is contained in:
Profpatsch 2024-10-01 03:54:36 +02:00
parent 102c9b30a7
commit ad711b15a0
6 changed files with 140 additions and 89 deletions

View file

@ -1,16 +1,16 @@
import { tapBpm } from "./tap-bpm.js";
import { tapBpm } from './tap-bpm.js';
async function main() {
function main() {
// subcommand for tap-bpm
if (process.argv[2] === "tap-bpm") {
await tapBpm();
if (process.argv[2] === 'tap-bpm') {
tapBpm();
}
}
await main();
main();
// sleep in a loop to block nodejs
console.log("Blocking event loop...");
console.log('Blocking event loop...');
while (true) {
await new Promise((resolve) => setTimeout(resolve, 1000));
await new Promise(resolve => setTimeout(resolve, 1000));
}

View file

@ -1,7 +1,7 @@
// create a node command line listener that allows the user to press any key , and averages the distances between the key presses to determine the BPM (with a window of 4 key presses). If the user presses q, the program should exit and print the final BPM.
// Import the necessary modules
import * as readline from "readline";
import * as readline from 'readline';
export function tapBpm() {
// Set up readline interface to listen for keypresses
@ -19,35 +19,28 @@ export function tapBpm() {
return 0;
}
const averageTimeDiff =
timeDifferences.reduce((acc, curr) => acc + curr, 0) /
timeDifferences.length;
timeDifferences.reduce((acc, curr) => acc + curr, 0) / timeDifferences.length;
return (60 * 1000) / averageTimeDiff;
}
// Handle the SIGINT (Ctrl+C) event manually
process.on("SIGINT", () => {
console.log(
"\nExiting via SIGINT (Ctrl+C)... Final BPM:",
calculateBPM().toFixed(2)
);
process.on('SIGINT', () => {
console.log('\nExiting via SIGINT (Ctrl+C)... Final BPM:', calculateBPM().toFixed(2));
process.exit();
});
// Listen for keypress events
process.stdin.on("keypress", (str, key) => {
process.stdin.on('keypress', (str, key: { name: string; sequence: string }) => {
// Exit if 'q' is pressed
if (key.name === "q") {
console.log("Exiting... Final BPM:", calculateBPM().toFixed(2));
if (key.name === 'q') {
console.log('Exiting... Final BPM:', calculateBPM().toFixed(2));
process.exit();
}
// Handle Ctrl+C (SIGINT)
if (key.sequence === "\u0003") {
if (key.sequence === '\u0003') {
// '\u0003' is the raw code for Ctrl+C
console.log(
"\nExiting via Ctrl+C... Final BPM:",
calculateBPM().toFixed(2)
);
console.log('\nExiting via Ctrl+C... Final BPM:', calculateBPM().toFixed(2));
process.exit();
}
@ -66,9 +59,9 @@ export function tapBpm() {
// Calculate and display the BPM
const bpm = calculateBPM();
console.log("Current BPM:", bpm.toFixed(2));
console.log('Current BPM:', bpm.toFixed(2));
} else {
console.log("Waiting for more key presses to calculate BPM...");
console.log('Waiting for more key presses to calculate BPM...');
}
// Update the lastPressTime to the current time