标签:move 替换 注册表 require rds auth view 发布 author
常用命令行选项有
所有的模块在他的根目录下必须包含一个package.json文件。他是定义一个模块,包括其依赖关系的一个简单的JSON文件包。该package.json文件包含多个指令告诉Node管理器如何处理模块。例如:
{ "name":"my_module", "version":"0.1.0", "description":"a simple node.js module", "dependencies":{ "express":"latest" } }
1 var censoredWords=["sad","bad","mad"]; 2 var customCensoredWords=[]; 3 function censor(inStr){ 4 for(idx in censoredWords){ 5 inStr=inStr.replace(censoredWords[idx],"****"); 6 } 7 for(idx in customCensoredWords){ 8 inStr=inStr.replace(customCensoredWords[idx],"****"); 9 } 10 return inStr; 11 } 12 13 function addCensoredWord (word) { 14 customCensoredWords.push(word); 15 } 16 function getCensoredWords(){ 17 return censoredWords.concat(customCensoredWords); 18 } 19 20 exports.censor=censor; 21 exports.addCensoredWord=addCensoredWord; 22 exports.getCensoredWords=getCensoredWords;
1 { 2 "author":"zhouruxian", 3 "name":"censorify", 4 "version":"0.1.1", 5 "description":"hi", 6 "main":"censortext", 7 "dependencies":{}, 8 "engines":{ 9 "node":"*" 10 } 11 }
npm pack
npm pack会在.../censorify文件夹中生成censorify-0.1.1.tgz文件。
1 var censor=require("censorify"); 2 console.log(censor.getCensoredWords()); 3 console.log(censor.censor("Some very sad,badand mad text.")); 4 censor.addCensoredWord("gloomy"); 5 console.log(censor.getCensoredWords()); 6 console.log(censor.censor("a very gloomy day."));
结果显示一些字符串被“****”替换了。
标签:move 替换 注册表 require rds auth view 发布 author
原文地址:http://www.cnblogs.com/dongzixiansheng/p/7019663.html