Skip to content

Commit

Permalink
Removed dependency on wordwrap module.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Ford committed Nov 22, 2013
2 parents ea14630 + 6655688 commit 79ec980
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea/
node_modules/
node_modules/
*.swp
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var path = require('path');
var minimist = require('minimist');
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
50 changes: 50 additions & 0 deletions lib/wordwrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Simplified version of https://github.com/substack/node-wordwrap

'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');
};
};
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"description" : "Light-weight option parsing with an argv hash. No optstrings attached.",
"main" : "./index.js",
"dependencies" : {
"wordwrap" : "~0.0.2",
"minimist" : "~0.0.1"
},
"devDependencies" : {
Expand Down

0 comments on commit 79ec980

Please sign in to comment.