Skip to content

Commit

Permalink
v0.5.3 - Remove wordwrap as dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
DeadAlready committed Jun 18, 2013
1 parent d5da5eb commit 602a2a9
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.js
@@ -1,5 +1,5 @@
var path = require('path');
var wordwrap = require('wordwrap');
var wordwrap = require('./lib/wordwrap');

/* Hack an instance of Argv with process.argv into Argv
so people can do
Expand Down
48 changes: 48 additions & 0 deletions lib/wordwrap.js
@@ -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');
};
};
3 changes: 1 addition & 2 deletions package.json
@@ -1,10 +1,9 @@
{
"name" : "optimist",
"version" : "0.5.2",
"version" : "0.5.3",
"description" : "Light-weight option parsing with an argv hash. No optstrings attached.",
"main" : "./index.js",
"dependencies" : {
"wordwrap" : "~0.0.2"
},
"devDependencies" : {
"hashish": "~0.0.4",
Expand Down

0 comments on commit 602a2a9

Please sign in to comment.