From 7785c25371f6ffe4dd091ffe0111d678437cfd24 Mon Sep 17 00:00:00 2001 From: Alexey Koran Date: Thu, 1 May 2025 16:58:20 +0400 Subject: [PATCH 1/9] style: set indentation to 2 spaces, add EOL to each file --- src/cli/args.js | 4 ++-- src/cli/env.js | 4 ++-- src/cp/cp.js | 2 +- src/cp/files/script.js | 6 +++--- src/fs/copy.js | 2 +- src/fs/create.js | 4 ++-- src/fs/delete.js | 4 ++-- src/fs/list.js | 4 ++-- src/fs/read.js | 4 ++-- src/fs/rename.js | 4 ++-- src/hash/calcHash.js | 4 ++-- src/modules/cjsToEsm.cjs | 15 +++++++-------- src/modules/files/a.json | 8 ++++---- src/modules/files/b.json | 8 ++++---- src/streams/read.js | 4 ++-- src/streams/transform.js | 4 ++-- src/streams/write.js | 4 ++-- src/wt/main.js | 4 ++-- src/wt/worker.js | 4 ++-- src/zip/compress.js | 4 ++-- src/zip/decompress.js | 4 ++-- 21 files changed, 50 insertions(+), 51 deletions(-) diff --git a/src/cli/args.js b/src/cli/args.js index 8283f7f7aa..9e3622f791 100644 --- a/src/cli/args.js +++ b/src/cli/args.js @@ -1,5 +1,5 @@ const parseArgs = () => { - // Write your code here + // Write your code here }; -parseArgs(); \ No newline at end of file +parseArgs(); diff --git a/src/cli/env.js b/src/cli/env.js index fe4aa4a8df..e3616dc8e7 100644 --- a/src/cli/env.js +++ b/src/cli/env.js @@ -1,5 +1,5 @@ const parseEnv = () => { - // Write your code here + // Write your code here }; -parseEnv(); \ No newline at end of file +parseEnv(); diff --git a/src/cp/cp.js b/src/cp/cp.js index 4a87b98c55..72c6addc9c 100644 --- a/src/cp/cp.js +++ b/src/cp/cp.js @@ -1,5 +1,5 @@ const spawnChildProcess = async (args) => { - // Write your code here + // Write your code here }; // Put your arguments in function call to test this functionality diff --git a/src/cp/files/script.js b/src/cp/files/script.js index 44a0622fbc..bd194433cd 100644 --- a/src/cp/files/script.js +++ b/src/cp/files/script.js @@ -4,9 +4,9 @@ console.log(`Total number of arguments is ${args.length}`); console.log(`Arguments: ${JSON.stringify(args)}`); const echoInput = (chunk) => { - const chunkStringified = chunk.toString(); - if (chunkStringified.includes('CLOSE')) process.exit(0); - process.stdout.write(`Received from master process: ${chunk.toString()}\n`) + const chunkStringified = chunk.toString(); + if (chunkStringified.includes('CLOSE')) process.exit(0); + process.stdout.write(`Received from master process: ${chunk.toString()}\n`) }; process.stdin.on('data', echoInput); diff --git a/src/fs/copy.js b/src/fs/copy.js index bd17fe3991..e226075b4c 100644 --- a/src/fs/copy.js +++ b/src/fs/copy.js @@ -1,5 +1,5 @@ const copy = async () => { - // Write your code here + // Write your code here }; await copy(); diff --git a/src/fs/create.js b/src/fs/create.js index 8d18cf9fc2..6ede285599 100644 --- a/src/fs/create.js +++ b/src/fs/create.js @@ -1,5 +1,5 @@ const create = async () => { - // Write your code here + // Write your code here }; -await create(); \ No newline at end of file +await create(); diff --git a/src/fs/delete.js b/src/fs/delete.js index 4718dbc4c5..a70b13766c 100644 --- a/src/fs/delete.js +++ b/src/fs/delete.js @@ -1,5 +1,5 @@ const remove = async () => { - // Write your code here + // Write your code here }; -await remove(); \ No newline at end of file +await remove(); diff --git a/src/fs/list.js b/src/fs/list.js index c0a83dea15..0c0fa21f7e 100644 --- a/src/fs/list.js +++ b/src/fs/list.js @@ -1,5 +1,5 @@ const list = async () => { - // Write your code here + // Write your code here }; -await list(); \ No newline at end of file +await list(); diff --git a/src/fs/read.js b/src/fs/read.js index 52c78cc6ee..e3938be563 100644 --- a/src/fs/read.js +++ b/src/fs/read.js @@ -1,5 +1,5 @@ const read = async () => { - // Write your code here + // Write your code here }; -await read(); \ No newline at end of file +await read(); diff --git a/src/fs/rename.js b/src/fs/rename.js index 2bb99ecdb5..b1d65b0c86 100644 --- a/src/fs/rename.js +++ b/src/fs/rename.js @@ -1,5 +1,5 @@ const rename = async () => { - // Write your code here + // Write your code here }; -await rename(); \ No newline at end of file +await rename(); diff --git a/src/hash/calcHash.js b/src/hash/calcHash.js index 450f8f72e2..e37c17ed62 100644 --- a/src/hash/calcHash.js +++ b/src/hash/calcHash.js @@ -1,5 +1,5 @@ const calculateHash = async () => { - // Write your code here + // Write your code here }; -await calculateHash(); \ No newline at end of file +await calculateHash(); diff --git a/src/modules/cjsToEsm.cjs b/src/modules/cjsToEsm.cjs index d7180351e7..7971b277b1 100644 --- a/src/modules/cjsToEsm.cjs +++ b/src/modules/cjsToEsm.cjs @@ -8,9 +8,9 @@ const random = Math.random(); let unknownObject; if (random > 0.5) { - unknownObject = require('./files/a.json'); + unknownObject = require('./files/a.json'); } else { - unknownObject = require('./files/b.json'); + unknownObject = require('./files/b.json'); } console.log(`Release ${release()}`); @@ -21,7 +21,7 @@ console.log(`Path to current file is ${__filename}`); console.log(`Path to current directory is ${__dirname}`); const myServer = createServerHttp((_, res) => { - res.end('Request accepted'); + res.end('Request accepted'); }); const PORT = 3000; @@ -29,12 +29,11 @@ const PORT = 3000; console.log(unknownObject); myServer.listen(PORT, () => { - console.log(`Server is listening on port ${PORT}`); - console.log('To terminate it, use Ctrl+C combination'); + console.log(`Server is listening on port ${PORT}`); + console.log('To terminate it, use Ctrl+C combination'); }); module.exports = { - unknownObject, - myServer, + unknownObject, + myServer, }; - diff --git a/src/modules/files/a.json b/src/modules/files/a.json index 7878a209f6..d1f6dac48a 100644 --- a/src/modules/files/a.json +++ b/src/modules/files/a.json @@ -1,5 +1,5 @@ { - "a": 1, - "b": 2, - "c": 3 -} \ No newline at end of file + "a": 1, + "b": 2, + "c": 3 +} diff --git a/src/modules/files/b.json b/src/modules/files/b.json index 5214b8c93d..e442128649 100644 --- a/src/modules/files/b.json +++ b/src/modules/files/b.json @@ -1,5 +1,5 @@ { - "a": 11, - "b": 22, - "c": 33 -} \ No newline at end of file + "a": 11, + "b": 22, + "c": 33 +} diff --git a/src/streams/read.js b/src/streams/read.js index 52c78cc6ee..e3938be563 100644 --- a/src/streams/read.js +++ b/src/streams/read.js @@ -1,5 +1,5 @@ const read = async () => { - // Write your code here + // Write your code here }; -await read(); \ No newline at end of file +await read(); diff --git a/src/streams/transform.js b/src/streams/transform.js index 315fc6597f..9e6c15fe84 100644 --- a/src/streams/transform.js +++ b/src/streams/transform.js @@ -1,5 +1,5 @@ const transform = async () => { - // Write your code here + // Write your code here }; -await transform(); \ No newline at end of file +await transform(); diff --git a/src/streams/write.js b/src/streams/write.js index fc917160a2..84aa11e7cb 100644 --- a/src/streams/write.js +++ b/src/streams/write.js @@ -1,5 +1,5 @@ const write = async () => { - // Write your code here + // Write your code here }; -await write(); \ No newline at end of file +await write(); diff --git a/src/wt/main.js b/src/wt/main.js index 37d80484ec..e2ef054d41 100644 --- a/src/wt/main.js +++ b/src/wt/main.js @@ -1,5 +1,5 @@ const performCalculations = async () => { - // Write your code here + // Write your code here }; -await performCalculations(); \ No newline at end of file +await performCalculations(); diff --git a/src/wt/worker.js b/src/wt/worker.js index 441b2154f8..405595394d 100644 --- a/src/wt/worker.js +++ b/src/wt/worker.js @@ -2,7 +2,7 @@ const nthFibonacci = (n) => n < 2 ? n : nthFibonacci(n - 1) + nthFibonacci(n - 2); const sendResult = () => { - // This function sends result of nthFibonacci computations to main thread + // This function sends result of nthFibonacci computations to main thread }; -sendResult(); \ No newline at end of file +sendResult(); diff --git a/src/zip/compress.js b/src/zip/compress.js index bb328f43c6..d55209587e 100644 --- a/src/zip/compress.js +++ b/src/zip/compress.js @@ -1,5 +1,5 @@ const compress = async () => { - // Write your code here + // Write your code here }; -await compress(); \ No newline at end of file +await compress(); diff --git a/src/zip/decompress.js b/src/zip/decompress.js index 69f6c345f8..8aaf26c8a4 100644 --- a/src/zip/decompress.js +++ b/src/zip/decompress.js @@ -1,5 +1,5 @@ const decompress = async () => { - // Write your code here + // Write your code here }; -await decompress(); \ No newline at end of file +await decompress(); From 4a9cc25b9f1a58f6a1bdf26bd4550c7df91a85c7 Mon Sep 17 00:00:00 2001 From: Alexey Koran Date: Thu, 1 May 2025 18:14:59 +0400 Subject: [PATCH 2/9] refactor: `cp script.js`, use EOL instead of `\n` --- src/cp/files/script.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cp/files/script.js b/src/cp/files/script.js index bd194433cd..b283657cf7 100644 --- a/src/cp/files/script.js +++ b/src/cp/files/script.js @@ -1,12 +1,14 @@ +import { EOL } from 'node:os'; + const args = process.argv.slice(2); console.log(`Total number of arguments is ${args.length}`); -console.log(`Arguments: ${JSON.stringify(args)}`); +console.log(`Arguments: ${JSON.stringify(args)}${EOL}`); const echoInput = (chunk) => { const chunkStringified = chunk.toString(); if (chunkStringified.includes('CLOSE')) process.exit(0); - process.stdout.write(`Received from master process: ${chunk.toString()}\n`) + process.stdout.write(`Received from master process: ${chunk.toString()}${EOL}`) }; process.stdin.on('data', echoInput); From 30e50208f4d04754b99c2840bae2df58730650c3 Mon Sep 17 00:00:00 2001 From: Alexey Koran Date: Thu, 1 May 2025 18:17:00 +0400 Subject: [PATCH 3/9] refactor: `cp script.js`, import argv, stdout, stdin, exit from `node:process` --- src/cp/files/script.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/cp/files/script.js b/src/cp/files/script.js index b283657cf7..139d5d781d 100644 --- a/src/cp/files/script.js +++ b/src/cp/files/script.js @@ -1,14 +1,20 @@ import { EOL } from 'node:os'; -const args = process.argv.slice(2); +import { argv, stdout, stdin, exit } from 'node:process'; + +const args = argv.slice(2); console.log(`Total number of arguments is ${args.length}`); console.log(`Arguments: ${JSON.stringify(args)}${EOL}`); const echoInput = (chunk) => { const chunkStringified = chunk.toString(); - if (chunkStringified.includes('CLOSE')) process.exit(0); - process.stdout.write(`Received from master process: ${chunk.toString()}${EOL}`) + + if (chunkStringified.includes('CLOSE')) { + exit(0); + } + + stdout.write(`Received from master process: ${chunk.toString()}${EOL}`) }; -process.stdin.on('data', echoInput); +stdin.on('data', echoInput); From 81be94416f9f42b7494f8e3d4fefc19da149df41 Mon Sep 17 00:00:00 2001 From: Alexey Koran Date: Thu, 1 May 2025 18:19:47 +0400 Subject: [PATCH 4/9] refactor: `cjsToEsm`, add `node:` protocol to imports --- src/modules/cjsToEsm.cjs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/cjsToEsm.cjs b/src/modules/cjsToEsm.cjs index 7971b277b1..d6f6825102 100644 --- a/src/modules/cjsToEsm.cjs +++ b/src/modules/cjsToEsm.cjs @@ -1,6 +1,6 @@ -const path = require('path'); -const { release, version } = require('os'); -const { createServer: createServerHttp } = require('http'); +const path = require('node:path'); +const { release, version } = require('node:os'); +const { createServer: createServerHttp } = require('node:http'); require('./files/c.cjs'); const random = Math.random(); From 7a875d5f73835eefa83591163799e8719946830a Mon Sep 17 00:00:00 2001 From: Alexey Koran Date: Thu, 1 May 2025 18:25:16 +0400 Subject: [PATCH 5/9] refactor: `cjsToEsm`, unknownObject import --- src/modules/cjsToEsm.cjs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/modules/cjsToEsm.cjs b/src/modules/cjsToEsm.cjs index d6f6825102..089bd2db13 100644 --- a/src/modules/cjsToEsm.cjs +++ b/src/modules/cjsToEsm.cjs @@ -1,17 +1,12 @@ const path = require('node:path'); const { release, version } = require('node:os'); const { createServer: createServerHttp } = require('node:http'); + require('./files/c.cjs'); const random = Math.random(); -let unknownObject; - -if (random > 0.5) { - unknownObject = require('./files/a.json'); -} else { - unknownObject = require('./files/b.json'); -} +const unknownObject = random > 0.5 ? require('./files/a.json') : require('./files/b.json'); console.log(`Release ${release()}`); console.log(`Version ${version()}`); From b025c0fd143a68f8f9de4566ebf39ba3fe891057 Mon Sep 17 00:00:00 2001 From: Alexey Koran Date: Thu, 1 May 2025 18:44:58 +0400 Subject: [PATCH 6/9] refactor: `wt/worker.js`, improve nthFibonacci function --- src/wt/worker.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/wt/worker.js b/src/wt/worker.js index 405595394d..9c2a7e7fb3 100644 --- a/src/wt/worker.js +++ b/src/wt/worker.js @@ -1,5 +1,14 @@ // n should be received from main thread -const nthFibonacci = (n) => n < 2 ? n : nthFibonacci(n - 1) + nthFibonacci(n - 2); +const nthFibonacci = (n) => { + let a = 0; + let b = 1; + + for (let i = 0; i < n; i += 1) { + [a, b] = [b, a + b]; + } + + return a; +}; const sendResult = () => { // This function sends result of nthFibonacci computations to main thread From f365e3bb9d998ee40170d8164b660756d96dc31d Mon Sep 17 00:00:00 2001 From: Alexey Koran Date: Fri, 2 May 2025 21:41:05 +0400 Subject: [PATCH 7/9] refactor: add missing semicolon --- src/cp/files/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cp/files/script.js b/src/cp/files/script.js index 139d5d781d..88568560e1 100644 --- a/src/cp/files/script.js +++ b/src/cp/files/script.js @@ -14,7 +14,7 @@ const echoInput = (chunk) => { exit(0); } - stdout.write(`Received from master process: ${chunk.toString()}${EOL}`) + stdout.write(`Received from master process: ${chunk.toString()}${EOL}`); }; stdin.on('data', echoInput); From 499e00c540bb491ad4edc9895420eaeac4610eb5 Mon Sep 17 00:00:00 2001 From: Alexey Koran Date: Mon, 5 May 2025 05:49:04 +0400 Subject: [PATCH 8/9] style: remove empty line between imports --- src/cp/files/script.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cp/files/script.js b/src/cp/files/script.js index 88568560e1..0c6654f12f 100644 --- a/src/cp/files/script.js +++ b/src/cp/files/script.js @@ -1,5 +1,4 @@ import { EOL } from 'node:os'; - import { argv, stdout, stdin, exit } from 'node:process'; const args = argv.slice(2); From dbcd947361127f348878a3fd5c388d857c598493 Mon Sep 17 00:00:00 2001 From: Alexey Koran Date: Mon, 5 May 2025 17:24:58 +0400 Subject: [PATCH 9/9] Revert "refactor: `wt/worker.js`, improve nthFibonacci function" This reverts commit b025c0fd143a68f8f9de4566ebf39ba3fe891057. --- src/wt/worker.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/wt/worker.js b/src/wt/worker.js index 9c2a7e7fb3..405595394d 100644 --- a/src/wt/worker.js +++ b/src/wt/worker.js @@ -1,14 +1,5 @@ // n should be received from main thread -const nthFibonacci = (n) => { - let a = 0; - let b = 1; - - for (let i = 0; i < n; i += 1) { - [a, b] = [b, a + b]; - } - - return a; -}; +const nthFibonacci = (n) => n < 2 ? n : nthFibonacci(n - 1) + nthFibonacci(n - 2); const sendResult = () => { // This function sends result of nthFibonacci computations to main thread