diff options
author | Rebecca Turner <me@re-becca.org> | 2017-04-12 21:47:49 -0700 |
---|---|---|
committer | Jeremiah Senkpiel <fishrock123@rocketmail.com> | 2017-04-25 10:52:01 -0400 |
commit | 00842604483e4c2e622dfdb3a97440e07646158f (patch) | |
tree | f3346902636a44b6037652523767636bf7e4f2c9 /deps/npm/node_modules/update-notifier/node_modules/boxen/node_modules/ansi-align/index.js | |
parent | 061c5da010e0d249379618382a499840d38247b8 (diff) | |
download | android-node-v8-00842604483e4c2e622dfdb3a97440e07646158f.tar.gz android-node-v8-00842604483e4c2e622dfdb3a97440e07646158f.tar.bz2 android-node-v8-00842604483e4c2e622dfdb3a97440e07646158f.zip |
deps: upgrade npm to 4.5.0
PR-URL: https://github.com/nodejs/node/pull/12480
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'deps/npm/node_modules/update-notifier/node_modules/boxen/node_modules/ansi-align/index.js')
-rw-r--r-- | deps/npm/node_modules/update-notifier/node_modules/boxen/node_modules/ansi-align/index.js | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/deps/npm/node_modules/update-notifier/node_modules/boxen/node_modules/ansi-align/index.js b/deps/npm/node_modules/update-notifier/node_modules/boxen/node_modules/ansi-align/index.js new file mode 100644 index 0000000000..16a98fc38f --- /dev/null +++ b/deps/npm/node_modules/update-notifier/node_modules/boxen/node_modules/ansi-align/index.js @@ -0,0 +1,61 @@ +'use strict' + +var stringWidth = require('string-width') + +function ansiAlign (text, opts) { + if (!text) return text + + opts = opts || {} + var align = opts.align || 'center' + + // short-circuit `align: 'left'` as no-op + if (align === 'left') return text + + var split = opts.split || '\n' + var pad = opts.pad || ' ' + var widthDiffFn = align !== 'right' ? halfDiff : fullDiff + + var returnString = false + if (!Array.isArray(text)) { + returnString = true + text = String(text).split(split) + } + + var width + var maxWidth = 0 + text = text.map(function (str) { + str = String(str) + width = stringWidth(str) + maxWidth = Math.max(width, maxWidth) + return { + str: str, + width: width + } + }).map(function (obj) { + return new Array(widthDiffFn(maxWidth, obj.width) + 1).join(pad) + obj.str + }) + + return returnString ? text.join(split) : text +} + +ansiAlign.left = function left (text) { + return ansiAlign(text, { align: 'left' }) +} + +ansiAlign.center = function center (text) { + return ansiAlign(text, { align: 'center' }) +} + +ansiAlign.right = function right (text) { + return ansiAlign(text, { align: 'right' }) +} + +module.exports = ansiAlign + +function halfDiff (maxWidth, curWidth) { + return Math.floor((maxWidth - curWidth) / 2) +} + +function fullDiff (maxWidth, curWidth) { + return maxWidth - curWidth +} |