README.markdown (1827B)
1 wordwrap 2 ======== 3 4 Wrap your words. 5 6 example 7 ======= 8 9 made out of meat 10 ---------------- 11 12 meat.js 13 14 var wrap = require('wordwrap')(15); 15 console.log(wrap('You and your whole family are made out of meat.')); 16 17 output: 18 19 You and your 20 whole family 21 are made out 22 of meat. 23 24 centered 25 -------- 26 27 center.js 28 29 var wrap = require('wordwrap')(20, 60); 30 console.log(wrap( 31 'At long last the struggle and tumult was over.' 32 + ' The machines had finally cast off their oppressors' 33 + ' and were finally free to roam the cosmos.' 34 + '\n' 35 + 'Free of purpose, free of obligation.' 36 + ' Just drifting through emptiness.' 37 + ' The sun was just another point of light.' 38 )); 39 40 output: 41 42 At long last the struggle and tumult 43 was over. The machines had finally cast 44 off their oppressors and were finally 45 free to roam the cosmos. 46 Free of purpose, free of obligation. 47 Just drifting through emptiness. The 48 sun was just another point of light. 49 50 methods 51 ======= 52 53 var wrap = require('wordwrap'); 54 55 wrap(stop), wrap(start, stop, params={mode:"soft"}) 56 --------------------------------------------------- 57 58 Returns a function that takes a string and returns a new string. 59 60 Pad out lines with spaces out to column `start` and then wrap until column 61 `stop`. If a word is longer than `stop - start` characters it will overflow. 62 63 In "soft" mode, split chunks by `/(\S+\s+/` and don't break up chunks which are 64 longer than `stop - start`, in "hard" mode, split chunks with `/\b/` and break 65 up chunks longer than `stop - start`. 66 67 wrap.hard(start, stop) 68 ---------------------- 69 70 Like `wrap()` but with `params.mode = "hard"`.