summaryrefslogtreecommitdiffstats
path: root/node_modules/wide-align
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/wide-align')
-rw-r--r--node_modules/wide-align/LICENSE14
-rw-r--r--node_modules/wide-align/README.md47
-rw-r--r--node_modules/wide-align/align.js65
-rw-r--r--node_modules/wide-align/package.json66
4 files changed, 192 insertions, 0 deletions
diff --git a/node_modules/wide-align/LICENSE b/node_modules/wide-align/LICENSE
new file mode 100644
index 0000000..f4be44d
--- /dev/null
+++ b/node_modules/wide-align/LICENSE
@@ -0,0 +1,14 @@
+Copyright (c) 2015, Rebecca Turner <me@re-becca.org>
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
diff --git a/node_modules/wide-align/README.md b/node_modules/wide-align/README.md
new file mode 100644
index 0000000..32f1be0
--- /dev/null
+++ b/node_modules/wide-align/README.md
@@ -0,0 +1,47 @@
+wide-align
+----------
+
+A wide-character aware text alignment function for use in terminals / on the
+console.
+
+### Usage
+
+```
+var align = require('wide-align')
+
+// Note that if you view this on a unicode console, all of the slashes are
+// aligned. This is because on a console, all narrow characters are
+// an en wide and all wide characters are an em. In browsers, this isn't
+// held to and wide characters like "古" can be less than two narrow
+// characters even with a fixed width font.
+
+console.log(align.center('abc', 10)) // ' abc '
+console.log(align.center('古古古', 10)) // ' 古古古 '
+console.log(align.left('abc', 10)) // 'abc '
+console.log(align.left('古古古', 10)) // '古古古 '
+console.log(align.right('abc', 10)) // ' abc'
+console.log(align.right('古古古', 10)) // ' 古古古'
+```
+
+### Functions
+
+#### `align.center(str, length)` → `str`
+
+Returns *str* with spaces added to both sides such that that it is *length*
+chars long and centered in the spaces.
+
+#### `align.left(str, length)` → `str`
+
+Returns *str* with spaces to the right such that it is *length* chars long.
+
+### `align.right(str, length)` → `str`
+
+Returns *str* with spaces to the left such that it is *length* chars long.
+
+### Origins
+
+These functions were originally taken from
+[cliui](https://npmjs.com/package/cliui). Changes include switching to the
+MUCH faster pad generation function from
+[lodash](https://npmjs.com/package/lodash), making center alignment pad
+both sides and adding left alignment.
diff --git a/node_modules/wide-align/align.js b/node_modules/wide-align/align.js
new file mode 100644
index 0000000..4f94ca4
--- /dev/null
+++ b/node_modules/wide-align/align.js
@@ -0,0 +1,65 @@
+'use strict'
+var stringWidth = require('string-width')
+
+exports.center = alignCenter
+exports.left = alignLeft
+exports.right = alignRight
+
+// lodash's way of generating pad characters.
+
+function createPadding (width) {
+ var result = ''
+ var string = ' '
+ var n = width
+ do {
+ if (n % 2) {
+ result += string;
+ }
+ n = Math.floor(n / 2);
+ string += string;
+ } while (n);
+
+ return result;
+}
+
+function alignLeft (str, width) {
+ var trimmed = str.trimRight()
+ if (trimmed.length === 0 && str.length >= width) return str
+ var padding = ''
+ var strWidth = stringWidth(trimmed)
+
+ if (strWidth < width) {
+ padding = createPadding(width - strWidth)
+ }
+
+ return trimmed + padding
+}
+
+function alignRight (str, width) {
+ var trimmed = str.trimLeft()
+ if (trimmed.length === 0 && str.length >= width) return str
+ var padding = ''
+ var strWidth = stringWidth(trimmed)
+
+ if (strWidth < width) {
+ padding = createPadding(width - strWidth)
+ }
+
+ return padding + trimmed
+}
+
+function alignCenter (str, width) {
+ var trimmed = str.trim()
+ if (trimmed.length === 0 && str.length >= width) return str
+ var padLeft = ''
+ var padRight = ''
+ var strWidth = stringWidth(trimmed)
+
+ if (strWidth < width) {
+ var padLeftBy = parseInt((width - strWidth) / 2, 10)
+ padLeft = createPadding(padLeftBy)
+ padRight = createPadding(width - (strWidth + padLeftBy))
+ }
+
+ return padLeft + trimmed + padRight
+}
diff --git a/node_modules/wide-align/package.json b/node_modules/wide-align/package.json
new file mode 100644
index 0000000..f1fbb09
--- /dev/null
+++ b/node_modules/wide-align/package.json
@@ -0,0 +1,66 @@
+{
+ "_from": "wide-align@^1.1.0",
+ "_id": "wide-align@1.1.3",
+ "_inBundle": false,
+ "_integrity": "sha512-QGkOQc8XL6Bt5PwnsExKBPuMKBxnGxWWW3fU55Xt4feHozMUhdUMaBCk290qpm/wG5u/RSKzwdAC4i51YigihA==",
+ "_location": "/wide-align",
+ "_phantomChildren": {},
+ "_requested": {
+ "type": "range",
+ "registry": true,
+ "raw": "wide-align@^1.1.0",
+ "name": "wide-align",
+ "escapedName": "wide-align",
+ "rawSpec": "^1.1.0",
+ "saveSpec": null,
+ "fetchSpec": "^1.1.0"
+ },
+ "_requiredBy": [
+ "/gauge"
+ ],
+ "_resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.3.tgz",
+ "_shasum": "ae074e6bdc0c14a431e804e624549c633b000457",
+ "_spec": "wide-align@^1.1.0",
+ "_where": "/home/pruss/Dev/3-minute-website/node_modules/gauge",
+ "author": {
+ "name": "Rebecca Turner",
+ "email": "me@re-becca.org",
+ "url": "http://re-becca.org/"
+ },
+ "bugs": {
+ "url": "https://github.com/iarna/wide-align/issues"
+ },
+ "bundleDependencies": false,
+ "dependencies": {
+ "string-width": "^1.0.2 || 2"
+ },
+ "deprecated": false,
+ "description": "A wide-character aware text alignment function for use on the console or with fixed width fonts.",
+ "devDependencies": {
+ "tap": "10 || 11 || 12"
+ },
+ "files": [
+ "align.js"
+ ],
+ "homepage": "https://github.com/iarna/wide-align#readme",
+ "keywords": [
+ "wide",
+ "double",
+ "unicode",
+ "cjkv",
+ "pad",
+ "align"
+ ],
+ "license": "ISC",
+ "main": "align.js",
+ "name": "wide-align",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/iarna/wide-align.git"
+ },
+ "scripts": {
+ "test": "tap --coverage test/*.js",
+ "version": "perl -pi -e 's/^( \"version\": $ENV{npm_config_node_version}\").*?\",/$1abc\",/' package-lock.json ; git add package-lock.json"
+ },
+ "version": "1.1.3"
+}