github:https://github.com/patorjk/figlet.js
1、安装
npm install figlet
2、figlet.text( parms,{options},function (err,data){})
parms:需要格式化的字符串
options:参数配置
funtion(err,data):回调
options
Font:字体(String)
Default value:’Standard’
horizontalLayout:布局(String)
Default value:’default’
Values:{‘default’,’full’,’fitted’}
verticalLayout:垂直布局(String)
Default value:’defalut’
Values:{‘defalut’,’full’,’fitted’,’controlled smushing’,’universal smushing’}
Width:宽度(Number)
Default values:undefind
whitespaceBreak:换行(Boolean)
Default value:false
与width配合使用
示例
const figlet = require('figlet')
const arr = ['node','javascript','hello','world']
const options = [
{op1:{
font:'Cygnet',
horizontalLayout:'default',
verticalLayout:'default'
}},
{op2:{
font:'Cygnet',
horizontalLayout:'full',
verticalLayout:'default'
}},
{op3:{
font:'Cygnet',
horizontalLayout:'fitted',
verticalLayout:'default'
}},
{op4:{
font:'Cygnet',
horizontalLayout:'fitted',
verticalLayout:'fitted'
}}
]
function example(items,index){
options.forEach(function (item_,index_){
if(index === index_){
figlet.text(items,item_,function (err,data){
if(err){
return err
}
console.log(data)
})
}
})
}
arr.forEach(example)
output
3、figlet.textSync(parms,options){}
同步方法
示例
console.log(figlet.textSync('Boo!', {
font: 'Ghost',
horizontalLayout: 'default',
verticalLayout: 'default',
width: 80,
whitespaceBreak: true
}));
4、figlet.meta(parms,function(err,options,headerComment){})
parms:字体(String)
options:字体的默认配置
headerComment
示例
figlet.metadata('Standard', function(err, options, headerComment) {
if (err) {
console.log('something went wrong...');
console.dir(err);
return;
}
console.dir(options);
console.log(headerComment);
});
5、figlet.fonts(function(err,data){})获取字体列表
6、figlet.fontsSync()同步获取字体列表
7、figlet.parseFont(name,data)使用其他来源字体
示例
//Sweet.flf是figlet字体
let data = fs.readFileSync(path.join(__dirname, 'Sweet.flf'), 'utf8');
figlet.parseFont('myt', data);
console.log(figlet.textSync('helloworld', {font:'myt'}));