diff --git "a/node/2022.02.23 \345\212\240\345\207\217\344\271\230\351\231\244/\346\216\245\346\224\266.js" "b/node/2022.02.23 \345\212\240\345\207\217\344\271\230\351\231\244/\346\216\245\346\224\266.js" new file mode 100644 index 0000000000000000000000000000000000000000..2a6b909cc2270fb3450ae1204d70ee625bcc566b --- /dev/null +++ "b/node/2022.02.23 \345\212\240\345\207\217\344\271\230\351\231\244/\346\216\245\346\224\266.js" @@ -0,0 +1,10 @@ +// 接收 +let math = require("./暴露"); + +// 进行运算 +try{ + let result = math.operation(147.5, 8, "/") + console.log(result); +}catch(error) { + console.log(error.message); +} \ No newline at end of file diff --git "a/node/2022.02.23 \345\212\240\345\207\217\344\271\230\351\231\244/\346\232\264\351\234\262.js" "b/node/2022.02.23 \345\212\240\345\207\217\344\271\230\351\231\244/\346\232\264\351\234\262.js" new file mode 100644 index 0000000000000000000000000000000000000000..1c24c87739ff73e2e28759ea887911ce2fb83ad8 --- /dev/null +++ "b/node/2022.02.23 \345\212\240\345\207\217\344\271\230\351\231\244/\346\232\264\351\234\262.js" @@ -0,0 +1,26 @@ +// 做加减乘除运算 +let count = { + "+":function(a1, a2) { + return a1 + a2; + }, + "-":function(a1, a2) { + return a1 - a2; + }, + "*":function(a1, a2) { + return a1 * a2; + }, + "/":function(a1, a2) { + return a1 / a2; + } +} + +// 判断是否为数字 +function operation(a1, a2, symbol) { + if(isNaN(a1) || isNaN(a2)) { + throw Error('请输入数字!'); + } + return count[symbol](a1, a2); +} + +// 暴露 +module.exports.operation = operation; \ No newline at end of file diff --git "a/node/2022.02.24 \345\220\214\346\255\245\346\226\207\344\273\266\347\232\204\345\206\231\345\205\245/\345\220\214\346\255\245\346\226\207\344\273\266\345\206\231\345\205\245.js" "b/node/2022.02.24 \345\220\214\346\255\245\346\226\207\344\273\266\347\232\204\345\206\231\345\205\245/\345\220\214\346\255\245\346\226\207\344\273\266\345\206\231\345\205\245.js" new file mode 100644 index 0000000000000000000000000000000000000000..61a0502afc675c2209ad7c0cd2f63275c3819cd8 --- /dev/null +++ "b/node/2022.02.24 \345\220\214\346\255\245\346\226\207\344\273\266\347\232\204\345\206\231\345\205\245/\345\220\214\346\255\245\346\226\207\344\273\266\345\206\231\345\205\245.js" @@ -0,0 +1,42 @@ +// 创建fs模块 +let fs = require("fs"); + +let createFile = { + + // 创建文件夹 + createPath: function (dir) { + // 文件夹可能存在 + if(fs.existsSync(dir)){ + return ; + } + fs.mkdirSync(dir); + }, + + // 创建内容-可扩展 request模块可爬取内容 + createContent:function(num){ + return num+''; + }, + + // 写入文件与内容 + createFile:function(filePath,content){ + 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