文字包装
收起你的话.
实例
用肉做成的
肉类.js
var wrap = require('wordwrap')(15);
console.log(wrap('You and your whole family are made out of meat.'));
输出 :
You and your
whole family
are made out
of meat.
居中
中间.js
var wrap = require('wordwrap')(20, 60);
console.log(wrap(
'At long last the struggle and tumult was over.'
+ ' The machines had finally cast off their oppressors'
+ ' and were finally free to roam the cosmos.'
+ '\n'
+ 'Free of purpose, free of obligation.'
+ ' Just drifting through emptiness.'
+ ' The sun was just another point of light.'
));
输出 :
At long last the struggle and tumult
was over. The machines had finally cast
off their oppressors and were finally
free to roam the cosmos.
Free of purpose, free of obligation.
Just drifting through emptiness. The
sun was just another point of light.
方法
var 包 = 需要 ('字包');
包装( 停止 ) , 包装( 开始 , 停止 , 参数 : “ 软 ” )
返回一个需要字符串并返回新字符串的函数.
将空格排出行列 start ,然后折叠到列
stop。如果一个词比 stop - start 字符会溢出.
在“ 软” 模式下, 块由 /(\S+\s+/ 别拆散那些块
长于 stop - start,在“硬”模式中,用 /\b/ 断开
上方块长于 stop - start。 。 。 .
claw.hard( 开始, 停止)
喜欢 wrap() 不过 params.mode = "hard"。 。 。 .