package/package.json000644 000765 000024 0000001360 13002660204013006 0ustar00000000 000000 { "name": "pad", "description": "Left and right string padding", "version": "1.0.2", "author": "David Worms ", "contributors": [ { "name": "David Worms", "email": "david@adaltas.com" } ], "devDependencies": { "coffee-script": "^1.11.1", "mocha": "^3.1.2", "should": "^11.1.1" }, "engines": { "node": ">= 0.4.0" }, "keywords": [ "pad", "string" ], "license": "BSD-3-Clause", "main": "./lib", "repository": { "type": "git", "url": "https://github.com/wdavidw/node-pad.git" }, "scripts": { "coffee": "coffee -b -o lib src", "pretest": "coffee -b -o lib src", "test": "mocha --compilers coffee:coffee-script/register --reporter dot" } } package/.npmignore000664 000765 000024 0000000040 12456247332012532 0ustar00000000 000000 /src /test /Makefile .travis.ymlpackage/README.md000644 000765 000024 0000003237 13002657675012026 0ustar00000000 000000 [![Build Status](https://secure.travis-ci.org/wdavidw/node-pad.png)](http://travis-ci.org/wdavidw/node-pad) Node Pad is a simple function to pad strings in both left and right directions. ## Exemples ```javascript pad('pad', 5) # "pad " pad(5, 'pad') # " pad" pad('pad', 5, '+') # "pad++" pad(5, 'pad', '+') # "++pad" ``` ## Left padding: `pad(length, text, [options])` Left padding occurs when the first argument is a number and the second argument is a string. ```javascript var pad = require('pad'); pad(5, 'pad', '-').should.eql('-pad'); ``` ## Right padding: `pad(text, length, [options])` Right padding occurs when the first argument is a string and the second argument is a number. ```javascript var pad = require('pad'); pad('pad', 6).should.eql('pad '); ``` ## Options Options are provided as a third argument and are all optional. A string argument it is interpreted as the "char" option. Accepted options include: * `char` (string) The character used to fill the gap. * `colors` (boolean) Ajust to hidden terminal color characters, you may also use `require 'pad/lib/colors'` to avoid passing this option. * `strip` (boolean) Remove characters from text if length smaller than text length, default to "false". ## Installing Via [npm](http://github.com/isaacs/npm): ```bash npm install pad ``` Via git (or downloaded tarball), copy or link the project from a discoverable Node directory: ```bash git clone http://github.com/wdavidw/node-pad.git ``` ## Testing Clone the repo, install the development dependencies and run the suite: ```bash git clone http://github.com/wdavidw/node-pad.git . npm install make test ``` package/LICENSE000644 000765 000024 0000002770 12052137227011543 0ustar00000000 000000 Copyright (c) 2008-2012, SARL Adaltas. All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of SARL Adaltas nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of SARL Adaltas. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package/lib/colors.js000644 000765 000024 0000000500 13002660115013121 0ustar00000000 000000 // Generated by CoffeeScript 1.11.1 var pad; pad = require('./index'); module.exports = function(string, size, options) { if (options == null) { options = {}; } if (typeof options === 'string') { options = { char: options }; } options.colors = true; return pad(string, size, options); }; package/lib/index.js000644 000765 000024 0000002177 13002660115012743 0ustar00000000 000000 // Generated by CoffeeScript 1.11.1 module.exports = function(text, length, options) { var escapecolor, i, invert, j, pad, padlength, ref, ref1; if (options == null) { options = {}; } invert = typeof text === 'number'; if (invert) { ref = [text, length], length = ref[0], text = ref[1]; } if (typeof options === 'string') { options = { char: options }; } if (options.char == null) { options.char = ' '; } 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; length += text.length - text.replace(escapecolor, '').length; } 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 (invert) { return pad + text; } else { return text + pad; } }; package/samples/left.js000644 000765 000024 0000000142 12052137227013461 0ustar00000000 000000 var assert = require('assert'); var pad = require('pad'); assert.equal('pad ', pad('pad', 6)); package/samples/right.js000644 000765 000024 0000000142 12052137227013644 0ustar00000000 000000 var assert = require('assert'); var pad = require('pad'); assert.equal( ' pad', pad(5, 'pad'));