【Node.js 如何优雅的封装一个实用函数的 npm 包】,作者:萧萧fe,链接:https://t.cn/ESAhM2D
导读
为什么要封装一个实用函数的 npm 包?
当你连续写了多个 Node 应用, 都想要 console 漂亮一点, 你可能会像下面这样封装一个函数
import chalk from "chalk";
function noop(msg: string): string {
return msg
}
function log(fn: Function): (msg: string) => void {
return (msg: string): void => {
console.log(fn(msg));
};
}
export default {
success: log(chalk.green),
error: log(chalk.red),
warn: log(chalk.yellow),
info: log(chalk.cyan),
log: log(noop)
};
来源:掘金
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
导读
为什么要封装一个实用函数的 npm 包?
当你连续写了多个 Node 应用, 都想要 console 漂亮一点, 你可能会像下面这样封装一个函数
import chalk from "chalk";
function noop(msg: string): string {
return msg
}
function log(fn: Function): (msg: string) => void {
return (msg: string): void => {
console.log(fn(msg));
};
}
export default {
success: log(chalk.green),
error: log(chalk.red),
warn: log(chalk.yellow),
info: log(chalk.cyan),
log: log(noop)
};
来源:掘金
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
AI核心代码 估值一个亿,编程没有那么复杂,哈哈
package myself;
import java.util.Scanner;
/**
*
* Title: www.qjkj2018.com
* Description: Ai核心代码,皮这一下我非常开心
* @大数据java架构师
* @date 2018年12月15日
*/
public class AiMain {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
String str;
while(true) {
str=scanner.next();
str=str.replace("吗", "");
str=str.replace("谁", "小可爱");
str=str.replace("你", "我");
str=str.replace("?", "!");
str=str.replace("?", "!");
System.out.println(str);
}
}
package myself;
import java.util.Scanner;
/**
*
* Title: www.qjkj2018.com
* Description: Ai核心代码,皮这一下我非常开心
* @大数据java架构师
* @date 2018年12月15日
*/
public class AiMain {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
String str;
while(true) {
str=scanner.next();
str=str.replace("吗", "");
str=str.replace("谁", "小可爱");
str=str.replace("你", "我");
str=str.replace("?", "!");
str=str.replace("?", "!");
System.out.println(str);
}
}
public class Aisatsu{
public static void main(String[] args){
System.out.println("おはよう!");
(Google)public class Aisatsu {public static void main(String [] args){ System.out.println(“早上好!”);
(百度)public class Aisatsu{ public static void main(String[] args){
public static void main(String[] args){
System.out.println("おはよう!");
(Google)public class Aisatsu {public static void main(String [] args){ System.out.println(“早上好!”);
(百度)public class Aisatsu{ public static void main(String[] args){
✋热门推荐