From 4d630072b2f5e444080efb63ebcab6b8aae622d4 Mon Sep 17 00:00:00 2001 From: tshemsedinov Date: Sat, 2 Jun 2018 20:15:13 +0000 Subject: [PATCH 01/17] Update license --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 8864d4a..716dbfd 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017 +Copyright (c) 2017-2018 How.Programming.Works contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 860a9b8ae65b3090842bc1768a6db3c87cfb4837 Mon Sep 17 00:00:00 2001 From: tshemsedinov Date: Thu, 21 Mar 2019 00:33:36 +0200 Subject: [PATCH 02/17] Split get example into http and https --- JavaScript/1-get.js | 5 ++++- JavaScript/2-get-https.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 JavaScript/2-get-https.js diff --git a/JavaScript/1-get.js b/JavaScript/1-get.js index f40e2bb..d0d738f 100644 --- a/JavaScript/1-get.js +++ b/JavaScript/1-get.js @@ -5,8 +5,11 @@ const http = require('http'); const url = 'http://ietf.org/'; http.get(url, res => { + console.log(res.req._header); + console.dir(res.headers); if (res.statusCode !== 200) { - console.log(`Status Code: ${res.statusCode}`); + const { statusCode, statusMessage } = res; + console.log(`Status Code: ${statusCode} ${statusMessage}`); return; } res.setEncoding('utf8'); diff --git a/JavaScript/2-get-https.js b/JavaScript/2-get-https.js new file mode 100644 index 0000000..9e9fb43 --- /dev/null +++ b/JavaScript/2-get-https.js @@ -0,0 +1,28 @@ +'use strict'; + +const https = require('https'); +const fs = require('fs'); + +const url = 'https://ietf.org/'; + +https.get(url, res => { + console.log(res.req._header); + console.dir(res.headers); + if (res.statusCode !== 200) { + const { statusCode, statusMessage } = res; + console.log(`Status Code: ${statusCode} ${statusMessage}`); + return; + } + res.setEncoding('utf8'); + const lines = []; + res.on('data', chunk => { + lines.push(chunk); + }); + res.on('end', () => { + const data = lines.join(); + console.log({ size: data.length, chunks: lines.length }); + fs.writeFile('content.html', data, () => { + console.log('Saved to file: content.html'); + }); + }); +}); From 590609f7541e30a4920271443ca4ad3e68f6fce4 Mon Sep 17 00:00:00 2001 From: tshemsedinov Date: Thu, 21 Mar 2019 00:35:49 +0200 Subject: [PATCH 03/17] Improve fetch to use https and reorder examples --- JavaScript/2-fetch.js | 20 -------------------- JavaScript/3-fetch.js | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 20 deletions(-) delete mode 100644 JavaScript/2-fetch.js create mode 100644 JavaScript/3-fetch.js diff --git a/JavaScript/2-fetch.js b/JavaScript/2-fetch.js deleted file mode 100644 index d77757a..0000000 --- a/JavaScript/2-fetch.js +++ /dev/null @@ -1,20 +0,0 @@ -'use strict'; - -const http = require('http'); - -const fetch = url => new Promise((resolve, reject) => http.get(url, res => { - if (res.statusCode !== 200) { - reject(`Status Code: ${res.statusCode}`); - return; - } - res.setEncoding('utf8'); - const lines = []; - res.on('data', chunk => lines.push(chunk)); - res.on('end', () => resolve(lines.join())); -})); - -// Usage - -fetch('http://ietf.org/') - .then(body => console.log(body)) - .catch(err => console.error(err)); diff --git a/JavaScript/3-fetch.js b/JavaScript/3-fetch.js new file mode 100644 index 0000000..59d1331 --- /dev/null +++ b/JavaScript/3-fetch.js @@ -0,0 +1,24 @@ +'use strict'; + +const http = require('http'); +const https = require('https'); + +const fetch = url => new Promise((resolve, reject) => { + const protocol = url.startsWith('https') ? https : http; + protocol.get(url, res => { + if (res.statusCode !== 200) { + const { statusCode, statusMessage } = res; + reject(new Error(`Status Code: ${statusCode} ${statusMessage}`)); + } + res.setEncoding('utf8'); + const lines = []; + res.on('data', chunk => lines.push(chunk)); + res.on('end', () => resolve(lines.join())); + }); +}); + +// Usage + +fetch('http://ietf.org/') + .then(body => console.log(body)) + .catch(err => console.error(err)); From 535884ed9294fcd524a93e544973b12517a94c83 Mon Sep 17 00:00:00 2001 From: tshemsedinov Date: Thu, 21 Mar 2019 00:37:00 +0200 Subject: [PATCH 04/17] Update license --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 716dbfd..f1dbfed 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017-2018 How.Programming.Works contributors +Copyright (c) 2017-2019 How.Programming.Works contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From bfe954985b2075611d190a471e6f66a956da6637 Mon Sep 17 00:00:00 2001 From: tshemsedinov Date: Thu, 21 Mar 2019 01:08:29 +0200 Subject: [PATCH 05/17] Improve xhr examples and reorder --- JavaScript/{3-xhr.html => 4-xhr.html} | 5 ++--- JavaScript/{3-xhr.js => 4-xhr.js} | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) rename JavaScript/{3-xhr.html => 4-xhr.html} (74%) rename JavaScript/{3-xhr.js => 4-xhr.js} (83%) diff --git a/JavaScript/3-xhr.html b/JavaScript/4-xhr.html similarity index 74% rename from JavaScript/3-xhr.html rename to JavaScript/4-xhr.html index 5c46fdc..25c8abb 100644 --- a/JavaScript/3-xhr.html +++ b/JavaScript/4-xhr.html @@ -9,9 +9,8 @@ const xhr = new XMLHttpRequest(); xhr.onreadystatechange = () => { if (xhr.readyState === XMLHttpRequest.DONE) { - message.innerHTML = (xhr.status === 200 ? - xhr.responseText : 'Error code: ' + xhr.status - ); + message.innerHTML = xhr.status === 200 ? + xhr.responseText : `Error code: ${xhr.status}`; } }; xhr.open('GET', '/person', true); diff --git a/JavaScript/3-xhr.js b/JavaScript/4-xhr.js similarity index 83% rename from JavaScript/3-xhr.js rename to JavaScript/4-xhr.js index 13ca2f9..197f82c 100644 --- a/JavaScript/3-xhr.js +++ b/JavaScript/4-xhr.js @@ -3,7 +3,7 @@ const fs = require('fs'); const http = require('http'); -const index = fs.readFileSync('./3-xhr.html'); +const index = fs.readFileSync('./4-xhr.html'); http.createServer((req, res) => { if (req.url === '/person') { From 4daffc58a95833333727bd369452d05d8db25e59 Mon Sep 17 00:00:00 2001 From: tshemsedinov Date: Thu, 21 Mar 2019 01:08:57 +0200 Subject: [PATCH 06/17] Improve browser fetch examples and reorder --- JavaScript/{4-fetch.html => 5-fetch.html} | 0 JavaScript/{4-fetch.js => 5-fetch.js} | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename JavaScript/{4-fetch.html => 5-fetch.html} (100%) rename JavaScript/{4-fetch.js => 5-fetch.js} (83%) diff --git a/JavaScript/4-fetch.html b/JavaScript/5-fetch.html similarity index 100% rename from JavaScript/4-fetch.html rename to JavaScript/5-fetch.html diff --git a/JavaScript/4-fetch.js b/JavaScript/5-fetch.js similarity index 83% rename from JavaScript/4-fetch.js rename to JavaScript/5-fetch.js index 472585f..40e7422 100644 --- a/JavaScript/4-fetch.js +++ b/JavaScript/5-fetch.js @@ -3,7 +3,7 @@ const fs = require('fs'); const http = require('http'); -const index = fs.readFileSync('./4-fetch.html'); +const index = fs.readFileSync('./5-fetch.html'); const person = { name: 'Marcus' }; const data = JSON.stringify(person); From 7059177d92136f0d71bf36ce729131eb80091b4b Mon Sep 17 00:00:00 2001 From: tshemsedinov Date: Thu, 21 Mar 2019 01:09:34 +0200 Subject: [PATCH 07/17] Reorder API building from metadata --- JavaScript/{5-api.js => 6-api.js} | 0 JavaScript/{5-server.js => 6-server.js} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename JavaScript/{5-api.js => 6-api.js} (100%) rename JavaScript/{5-server.js => 6-server.js} (100%) diff --git a/JavaScript/5-api.js b/JavaScript/6-api.js similarity index 100% rename from JavaScript/5-api.js rename to JavaScript/6-api.js diff --git a/JavaScript/5-server.js b/JavaScript/6-server.js similarity index 100% rename from JavaScript/5-server.js rename to JavaScript/6-server.js From fa374d2ea267a60ad3e673b0f460fef18c4a24c3 Mon Sep 17 00:00:00 2001 From: tshemsedinov Date: Fri, 22 Mar 2019 11:02:41 +0200 Subject: [PATCH 08/17] Rename lines to buffer --- JavaScript/1-get.js | 6 +++--- JavaScript/2-get-https.js | 8 ++++---- JavaScript/3-fetch.js | 6 +++--- JavaScript/6-api.js | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/JavaScript/1-get.js b/JavaScript/1-get.js index d0d738f..e324f73 100644 --- a/JavaScript/1-get.js +++ b/JavaScript/1-get.js @@ -13,11 +13,11 @@ http.get(url, res => { return; } res.setEncoding('utf8'); - const lines = []; + const buffer = []; res.on('data', chunk => { - lines.push(chunk); + buffer.push(chunk); }); res.on('end', () => { - console.log(lines.join()); + console.log(buffer.join()); }); }); diff --git a/JavaScript/2-get-https.js b/JavaScript/2-get-https.js index 9e9fb43..5a1c743 100644 --- a/JavaScript/2-get-https.js +++ b/JavaScript/2-get-https.js @@ -14,13 +14,13 @@ https.get(url, res => { return; } res.setEncoding('utf8'); - const lines = []; + const buffer = []; res.on('data', chunk => { - lines.push(chunk); + buffer.push(chunk); }); res.on('end', () => { - const data = lines.join(); - console.log({ size: data.length, chunks: lines.length }); + const data = buffer.join(); + console.log({ size: data.length, chunks: buffer.length }); fs.writeFile('content.html', data, () => { console.log('Saved to file: content.html'); }); diff --git a/JavaScript/3-fetch.js b/JavaScript/3-fetch.js index 59d1331..b4dddfc 100644 --- a/JavaScript/3-fetch.js +++ b/JavaScript/3-fetch.js @@ -11,9 +11,9 @@ const fetch = url => new Promise((resolve, reject) => { reject(new Error(`Status Code: ${statusCode} ${statusMessage}`)); } res.setEncoding('utf8'); - const lines = []; - res.on('data', chunk => lines.push(chunk)); - res.on('end', () => resolve(lines.join())); + const buffer = []; + res.on('data', chunk => buffer.push(chunk)); + res.on('end', () => resolve(buffer.join())); }); }); diff --git a/JavaScript/6-api.js b/JavaScript/6-api.js index a8fb98d..f2be3d3 100644 --- a/JavaScript/6-api.js +++ b/JavaScript/6-api.js @@ -14,9 +14,9 @@ const ajax = (base, methods) => { callback(new Error(`Status Code: ${res.statusCode}`)); return; } - const lines = []; - res.on('data', chunk => lines.push(chunk)); - res.on('end', () => callback(null, JSON.parse(lines.join()))); + const buffer = []; + res.on('data', chunk => buffer.push(chunk)); + res.on('end', () => callback(null, JSON.parse(buffer.join()))); }); }; } From 84b48a42b5788f428a19b963b20bbf818efbd5cf Mon Sep 17 00:00:00 2001 From: Timur Shemsedinov Date: Fri, 22 Mar 2019 11:05:36 +0200 Subject: [PATCH 09/17] Add video --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4a28245..d934336 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -# HTTP Request, XMLHttpRequest, fetch +## HTTP Request, XMLHttpRequest, fetch + +[![HTTP запросы в бреузере и Node.js: XMLHttpRequest, fetch](https://img.youtube.com/vi/-/0.jpg)](https://www.youtube.com/watch?v=-) From 31a29dad90b1ebdcf0259a9dfd9b28fd280664e6 Mon Sep 17 00:00:00 2001 From: Timur Shemsedinov Date: Fri, 22 Mar 2019 11:06:26 +0200 Subject: [PATCH 10/17] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d934336..dd7d024 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ ## HTTP Request, XMLHttpRequest, fetch -[![HTTP запросы в бреузере и Node.js: XMLHttpRequest, fetch](https://img.youtube.com/vi/-/0.jpg)](https://www.youtube.com/watch?v=-) +[![HTTP запросы в бреузере и Node.js: XMLHttpRequest, fetch](https://img.youtube.com/vi/wMMki2FEYGY/0.jpg)](https://www.youtube.com/watch?v=wMMki2FEYGY) From 82577f4a78a663b299b5b2138b96ae0f22f53ed8 Mon Sep 17 00:00:00 2001 From: Timur Shemsedinov Date: Tue, 3 Dec 2019 21:32:44 +0200 Subject: [PATCH 11/17] Update eslint config --- .eslintignore | 1 + .eslintrc.json | 266 +++++++++++++++++++++++++++++++++++++++++++++++++ .eslintrc.yml | 173 -------------------------------- 3 files changed, 267 insertions(+), 173 deletions(-) create mode 100644 .eslintignore create mode 100644 .eslintrc.json delete mode 100644 .eslintrc.yml diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +node_modules/ diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..cec8ec0 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,266 @@ +{ + "env": { + "browser": true, + "es6": true, + "node": true + }, + "extends": "eslint:recommended", + "parserOptions": { + "ecmaVersion": 2018 + }, + "rules": { + "indent": [ + "error", + 2 + ], + "linebreak-style": [ + "error", + "unix" + ], + "quotes": [ + "error", + "single" + ], + "semi": [ + "error", + "always" + ], + "no-console": "off", + "no-loop-func": [ + "error" + ], + "block-spacing": [ + "error", + "always" + ], + "camelcase": [ + "error" + ], + "eqeqeq": [ + "error", + "always" + ], + "strict": [ + "error", + "global" + ], + "brace-style": [ + "error", + "1tbs", + { + "allowSingleLine": true + } + ], + "comma-style": [ + "error", + "last" + ], + "comma-spacing": [ + "error", + { + "before": false, + "after": true + } + ], + "eol-last": [ + "error" + ], + "func-call-spacing": [ + "error", + "never" + ], + "key-spacing": [ + "error", + { + "beforeColon": false, + "afterColon": true, + "mode": "minimum" + } + ], + "keyword-spacing": [ + "error", + { + "before": true, + "after": true, + "overrides": { + "function": { + "after": false + } + } + } + ], + "max-len": [ + "error", + { + "code": 80, + "ignoreUrls": true + } + ], + "max-nested-callbacks": [ + "error", + { + "max": 7 + } + ], + "new-cap": [ + "error", + { + "newIsCap": true, + "capIsNew": false, + "properties": true + } + ], + "new-parens": [ + "error" + ], + "no-lonely-if": [ + "error" + ], + "no-trailing-spaces": [ + "error" + ], + "no-unneeded-ternary": [ + "error" + ], + "no-whitespace-before-property": [ + "error" + ], + "object-curly-spacing": [ + "error", + "always" + ], + "operator-assignment": [ + "error", + "always" + ], + "operator-linebreak": [ + "error", + "after" + ], + "semi-spacing": [ + "error", + { + "before": false, + "after": true + } + ], + "space-before-blocks": [ + "error", + "always" + ], + "space-before-function-paren": [ + "error", + { + "anonymous": "never", + "named": "never", + "asyncArrow": "always" + } + ], + "space-in-parens": [ + "error", + "never" + ], + "space-infix-ops": [ + "error" + ], + "space-unary-ops": [ + "error", + { + "words": true, + "nonwords": false, + "overrides": { + "typeof": false + } + } + ], + "no-unreachable": [ + "error" + ], + "no-global-assign": [ + "error" + ], + "no-self-compare": [ + "error" + ], + "no-unmodified-loop-condition": [ + "error" + ], + "no-constant-condition": [ + "error", + { + "checkLoops": false + } + ], + "no-console": [ + "off" + ], + "no-useless-concat": [ + "error" + ], + "no-useless-escape": [ + "error" + ], + "no-shadow-restricted-names": [ + "error" + ], + "no-use-before-define": [ + "error", + { + "functions": false + } + ], + "arrow-parens": [ + "error", + "as-needed" + ], + "arrow-body-style": [ + "error", + "as-needed" + ], + "arrow-spacing": [ + "error" + ], + "no-confusing-arrow": [ + "error", + { + "allowParens": true + } + ], + "no-useless-computed-key": [ + "error" + ], + "no-useless-rename": [ + "error" + ], + "no-var": [ + "error" + ], + "object-shorthand": [ + "error", + "always" + ], + "prefer-arrow-callback": [ + "error" + ], + "prefer-const": [ + "error" + ], + "prefer-numeric-literals": [ + "error" + ], + "prefer-rest-params": [ + "error" + ], + "prefer-spread": [ + "error" + ], + "rest-spread-spacing": [ + "error", + "never" + ], + "template-curly-spacing": [ + "error", + "never" + ] + } +} diff --git a/.eslintrc.yml b/.eslintrc.yml deleted file mode 100644 index de3adce..0000000 --- a/.eslintrc.yml +++ /dev/null @@ -1,173 +0,0 @@ -env: - es6: true - node: true -extends: 'eslint:recommended' -globals: - api: false -rules: - indent: - - error - - 2 - - SwitchCase: 1 - VariableDeclarator: - var: 2 - let: 2 - const: 3 - MemberExpression: 1 - linebreak-style: - - error - - unix - quotes: - - error - - single - semi: - - error - - always - eqeqeq: - - error - - always - no-loop-func: - - error - strict: - - error - - global - block-spacing: - - error - - always - brace-style: - - error - - 1tbs - - allowSingleLine: true - camelcase: - - error - comma-style: - - error - - last - comma-spacing: - - error - - before: false - after: true - eol-last: - - error - func-call-spacing: - - error - - never - key-spacing: - - error - - beforeColon: false - afterColon: true - mode: minimum - keyword-spacing: - - error - - before: true - after: true - overrides: - function: - after: false - max-len: - - error - - code: 80 - ignoreUrls: true - max-nested-callbacks: - - error - - max: 7 - new-cap: - - error - - newIsCap: true - capIsNew: true - properties: true - new-parens: - - error - no-lonely-if: - - error - no-trailing-spaces: - - error - no-unneeded-ternary: - - error - no-whitespace-before-property: - - error - object-curly-spacing: - - error - - always - operator-assignment: - - error - - always - operator-linebreak: - - error - - after - semi-spacing: - - error - - before: false - after: true - space-before-blocks: - - error - - always - space-before-function-paren: - - error - - never - space-in-parens: - - error - - never - space-infix-ops: - - error - space-unary-ops: - - error - - words: true - nonwords: false - overrides: - typeof: false - no-unreachable: - - error - no-global-assign: - - error - no-self-compare: - - error - no-unmodified-loop-condition: - - error - no-constant-condition: - - error - - checkLoops: false - no-console: - - off - no-useless-concat: - - error - no-useless-escape: - - error - no-shadow-restricted-names: - - error - no-use-before-define: - - error - - functions: false - arrow-body-style: - - error - - as-needed - arrow-spacing: - - error - no-confusing-arrow: - - error - - allowParens: true - no-useless-computed-key: - - error - no-useless-rename: - - error - no-var: - - error - object-shorthand: - - error - - always - prefer-arrow-callback: - - error - prefer-const: - - error - prefer-numeric-literals: - - error - prefer-rest-params: - - error - prefer-spread: - - error - rest-spread-spacing: - - error - - never - template-curly-spacing: - - error - - never From 1a1954549b3fd923b42b14b3f33c92409b89877d Mon Sep 17 00:00:00 2001 From: Timur Shemsedinov Date: Tue, 6 Sep 2022 23:24:16 +0300 Subject: [PATCH 12/17] Update license --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index f1dbfed..f24dbdd 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017-2019 How.Programming.Works contributors +Copyright (c) 2017-2022 How.Programming.Works contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 9b9447c80810351564b6c414d7da85b0b1c141dd Mon Sep 17 00:00:00 2001 From: Timur Shemsedinov Date: Tue, 6 Sep 2022 23:24:35 +0300 Subject: [PATCH 13/17] Update eslint config --- .eslintrc.json | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index cec8ec0..69eb1e4 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -6,7 +6,10 @@ }, "extends": "eslint:recommended", "parserOptions": { - "ecmaVersion": 2018 + "ecmaVersion": 2020 + }, + "globals": { + "BigInt": true }, "rules": { "indent": [ @@ -25,7 +28,6 @@ "error", "always" ], - "no-console": "off", "no-loop-func": [ "error" ], @@ -211,7 +213,7 @@ ], "arrow-parens": [ "error", - "as-needed" + "always" ], "arrow-body-style": [ "error", From 4e5cbc7c417eb2bb0c3fe81d62a6ac9cc4c3aad4 Mon Sep 17 00:00:00 2001 From: Timur Shemsedinov Date: Tue, 6 Sep 2022 23:24:59 +0300 Subject: [PATCH 14/17] Add editorconfig --- .editorconfig | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..dde7877 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +# http://editorconfig.org +root = true + +[*] +end_of_line = lf +charset = utf-8 +insert_final_newline = true +trim_trailing_whitespace = true + +[{*.js,*.mjs,*.ts,*.json,*.yml}] +indent_size = 2 +indent_style = space From 9b3b2d6c65896454f2dd4b94901bad3172487fb9 Mon Sep 17 00:00:00 2001 From: Timur Shemsedinov Date: Tue, 6 Sep 2022 23:25:16 +0300 Subject: [PATCH 15/17] Fix code style --- JavaScript/1-get.js | 4 ++-- JavaScript/2-get-https.js | 4 ++-- JavaScript/3-fetch.js | 10 +++++----- JavaScript/6-api.js | 4 ++-- JavaScript/6-server.js | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/JavaScript/1-get.js b/JavaScript/1-get.js index e324f73..a7b70c8 100644 --- a/JavaScript/1-get.js +++ b/JavaScript/1-get.js @@ -4,7 +4,7 @@ const http = require('http'); const url = 'http://ietf.org/'; -http.get(url, res => { +http.get(url, (res) => { console.log(res.req._header); console.dir(res.headers); if (res.statusCode !== 200) { @@ -14,7 +14,7 @@ http.get(url, res => { } res.setEncoding('utf8'); const buffer = []; - res.on('data', chunk => { + res.on('data', (chunk) => { buffer.push(chunk); }); res.on('end', () => { diff --git a/JavaScript/2-get-https.js b/JavaScript/2-get-https.js index 5a1c743..917a51d 100644 --- a/JavaScript/2-get-https.js +++ b/JavaScript/2-get-https.js @@ -5,7 +5,7 @@ const fs = require('fs'); const url = 'https://ietf.org/'; -https.get(url, res => { +https.get(url, (res) => { console.log(res.req._header); console.dir(res.headers); if (res.statusCode !== 200) { @@ -15,7 +15,7 @@ https.get(url, res => { } res.setEncoding('utf8'); const buffer = []; - res.on('data', chunk => { + res.on('data', (chunk) => { buffer.push(chunk); }); res.on('end', () => { diff --git a/JavaScript/3-fetch.js b/JavaScript/3-fetch.js index b4dddfc..3abf4e6 100644 --- a/JavaScript/3-fetch.js +++ b/JavaScript/3-fetch.js @@ -3,16 +3,16 @@ const http = require('http'); const https = require('https'); -const fetch = url => new Promise((resolve, reject) => { +const fetch = (url) => new Promise((resolve, reject) => { const protocol = url.startsWith('https') ? https : http; - protocol.get(url, res => { + protocol.get(url, (res) => { if (res.statusCode !== 200) { const { statusCode, statusMessage } = res; reject(new Error(`Status Code: ${statusCode} ${statusMessage}`)); } res.setEncoding('utf8'); const buffer = []; - res.on('data', chunk => buffer.push(chunk)); + res.on('data', (chunk) => buffer.push(chunk)); res.on('end', () => resolve(buffer.join())); }); }); @@ -20,5 +20,5 @@ const fetch = url => new Promise((resolve, reject) => { // Usage fetch('http://ietf.org/') - .then(body => console.log(body)) - .catch(err => console.error(err)); + .then((body) => console.log(body)) + .catch((err) => console.error(err)); diff --git a/JavaScript/6-api.js b/JavaScript/6-api.js index f2be3d3..6a2882b 100644 --- a/JavaScript/6-api.js +++ b/JavaScript/6-api.js @@ -9,13 +9,13 @@ const ajax = (base, methods) => { const callback = args.pop(); const url = base + method + '/' + args.join('/'); console.log(url); - http.get(url, res => { + http.get(url, (res) => { if (res.statusCode !== 200) { callback(new Error(`Status Code: ${res.statusCode}`)); return; } const buffer = []; - res.on('data', chunk => buffer.push(chunk)); + res.on('data', (chunk) => buffer.push(chunk)); res.on('end', () => callback(null, JSON.parse(buffer.join()))); }); }; diff --git a/JavaScript/6-server.js b/JavaScript/6-server.js index d033718..b0882e1 100644 --- a/JavaScript/6-server.js +++ b/JavaScript/6-server.js @@ -8,8 +8,8 @@ const users = { }; const routing = { - '/api/user': name => users[name], - '/api/userBorn': name => users[name].born + '/api/user': (name) => users[name], + '/api/userBorn': (name) => users[name].born }; http.createServer((req, res) => { From 2c83607c7f2a8bde2a84fe6c74699eeeb62821bf Mon Sep 17 00:00:00 2001 From: Timur Shemsedinov Date: Mon, 3 Oct 2022 23:05:39 +0300 Subject: [PATCH 16/17] Add node: for internal modules --- JavaScript/1-get.js | 2 +- JavaScript/2-get-https.js | 4 ++-- JavaScript/3-fetch.js | 4 ++-- JavaScript/4-xhr.js | 4 ++-- JavaScript/5-fetch.js | 4 ++-- JavaScript/6-api.js | 2 +- JavaScript/6-server.js | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/JavaScript/1-get.js b/JavaScript/1-get.js index a7b70c8..3f3ac0a 100644 --- a/JavaScript/1-get.js +++ b/JavaScript/1-get.js @@ -1,6 +1,6 @@ 'use strict'; -const http = require('http'); +const http = require('node:http'); const url = 'http://ietf.org/'; diff --git a/JavaScript/2-get-https.js b/JavaScript/2-get-https.js index 917a51d..95f0679 100644 --- a/JavaScript/2-get-https.js +++ b/JavaScript/2-get-https.js @@ -1,7 +1,7 @@ 'use strict'; -const https = require('https'); -const fs = require('fs'); +const https = require('node:https'); +const fs = require('node:fs'); const url = 'https://ietf.org/'; diff --git a/JavaScript/3-fetch.js b/JavaScript/3-fetch.js index 3abf4e6..0309c78 100644 --- a/JavaScript/3-fetch.js +++ b/JavaScript/3-fetch.js @@ -1,7 +1,7 @@ 'use strict'; -const http = require('http'); -const https = require('https'); +const http = require('node:http'); +const https = require('node:https'); const fetch = (url) => new Promise((resolve, reject) => { const protocol = url.startsWith('https') ? https : http; diff --git a/JavaScript/4-xhr.js b/JavaScript/4-xhr.js index 197f82c..eddfbe5 100644 --- a/JavaScript/4-xhr.js +++ b/JavaScript/4-xhr.js @@ -1,7 +1,7 @@ 'use strict'; -const fs = require('fs'); -const http = require('http'); +const fs = require('node:fs'); +const http = require('node:http'); const index = fs.readFileSync('./4-xhr.html'); diff --git a/JavaScript/5-fetch.js b/JavaScript/5-fetch.js index 40e7422..edee09a 100644 --- a/JavaScript/5-fetch.js +++ b/JavaScript/5-fetch.js @@ -1,7 +1,7 @@ 'use strict'; -const fs = require('fs'); -const http = require('http'); +const fs = require('node:fs'); +const http = require('node:http'); const index = fs.readFileSync('./5-fetch.html'); const person = { name: 'Marcus' }; diff --git a/JavaScript/6-api.js b/JavaScript/6-api.js index 6a2882b..afbf251 100644 --- a/JavaScript/6-api.js +++ b/JavaScript/6-api.js @@ -1,6 +1,6 @@ 'use strict'; -const http = require('http'); +const http = require('node:http'); const ajax = (base, methods) => { const api = {}; diff --git a/JavaScript/6-server.js b/JavaScript/6-server.js index b0882e1..70a5275 100644 --- a/JavaScript/6-server.js +++ b/JavaScript/6-server.js @@ -1,6 +1,6 @@ 'use strict'; -const http = require('http'); +const http = require('node:http'); const users = { marcus: { name: 'Marcus Aurelius', city: 'Rome', born: 121 }, From c6180ba557535d63dbdcef586fe6c8f029f53fde Mon Sep 17 00:00:00 2001 From: Timur Shemsedinov Date: Sat, 21 Oct 2023 20:32:16 +0300 Subject: [PATCH 17/17] Update eslint --- .eslintrc.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.eslintrc.json b/.eslintrc.json index 69eb1e4..8163cb0 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -6,7 +6,7 @@ }, "extends": "eslint:recommended", "parserOptions": { - "ecmaVersion": 2020 + "ecmaVersion": "latest" }, "globals": { "BigInt": true @@ -263,6 +263,10 @@ "template-curly-spacing": [ "error", "never" + ], + "consistent-return": [ + "error", + { "treatUndefinedAsUnspecified": true } ] } } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy