Comparing version 0.1.0 to 1.0.0
// Generated by CoffeeScript 1.9.3 | ||
module.exports = function(string, size, options) { | ||
var escapecolor, i, j, pad, prefix, ref, ref1; | ||
module.exports = function(text, length, options) { | ||
var escapecolor, i, invert, j, pad, padlength, ref, ref1; | ||
if (options == null) { | ||
options = {}; | ||
} | ||
prefix = typeof string === 'number'; | ||
if (prefix) { | ||
ref = [string, size], size = ref[0], string = ref[1]; | ||
invert = typeof text === 'number'; | ||
if (invert) { | ||
ref = [text, length], length = ref[0], text = ref[1]; | ||
} | ||
@@ -19,17 +19,30 @@ if (typeof options === 'string') { | ||
} | ||
string = string.toString(); | ||
if (options.strip == null) { | ||
options.strip = false; | ||
} | ||
text = text.toString(); | ||
pad = ''; | ||
if (options.colors) { | ||
escapecolor = /\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]/g; | ||
size += string.length - string.replace(escapecolor, '').length; | ||
length += text.length - text.replace(escapecolor, '').length; | ||
} | ||
size = size - string.length; | ||
for (i = j = 0, ref1 = size; 0 <= ref1 ? j < ref1 : j > ref1; i = 0 <= ref1 ? ++j : --j) { | ||
padlength = length - text.length; | ||
if (padlength < 0) { | ||
if (options.strip) { | ||
if (invert) { | ||
return text.substr(length * -1); | ||
} else { | ||
return text.substr(0, length); | ||
} | ||
} | ||
return text; | ||
} | ||
for (i = j = 0, ref1 = padlength; 0 <= ref1 ? j < ref1 : j > ref1; i = 0 <= ref1 ? ++j : --j) { | ||
pad += options.char; | ||
} | ||
if (prefix) { | ||
return pad + string; | ||
if (invert) { | ||
return pad + text; | ||
} else { | ||
return string + pad; | ||
return text + pad; | ||
} | ||
}; |
{ | ||
"name": "pad", | ||
"version": "0.1.0", | ||
"version": "1.0.0", | ||
"description": "Left and right string padding", | ||
@@ -11,5 +11,5 @@ "author": "David Worms <david@adaltas.com>", | ||
"devDependencies": { | ||
"mocha": "2.2.5", | ||
"coffee-script": "1.9.3", | ||
"should": "6.0.3" | ||
"mocha": "^2.3.3", | ||
"coffee-script": "^1.10.0", | ||
"should": "^7.1.0" | ||
}, | ||
@@ -16,0 +16,0 @@ "engines": { |
@@ -14,3 +14,3 @@ [![Build Status](https://secure.travis-ci.org/wdavidw/node-pad.png)](http://travis-ci.org/wdavidw/node-pad) | ||
## `pad(size, text, [options])`: Left padding | ||
## `pad(length, text, [options])`: Left padding | ||
@@ -25,3 +25,3 @@ Node Pad does left padding when the first argument is a number and the second | ||
## `pad(text, size, [options])`: Right padding | ||
## `pad(text, length, [options])`: Right padding | ||
@@ -46,2 +46,5 @@ Node Pad does right padding when the first argument is a string and the second | ||
`require 'pad/lib/colors'` to avoid passing this option. | ||
* `strip` (boolean) | ||
Remove characters from text if length smaller than text length, default to | ||
"false". | ||
@@ -48,0 +51,0 @@ ## Installing |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
5898
68
1
71