[Pkg-javascript-commits] [node-pad] 01/03: Import Upstream version 1.0.2
Paolo Greppi
paolog-guest at moszumanska.debian.org
Fri Dec 23 10:30:32 UTC 2016
This is an automated email from the git hooks/post-receive script.
paolog-guest pushed a commit to branch master
in repository node-pad.
commit 3d41209da555d1f2139b6593285eca608deb87da
Author: Paolo Greppi <paolo.greppi at libpf.com>
Date: Fri Dec 23 09:59:29 2016 +0000
Import Upstream version 1.0.2
---
.npmignore | 4 ++++
LICENSE | 28 +++++++++++++++++++++++
README.md | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
lib/colors.js | 17 ++++++++++++++
lib/index.js | 47 +++++++++++++++++++++++++++++++++++++
package.json | 35 ++++++++++++++++++++++++++++
samples/left.js | 4 ++++
samples/right.js | 4 ++++
8 files changed, 209 insertions(+)
diff --git a/.npmignore b/.npmignore
new file mode 100644
index 0000000..4c9bd0a
--- /dev/null
+++ b/.npmignore
@@ -0,0 +1,4 @@
+/src
+/test
+/Makefile
+.travis.yml
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..335db7d
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,28 @@
+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.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..29b73f7
--- /dev/null
+++ b/README.md
@@ -0,0 +1,70 @@
+[![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
+```
diff --git a/lib/colors.js b/lib/colors.js
new file mode 100644
index 0000000..2a236a5
--- /dev/null
+++ b/lib/colors.js
@@ -0,0 +1,17 @@
+// 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);
+};
diff --git a/lib/index.js b/lib/index.js
new file mode 100644
index 0000000..fc6e6db
--- /dev/null
+++ b/lib/index.js
@@ -0,0 +1,47 @@
+// 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;
+ }
+};
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..e68bcfc
--- /dev/null
+++ b/package.json
@@ -0,0 +1,35 @@
+{
+ "name": "pad",
+ "description": "Left and right string padding",
+ "version": "1.0.2",
+ "author": "David Worms <david at adaltas.com>",
+ "contributors": [
+ {
+ "name": "David Worms",
+ "email": "david at 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"
+ }
+}
diff --git a/samples/left.js b/samples/left.js
new file mode 100644
index 0000000..68a6566
--- /dev/null
+++ b/samples/left.js
@@ -0,0 +1,4 @@
+
+var assert = require('assert');
+var pad = require('pad');
+assert.equal('pad ', pad('pad', 6));
diff --git a/samples/right.js b/samples/right.js
new file mode 100644
index 0000000..7b61a22
--- /dev/null
+++ b/samples/right.js
@@ -0,0 +1,4 @@
+
+var assert = require('assert');
+var pad = require('pad');
+assert.equal( ' pad', pad(5, 'pad'));
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-pad.git
More information about the Pkg-javascript-commits
mailing list