Remove lodash dep

Reviewed By: davidaurelio

Differential Revision: D6736155

fbshipit-source-id: 3a9785ecc887f7b49ab3c2ac36b25ea458b1d783
This commit is contained in:
Peter van der Zee 2018-01-17 04:03:23 -08:00 committed by Facebook Github Bot
parent eaa4331d70
commit 329cfb4ee0
1 changed files with 37 additions and 18 deletions

View File

@ -6,13 +6,14 @@
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
* *
* $FlowFixMe
* Note: This file runs BEFORE transforms so DO NOT ADD ES6 or Flow in code! * Note: This file runs BEFORE transforms so DO NOT ADD ES6 or Flow in code!
* @format * @PrettierFixMe
* Note: Cannot safely use Prettier because of trailing call arg comma rule!
*/ */
'use strict'; 'use strict';
var _ = require('lodash');
var wordwrap = require('wordwrap'); var wordwrap = require('wordwrap');
var HORIZONTAL_LINE = '\u2500'; var HORIZONTAL_LINE = '\u2500';
@ -22,6 +23,10 @@ var TOP_RIGHT = '\u2510';
var BOTTOM_LEFT = '\u2514'; var BOTTOM_LEFT = '\u2514';
var BOTTOM_RIGHT = '\u2518'; var BOTTOM_RIGHT = '\u2518';
function identity(x) {
return x;
}
/** /**
* Prints a banner with a border around it containing the given message. The * Prints a banner with a border around it containing the given message. The
* following options are supported: * following options are supported:
@ -51,16 +56,30 @@ var BOTTOM_RIGHT = '\u2518';
*/ */
function formatBanner(message, options) { function formatBanner(message, options) {
options = options || {}; options = options || {};
_.defaults(options, { if (options.chalkFunction === undefined) {
chalkFunction: _.identity, options.chalkFunction = identity;
width: 80, }
marginLeft: 0, if (options.width === undefined) {
marginRight: 0, options.width = 80;
paddingTop: 0, }
paddingBottom: 0, if (options.marginLeft === undefined) {
paddingLeft: 2, options.marginLeft = 0;
paddingRight: 2, }
}); if (options.marginRight === undefined) {
options.marginRight = 0;
}
if (options.paddingTop === undefined) {
options.paddingTop = 0;
}
if (options.paddingBottom === undefined) {
options.paddingBottom = 0;
}
if (options.paddingLeft === undefined) {
options.paddingLeft = 2;
}
if (options.paddingRight === undefined) {
options.paddingRight = 2;
}
var width = options.width; var width = options.width;
var marginLeft = options.marginLeft; var marginLeft = options.marginLeft;
@ -78,18 +97,18 @@ function formatBanner(message, options) {
var left = spaces(marginLeft) + VERTICAL_LINE + spaces(paddingLeft); var left = spaces(marginLeft) + VERTICAL_LINE + spaces(paddingLeft);
var right = spaces(paddingRight) + VERTICAL_LINE + spaces(marginRight); var right = spaces(paddingRight) + VERTICAL_LINE + spaces(marginRight);
var bodyLines = _.flattenDeep([ var bodyLines = [].concat(
arrayOf('', paddingTop), arrayOf('', paddingTop),
body.split('\n'), body.split('\n'),
arrayOf('', paddingBottom), arrayOf('', paddingBottom)
]).map(function(line) { ).map(function(line) {
var padding = spaces(Math.max(0, maxLineWidth - line.length)); var padding = spaces(Math.max(0, maxLineWidth - line.length));
return left + options.chalkFunction(line) + padding + right; return left + options.chalkFunction(line) + padding + right;
}); });
var horizontalBorderLine = repeatString( var horizontalBorderLine = repeatString(
HORIZONTAL_LINE, HORIZONTAL_LINE,
width - marginLeft - marginRight - 2, width - marginLeft - marginRight - 2
); );
var top = var top =
spaces(marginLeft) + spaces(marginLeft) +
@ -103,7 +122,7 @@ function formatBanner(message, options) {
horizontalBorderLine + horizontalBorderLine +
BOTTOM_RIGHT + BOTTOM_RIGHT +
spaces(marginRight); spaces(marginRight);
return _.flattenDeep([top, bodyLines, bottom]).join('\n'); return [].concat(top, bodyLines, bottom).join('\n');
} }
function spaces(number) { function spaces(number) {
@ -115,7 +134,7 @@ function repeatString(string, number) {
} }
function arrayOf(value, number) { function arrayOf(value, number) {
return _.range(number).map(function() { return Array.apply(null, Array(number)).map(function() {
return value; return value;
}); });
} }