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 0000000000000000000000000000000000000000..39148a1697c2b4a7de51da04d1446c2dd1512e10 --- /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 0000000000000000000000000000000000000000..adbde7a2518527f2549164c5ec9805348085c0de --- /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 0000000000000000000000000000000000000000..14daa394cb9a50c8dd4a7efcb3cdfb1738f3f8b0 --- /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 0000000000000000000000000000000000000000..56a6051ca2b02b04ef92d5150c9ef600403cb1de --- /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 0000000000000000000000000000000000000000..d8263ee9860594d2806b0dfd1bfd17528b0ba2a4 --- /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 0000000000000000000000000000000000000000..e440e5c842586965a7fb77deda2eca68612b1f53 --- /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 0000000000000000000000000000000000000000..bf0d87ab1b2b0ec1a11a3973d2845b42413d9767 --- /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 0000000000000000000000000000000000000000..7813681f5b41c028345ca62a2be376bae70b7f61 --- /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 0000000000000000000000000000000000000000..62f9457511f879886bb7728c986fe10b0ece6bcb --- /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 0000000000000000000000000000000000000000..c7930257dfef505fd996e1d6f22f2f35149990d0 --- /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 0000000000000000000000000000000000000000..301160a93062df23030a69f4b5e4d9bf71866ee9 --- /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 0000000000000000000000000000000000000000..f11c82a4cb6cc2e8f3bdf52b5cdeaad4d5bb214e --- /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