-
Notifications
You must be signed in to change notification settings - Fork 991
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v0.5.3 - Remove wordwrap as dependency
- Loading branch information
1 parent
d5da5eb
commit 602a2a9
Showing
3 changed files
with
50 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict'; | ||
|
||
module.exports = function (start, stop) { | ||
|
||
if (!stop) { | ||
stop = start; | ||
start = 0; | ||
} | ||
|
||
var re = /(\S+\s+)/; | ||
|
||
return function (text) { | ||
var chunks = text.toString().split(re); | ||
|
||
return chunks.reduce(function (lines, rawChunk) { | ||
if (rawChunk === '') return lines; | ||
|
||
var chunk = rawChunk.replace(/\t/g, ' '); | ||
|
||
var i = lines.length - 1; | ||
if (lines[i].length + chunk.length > stop) { | ||
lines[i] = lines[i].replace(/\s+$/, ''); | ||
|
||
chunk.split(/\n/).forEach(function (c) { | ||
lines.push( | ||
new Array(start + 1).join(' ') | ||
+ c.replace(/^\s+/, '') | ||
); | ||
}); | ||
} | ||
else if (chunk.match(/\n/)) { | ||
var xs = chunk.split(/\n/); | ||
lines[i] += xs.shift(); | ||
xs.forEach(function (c) { | ||
lines.push( | ||
new Array(start + 1).join(' ') | ||
+ c.replace(/^\s+/, '') | ||
); | ||
}); | ||
} | ||
else { | ||
lines[i] += chunk; | ||
} | ||
|
||
return lines; | ||
}, [ new Array(start + 1).join(' ') ]).join('\n'); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters