Socket
Socket
Sign inDemoInstall

pad

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pad - npm Package Compare versions

Comparing version 0.1.0 to 1.0.0

37

lib/index.js
// 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc