From be0adbafb28c43f49e2790f0f0ad0c2e6198236a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=87=A4=E6=AC=A3?= <2111290549@qq.com> Date: Mon, 28 Feb 2022 16:05:39 +0800 Subject: [PATCH] =?UTF-8?q?22,24=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homework.js" | 7 +++ .../moduleCount.js" | 32 ++++++++++ .../demo.js" | 59 +++++++++++++++++++ .../homework2/1.txt" | 1 + .../homework2/2.txt" | 1 + .../homework2/3.txt" | 1 + .../homework2/4.txt" | 1 + .../homework2/5.txt" | 1 + .../homework2/6.txt" | 1 + .../homework2/7.txt" | 1 + .../homework2/8.txt" | 1 + .../homework2/9.txt" | 1 + 12 files changed, 107 insertions(+) create mode 100644 "\347\216\213\345\207\244\346\254\243/2022.02.22\344\275\234\344\270\232/homework.js" create mode 100644 "\347\216\213\345\207\244\346\254\243/2022.02.22\344\275\234\344\270\232/moduleCount.js" create mode 100644 "\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/demo.js" create mode 100644 "\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/1.txt" create mode 100644 "\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/2.txt" create mode 100644 "\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/3.txt" create mode 100644 "\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/4.txt" create mode 100644 "\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/5.txt" create mode 100644 "\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/6.txt" create mode 100644 "\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/7.txt" create mode 100644 "\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/8.txt" create mode 100644 "\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/9.txt" diff --git "a/\347\216\213\345\207\244\346\254\243/2022.02.22\344\275\234\344\270\232/homework.js" "b/\347\216\213\345\207\244\346\254\243/2022.02.22\344\275\234\344\270\232/homework.js" new file mode 100644 index 0000000..39148a1 --- /dev/null +++ "b/\347\216\213\345\207\244\346\254\243/2022.02.22\344\275\234\344\270\232/homework.js" @@ -0,0 +1,7 @@ +let math = require("./moduleCount") +try { + let result = math.handle(1, 3, "add"); + console.log(result); +} catch (error) { + console.log(error.message); +} \ No newline at end of file diff --git "a/\347\216\213\345\207\244\346\254\243/2022.02.22\344\275\234\344\270\232/moduleCount.js" "b/\347\216\213\345\207\244\346\254\243/2022.02.22\344\275\234\344\270\232/moduleCount.js" new file mode 100644 index 0000000..adbde7a --- /dev/null +++ "b/\347\216\213\345\207\244\346\254\243/2022.02.22\344\275\234\344\270\232/moduleCount.js" @@ -0,0 +1,32 @@ +//add,subtract,mutioply and divide +function add(a, b) { + + if (isNaN(a) || isNaN(b)) { + console.log(a); + throw new Error("请输入数字"); + } + return a + b; +} +function subtract(a,b){ + if(isNaN(a)||isNaN(b)){ + throw new Error("请输入数字"); + } + return a+b; +} + +var count = { + add:function(a,b){ + return a+b; + } +} +function handle(a,b,funcname){ + if(isNaN(a)||isNaN(b)){ + throw new Error("请输入数字"); + } + return count[funcname](a,b) +} +module.exports={ + add:add, + subtract:subtract, + handle:handle +} \ No newline at end of file diff --git "a/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/demo.js" "b/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/demo.js" new file mode 100644 index 0000000..14daa39 --- /dev/null +++ "b/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/demo.js" @@ -0,0 +1,59 @@ +let fs = require("fs"); + +let createFile = { + + /** + * 创建文件夹 + * @param {*} dir + */ + createPath: function (dir) { + //文件夹可能存在 + if (fs.existsSync(dir)) { + return; + } + fs.mkdirSync(dir); + + }, + + /** + * 创建内容-可扩展 request模块可爬取内容 + * @param {*} num + * @returns + */ + createContent: function (num) { + + return num + ''; + + }, + + /** + * 写入文件与内容 + * @param {*} filePath + * @param {*} content + */ + createFile: function (filePath, content) { + //flags w 可写 + console.log(filePath); + let fd = fs.openSync(filePath, 'w'); + fs.writeSync(fd, content); + fs.closeSync(fd); + + }, + + handle: function (num, dir) { + //目录不存在则创建 + this.createPath(dir); + //循环的创建文件与内容 + for (let i = 1; i < num; i++) { + let fileName = dir + '/' + i + '.txt';//可以进一步抽离 + let content = this.createContent(i); + this.createFile(fileName, content); + + } + + + } + +} + +createFile.handle(10, './homework2'); diff --git "a/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/1.txt" "b/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/1.txt" new file mode 100644 index 0000000..56a6051 --- /dev/null +++ "b/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/1.txt" @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git "a/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/2.txt" "b/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/2.txt" new file mode 100644 index 0000000..d8263ee --- /dev/null +++ "b/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/2.txt" @@ -0,0 +1 @@ +2 \ No newline at end of file diff --git "a/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/3.txt" "b/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/3.txt" new file mode 100644 index 0000000..e440e5c --- /dev/null +++ "b/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/3.txt" @@ -0,0 +1 @@ +3 \ No newline at end of file diff --git "a/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/4.txt" "b/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/4.txt" new file mode 100644 index 0000000..bf0d87a --- /dev/null +++ "b/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/4.txt" @@ -0,0 +1 @@ +4 \ No newline at end of file diff --git "a/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/5.txt" "b/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/5.txt" new file mode 100644 index 0000000..7813681 --- /dev/null +++ "b/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/5.txt" @@ -0,0 +1 @@ +5 \ No newline at end of file diff --git "a/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/6.txt" "b/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/6.txt" new file mode 100644 index 0000000..62f9457 --- /dev/null +++ "b/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/6.txt" @@ -0,0 +1 @@ +6 \ No newline at end of file diff --git "a/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/7.txt" "b/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/7.txt" new file mode 100644 index 0000000..c793025 --- /dev/null +++ "b/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/7.txt" @@ -0,0 +1 @@ +7 \ No newline at end of file diff --git "a/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/8.txt" "b/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/8.txt" new file mode 100644 index 0000000..301160a --- /dev/null +++ "b/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/8.txt" @@ -0,0 +1 @@ +8 \ No newline at end of file diff --git "a/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/9.txt" "b/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/9.txt" new file mode 100644 index 0000000..f11c82a --- /dev/null +++ "b/\347\216\213\345\207\244\346\254\243/2022.02.24\344\275\234\344\270\232/homework2/9.txt" @@ -0,0 +1 @@ +9 \ No newline at end of file -- Gitee