Comparing version 2.5.0 to 2.5.1
@@ -17,7 +17,9 @@ /*************************************************************************************************************************************************************** | ||
var _require = require('./Debugging.js'), | ||
Debugging = _require.Debugging; | ||
const { | ||
Debugging | ||
} = require('./Debugging.js'); | ||
var _require2 = require('./Colorize.js'), | ||
Colorize = _require2.Colorize; | ||
const { | ||
Colorize | ||
} = require('./Colorize.js'); | ||
/** | ||
@@ -37,9 +39,9 @@ * Add a new character to the output array | ||
var AddChar = function AddChar(CHAR, output, fontLines, fontChars, fontColors, colors) { | ||
const AddChar = (CHAR, output, fontLines, fontChars, fontColors, colors) => { | ||
Debugging.report(`Running AddChar with "${CHAR}"`, 1); | ||
var lines = output.length - fontLines; // last line is fontLines tall and is located at the bottom of the output array | ||
let lines = output.length - fontLines; // last line is fontLines tall and is located at the bottom of the output array | ||
for (var i = lines; i < output.length; i++) { | ||
for (let i = lines; i < output.length; i++) { | ||
// iterate over last line | ||
var index = i - lines; | ||
let index = i - lines; | ||
output[i] += Colorize(fontChars[CHAR][index], fontColors, colors); | ||
@@ -46,0 +48,0 @@ } |
@@ -17,7 +17,9 @@ /*************************************************************************************************************************************************************** | ||
var _require = require('./Debugging.js'), | ||
Debugging = _require.Debugging; | ||
const { | ||
Debugging | ||
} = require('./Debugging.js'); | ||
var _require2 = require('./Colorize.js'), | ||
Colorize = _require2.Colorize; | ||
const { | ||
Colorize | ||
} = require('./Colorize.js'); | ||
/** | ||
@@ -37,10 +39,10 @@ * Add letter spacing for the next character | ||
var AddLetterSpacing = function AddLetterSpacing(output, fontLines, fontLetterspace, fontColors, colors, letterSpacing) { | ||
const AddLetterSpacing = (output, fontLines, fontLetterspace, fontColors, colors, letterSpacing) => { | ||
Debugging.report(`Running AddLetterSpacing`, 1); | ||
var lines = output.length - fontLines; // last line is fontLines tall and is located at the bottom of the output array | ||
let lines = output.length - fontLines; // last line is fontLines tall and is located at the bottom of the output array | ||
for (var i = lines; i < output.length; i++) { | ||
for (let i = lines; i < output.length; i++) { | ||
// iterate over last line | ||
var index = i - lines; | ||
var space = Colorize(fontLetterspace[index], fontColors, colors); | ||
let index = i - lines; | ||
let space = Colorize(fontLetterspace[index], fontColors, colors); | ||
@@ -47,0 +49,0 @@ if (space.length === 0 && letterSpacing > 0) { |
@@ -17,4 +17,5 @@ /*************************************************************************************************************************************************************** | ||
var _require = require('./Debugging.js'), | ||
Debugging = _require.Debugging; | ||
const { | ||
Debugging | ||
} = require('./Debugging.js'); | ||
/** | ||
@@ -32,3 +33,3 @@ * Add a new line to the output array | ||
var AddLine = function AddLine(output, fontLines, FontBuffer, lineHeight) { | ||
const AddLine = (output, fontLines, FontBuffer, lineHeight) => { | ||
Debugging.report(`Running AddLine`, 1); | ||
@@ -40,7 +41,7 @@ | ||
var lines = fontLines + output.length + lineHeight; | ||
var length = output.length; | ||
let lines = fontLines + output.length + lineHeight; | ||
let length = output.length; | ||
for (var i = length; i < lines; i++) { | ||
var index = i - length; | ||
for (let i = length; i < lines; i++) { | ||
let index = i - length; | ||
@@ -47,0 +48,0 @@ if (index > lineHeight) { |
@@ -24,5 +24,5 @@ /*************************************************************************************************************************************************************** | ||
var AddShortcuts = function AddShortcuts(options) { | ||
var flatOptions = Object.assign({}, options); | ||
Object.keys(flatOptions).forEach(function (option) { | ||
const AddShortcuts = options => { | ||
const flatOptions = Object.assign({}, options); | ||
Object.keys(flatOptions).forEach(option => { | ||
flatOptions[option]._name = option; | ||
@@ -29,0 +29,0 @@ flatOptions[flatOptions[option].short] = flatOptions[option]; |
@@ -17,7 +17,9 @@ /*************************************************************************************************************************************************************** | ||
var _require = require('./Debugging.js'), | ||
Debugging = _require.Debugging; | ||
const { | ||
Debugging | ||
} = require('./Debugging.js'); | ||
var _require2 = require('./Size.js'), | ||
Size = _require2.Size; | ||
const { | ||
Size | ||
} = require('./Size.js'); | ||
/** | ||
@@ -38,6 +40,5 @@ * Calculate the spaces to be added to the left of each line to align them either center or right | ||
var AlignText = function AlignText(output, lineLength, characterLines, align) { | ||
var size = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : Size; | ||
const AlignText = (output, lineLength, characterLines, align, size = Size) => { | ||
Debugging.report(`Running AlignText`, 1); | ||
var space = 0; | ||
let space = 0; | ||
@@ -58,7 +59,7 @@ if (align === 'center') { | ||
// only add if there is something to add | ||
var lines = output.length - characterLines; // last line is characterLines tall and is located at the bottom of the output array | ||
let lines = output.length - characterLines; // last line is characterLines tall and is located at the bottom of the output array | ||
space = ' '.repeat(space); | ||
for (var i = lines; i < output.length; i++) { | ||
for (let i = lines; i < output.length; i++) { | ||
// iterate over last line (which can be several line breaks long) | ||
@@ -65,0 +66,0 @@ output[i] = space + output[i]; |
@@ -17,16 +17,11 @@ /*************************************************************************************************************************************************************** | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
const chalkOriginal = require(`chalk`); // We pass on the FORCE_COLOR env var to chalk so we can force it in ci | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
var chalkOriginal = require(`chalk`); // We pass on the FORCE_COLOR env var to chalk so we can force it in ci | ||
var Chalk = new chalkOriginal.Instance(_objectSpread({}, process.env.FORCE_COLOR ? { | ||
level: parseInt(process.env.FORCE_COLOR) | ||
} : null)); | ||
const Chalk = new chalkOriginal.Instance({ ...(process.env.FORCE_COLOR ? { | ||
level: parseInt(process.env.FORCE_COLOR) | ||
} : null) | ||
}); | ||
module.exports = exports = { | ||
Chalk | ||
}; |
@@ -17,4 +17,5 @@ /*************************************************************************************************************************************************************** | ||
var _require = require('./Debugging.js'), | ||
Debugging = _require.Debugging; | ||
const { | ||
Debugging | ||
} = require('./Debugging.js'); | ||
/** | ||
@@ -31,8 +32,8 @@ * Return the max width of a character by looking at its longest line | ||
var CharLength = function CharLength(character, fontLines, letterSpacing) { | ||
const CharLength = (character, fontLines, letterSpacing) => { | ||
Debugging.report(`Running CharLength`, 1); | ||
var charWidth = 0; | ||
let charWidth = 0; | ||
for (var i = 0; i < fontLines; i++) { | ||
var char = character[i].replace(/(<([^>]+)>)/ig, ''); // get character and strip color infos | ||
for (let i = 0; i < fontLines; i++) { | ||
let char = character[i].replace(/(<([^>]+)>)/ig, ''); // get character and strip color infos | ||
@@ -39,0 +40,0 @@ if (char.length > charWidth) { |
@@ -17,15 +17,18 @@ /*************************************************************************************************************************************************************** | ||
var _require = require('./Debugging.js'), | ||
Debugging = _require.Debugging; | ||
const { | ||
Debugging | ||
} = require('./Debugging.js'); | ||
var _require2 = require('./Chalk.js'), | ||
Chalk = _require2.Chalk; | ||
const { | ||
Chalk | ||
} = require('./Chalk.js'); | ||
var _require3 = require('./constants.js'), | ||
COLORS = _require3.COLORS, | ||
BGCOLORS = _require3.BGCOLORS, | ||
GRADIENTCOLORS = _require3.GRADIENTCOLORS, | ||
ALIGNMENT = _require3.ALIGNMENT, | ||
FONTFACES = _require3.FONTFACES, | ||
HEXTEST = _require3.HEXTEST; | ||
const { | ||
COLORS, | ||
BGCOLORS, | ||
GRADIENTCOLORS, | ||
ALIGNMENT, | ||
FONTFACES, | ||
HEXTEST | ||
} = require('./constants.js'); | ||
/** | ||
@@ -53,9 +56,4 @@ * Check input for human errors | ||
var CheckInput = function CheckInput(INPUT, userFont, userColors, userBackground, userAlign, userGradient) { | ||
var fontfaces = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : FONTFACES; | ||
var colors = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : COLORS; | ||
var bgcolors = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : BGCOLORS; | ||
var gradientcolors = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : GRADIENTCOLORS; | ||
var alignment = arguments.length > 10 && arguments[10] !== undefined ? arguments[10] : ALIGNMENT; | ||
var result = { | ||
const CheckInput = (INPUT, userFont, userColors, userBackground, userAlign, userGradient, fontfaces = FONTFACES, colors = COLORS, bgcolors = BGCOLORS, gradientcolors = GRADIENTCOLORS, alignment = ALIGNMENT) => { | ||
let result = { | ||
message: '', | ||
@@ -75,5 +73,3 @@ pass: true | ||
return { | ||
message: `"${Chalk.red(userFont)}" is not a valid font option.\n` + `Please use a font from the supported stack:\n${Chalk.green(Object.keys(fontfaces).map(function (font) { | ||
return fontfaces[font]; | ||
}).join(', '))}`, | ||
message: `"${Chalk.red(userFont)}" is not a valid font option.\n` + `Please use a font from the supported stack:\n${Chalk.green(Object.keys(fontfaces).map(font => fontfaces[font]).join(', '))}`, | ||
pass: false | ||
@@ -84,9 +80,7 @@ }; | ||
userColors.forEach(function (color) { | ||
userColors.forEach(color => { | ||
// check color usage | ||
if (Object.keys(colors).indexOf(color.toLowerCase()) === -1 && color !== 'candy' && !HEXTEST.test(color)) { | ||
result = { | ||
message: `"${Chalk.red(color)}" is not a valid font color option.\n` + `Please use a color from the supported stack or any valid hex color:\n${Chalk.green(`${Object.keys(colors).map(function (color) { | ||
return colors[color]; | ||
}).join(', ')}, candy, "#3456ff", "#f80", etc...`)}`, | ||
message: `"${Chalk.red(color)}" is not a valid font color option.\n` + `Please use a color from the supported stack or any valid hex color:\n${Chalk.green(`${Object.keys(colors).map(color => colors[color]).join(', ')}, candy, "#3456ff", "#f80", etc...`)}`, | ||
pass: false | ||
@@ -99,5 +93,3 @@ }; | ||
return { | ||
message: `"${Chalk.red(userBackground)}" is not a valid background option.\n` + `Please use a color from the supported stack:\n${Chalk.green(Object.keys(bgcolors).map(function (bgcolor) { | ||
return bgcolors[bgcolor]; | ||
}).join(', '))}`, | ||
message: `"${Chalk.red(userBackground)}" is not a valid background option.\n` + `Please use a color from the supported stack:\n${Chalk.green(Object.keys(bgcolors).map(bgcolor => bgcolors[bgcolor]).join(', '))}`, | ||
pass: false | ||
@@ -125,8 +117,6 @@ }; | ||
userGradient.forEach(function (color) { | ||
userGradient.forEach(color => { | ||
if (Object.keys(gradientcolors).indexOf(color.toLowerCase()) === -1 && !HEXTEST.test(color)) { | ||
result = { | ||
message: `"${Chalk.red(color)}" is not a valid gradient color option.\n` + `Please use a color from the supported stack or any valid hex color:\n${Chalk.green(`${Object.keys(gradientcolors).map(function (color) { | ||
return colors[color]; | ||
}).join(', ')}, "#3456ff", "#f80", etc...`)}`, | ||
message: `"${Chalk.red(color)}" is not a valid gradient color option.\n` + `Please use a color from the supported stack or any valid hex color:\n${Chalk.green(`${Object.keys(gradientcolors).map(color => colors[color]).join(', ')}, "#3456ff", "#f80", etc...`)}`, | ||
pass: false | ||
@@ -133,0 +123,0 @@ }; |
@@ -17,4 +17,5 @@ /*************************************************************************************************************************************************************** | ||
var _require = require('./constants.js'), | ||
CHARS = _require.CHARS; | ||
const { | ||
CHARS | ||
} = require('./constants.js'); | ||
/** | ||
@@ -30,9 +31,5 @@ * Filter only allowed character | ||
var CleanInput = function CleanInput(INPUT) { | ||
var chars = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : CHARS; | ||
const CleanInput = (INPUT, chars = CHARS) => { | ||
if (typeof INPUT === 'string') { | ||
var clean = INPUT.replace(/(?:\r\n|\r|\n)/g, '|').split('').filter(function (char) { | ||
return chars.includes(char.toUpperCase()); | ||
}).join(''); | ||
const clean = INPUT.replace(/(?:\r\n|\r|\n)/g, '|').split('').filter(char => chars.includes(char.toUpperCase())).join(''); | ||
return clean; | ||
@@ -39,0 +36,0 @@ } else { |
@@ -17,13 +17,17 @@ /*************************************************************************************************************************************************************** | ||
var _require = require('./UpperCaseFirst.js'), | ||
UpperCaseFirst = _require.UpperCaseFirst; | ||
const { | ||
UpperCaseFirst | ||
} = require('./UpperCaseFirst.js'); | ||
var _require2 = require('./Debugging.js'), | ||
Debugging = _require2.Debugging; | ||
const { | ||
Debugging | ||
} = require('./Debugging.js'); | ||
var _require3 = require('./constants.js'), | ||
HEXTEST = _require3.HEXTEST; | ||
const { | ||
HEXTEST | ||
} = require('./constants.js'); | ||
var _require4 = require('./Chalk.js'), | ||
Chalk = _require4.Chalk; | ||
const { | ||
Chalk | ||
} = require('./Chalk.js'); | ||
/** | ||
@@ -43,5 +47,3 @@ * Abstraction for coloring hex-, keyword- and background-colors | ||
var Color = function Color(color) { | ||
var bg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
const Color = (color, bg = false) => { | ||
// bail early if we use system color | ||
@@ -67,4 +69,4 @@ if (color === 'system' || process.env.FORCE_COLOR == 0) { | ||
var kind = HEXTEST.test(color) ? 'hex' : `${bg ? 'bgK' : 'k'}eyword`; | ||
var styles; | ||
const kind = HEXTEST.test(color) ? 'hex' : `${bg ? 'bgK' : 'k'}eyword`; | ||
let styles; | ||
@@ -71,0 +73,0 @@ try { |
@@ -17,7 +17,9 @@ /*************************************************************************************************************************************************************** | ||
var _require = require('./Debugging.js'), | ||
Debugging = _require.Debugging; | ||
const { | ||
Debugging | ||
} = require('./Debugging.js'); | ||
var _require2 = require('./Color.js'), | ||
Color = _require2.Color; | ||
const { | ||
Color | ||
} = require('./Color.js'); | ||
/** | ||
@@ -34,5 +36,5 @@ * Replace placeholders with color information | ||
var Colorize = function Colorize(character, fontColors, optionColors) { | ||
const Colorize = (character, fontColors, optionColors) => { | ||
Debugging.report(`Running Colorize`, 1); | ||
var candyColors = [// allowed candy colors | ||
let candyColors = [// allowed candy colors | ||
'red', 'green', 'yellow', 'magenta', 'cyan', 'redBright', 'greenBright', 'yellowBright', 'blueBright', 'magentaBright', 'cyanBright']; | ||
@@ -43,11 +45,10 @@ | ||
// we have to replace all color placeholder with ansi escape sequences | ||
for (var i = 0; i < fontColors; i++) { | ||
var color = optionColors[i] === 'candy' ? candyColors[Math.floor(Math.random() * candyColors.length)] : optionColors[i] || 'system'; | ||
var _Color = Color(color), | ||
openNew = _Color.open, | ||
closeNew = _Color.close; | ||
var open = new RegExp(`<c${i + 1}>`, 'g'); | ||
var close = new RegExp(`</c${i + 1}>`, 'g'); | ||
for (let i = 0; i < fontColors; i++) { | ||
const color = optionColors[i] === 'candy' ? candyColors[Math.floor(Math.random() * candyColors.length)] : optionColors[i] || 'system'; | ||
const { | ||
open: openNew, | ||
close: closeNew | ||
} = Color(color); | ||
const open = new RegExp(`<c${i + 1}>`, 'g'); | ||
const close = new RegExp(`</c${i + 1}>`, 'g'); | ||
character = character.replace(open, openNew); | ||
@@ -60,9 +61,8 @@ character = character.replace(close, closeNew); | ||
if (fontColors === 1) { | ||
var _color = optionColors[0] === 'candy' ? candyColors[Math.floor(Math.random() * candyColors.length)] : optionColors[0] || 'system'; | ||
var _Color2 = Color(_color), | ||
_openNew = _Color2.open, | ||
_closeNew = _Color2.close; | ||
character = _openNew + character + _closeNew; | ||
const color = optionColors[0] === 'candy' ? candyColors[Math.floor(Math.random() * candyColors.length)] : optionColors[0] || 'system'; | ||
const { | ||
open: openNew, | ||
close: closeNew | ||
} = Color(color); | ||
character = openNew + character + closeNew; | ||
} | ||
@@ -69,0 +69,0 @@ } |
@@ -25,8 +25,9 @@ /*************************************************************************************************************************************************************** | ||
var _require = require('./Chalk.js'), | ||
Chalk = _require.Chalk; // global defaults | ||
const { | ||
Chalk | ||
} = require('./Chalk.js'); // global defaults | ||
var CHARS = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "|", "!", "?", ".", "+", "-", "_", "=", "@", "#", "$", "%", "&", "(", ")", "/", ":", ";", ",", " ", "'"]; | ||
var COLORS = { | ||
const CHARS = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "|", "!", "?", ".", "+", "-", "_", "=", "@", "#", "$", "%", "&", "(", ")", "/", ":", ";", ",", " ", "'"]; | ||
const COLORS = { | ||
system: 'system', | ||
@@ -50,3 +51,3 @@ black: 'black', | ||
}; | ||
var BGCOLORS = { | ||
const BGCOLORS = { | ||
transparent: 'transparent', | ||
@@ -70,3 +71,3 @@ black: 'black', | ||
}; | ||
var GRADIENTCOLORS = { | ||
const GRADIENTCOLORS = { | ||
transparent: 'transparent', | ||
@@ -82,4 +83,4 @@ black: 'black', | ||
}; | ||
var ALIGNMENT = ['left', 'center', 'right']; | ||
var FONTFACES = { | ||
const ALIGNMENT = ['left', 'center', 'right']; | ||
const FONTFACES = { | ||
console: 'console', | ||
@@ -95,3 +96,3 @@ block: 'block', | ||
}; | ||
var CLIOPTIONS = { | ||
const CLIOPTIONS = { | ||
'--version': { | ||
@@ -111,9 +112,5 @@ description: 'Use to display the version of cfonts', | ||
description: 'Use to define the font face', | ||
example: `--font block ${Chalk.green(`( ${Object.keys(FONTFACES).map(function (font) { | ||
return FONTFACES[font]; | ||
}).join(', ')} )`)}`, | ||
example: `--font block ${Chalk.green(`( ${Object.keys(FONTFACES).map(font => FONTFACES[font]).join(', ')} )`)}`, | ||
short: '-f', | ||
options: Object.keys(FONTFACES).map(function (color) { | ||
return FONTFACES[color]; | ||
}), | ||
options: Object.keys(FONTFACES).map(color => FONTFACES[color]), | ||
default: 'block' | ||
@@ -123,5 +120,3 @@ }, | ||
description: 'Use to define the font color', | ||
example: `--colors red ${Chalk.green(`( ${Object.keys(COLORS).map(function (color) { | ||
return COLORS[color]; | ||
}).join(', ')}, #ff8800, hex-colors etc... )`)}`, | ||
example: `--colors red ${Chalk.green(`( ${Object.keys(COLORS).map(color => COLORS[color]).join(', ')}, #ff8800, hex-colors etc... )`)}`, | ||
short: '-c', | ||
@@ -133,9 +128,5 @@ options: true, | ||
description: 'Use to define background color', | ||
example: `--background blue ${Chalk.green(`( ${Object.keys(BGCOLORS).map(function (bgcolor) { | ||
return BGCOLORS[bgcolor]; | ||
}).join(', ')} )`)}`, | ||
example: `--background blue ${Chalk.green(`( ${Object.keys(BGCOLORS).map(bgcolor => BGCOLORS[bgcolor]).join(', ')} )`)}`, | ||
short: '-b', | ||
options: Object.keys(BGCOLORS).map(function (color) { | ||
return BGCOLORS[color]; | ||
}), | ||
options: Object.keys(BGCOLORS).map(color => BGCOLORS[color]), | ||
default: 'transparent' | ||
@@ -205,5 +196,5 @@ }, | ||
var PACKAGE = require('../package.json'); | ||
const PACKAGE = require('../package.json'); | ||
var HEXTEST = RegExp('^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$'); | ||
const HEXTEST = RegExp('^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$'); | ||
module.exports = exports = { | ||
@@ -210,0 +201,0 @@ CHARS, |
@@ -17,4 +17,5 @@ /*************************************************************************************************************************************************************** | ||
var _require = require('./Chalk.js'), | ||
Chalk = _require.Chalk; | ||
const { | ||
Chalk | ||
} = require('./Chalk.js'); | ||
/** | ||
@@ -27,3 +28,3 @@ * DEBUG object for tracking debug mode and level | ||
var DEBUG = { | ||
const DEBUG = { | ||
store: { | ||
@@ -57,3 +58,3 @@ enabled: false, | ||
var Debugging = { | ||
const Debugging = { | ||
/** | ||
@@ -65,7 +66,3 @@ * Return a headline preferably at the beginning of your app | ||
*/ | ||
headline: function headline(text) { | ||
var level = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 99; | ||
var debug = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEBUG.enabled; | ||
var debuglevel = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEBUG.level; | ||
headline: (text, level = 99, debug = DEBUG.enabled, debuglevel = DEBUG.level) => { | ||
if (debug && level >= debuglevel) { | ||
@@ -82,7 +79,3 @@ console.log(Chalk.bgWhite(`\n${Chalk.bold(' \u2611 ')} ${text}`)); | ||
*/ | ||
report: function report(text) { | ||
var level = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 99; | ||
var debug = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEBUG.enabled; | ||
var debuglevel = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEBUG.level; | ||
report: (text, level = 99, debug = DEBUG.enabled, debuglevel = DEBUG.level) => { | ||
if (debug && level >= debuglevel) { | ||
@@ -99,7 +92,3 @@ console.log(Chalk.bgWhite(`\n${Chalk.bold.green(' \u2611 ')} ${Chalk.black(`${text} `)}`)); | ||
*/ | ||
error: function error(text) { | ||
var level = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 99; | ||
var debug = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEBUG.enabled; | ||
var debuglevel = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEBUG.level; | ||
error: (text, level = 99, debug = DEBUG.enabled, debuglevel = DEBUG.level) => { | ||
if (debug && level >= debuglevel) { | ||
@@ -106,0 +95,0 @@ console.error(Chalk.bgWhite(`\n${Chalk.red(' \u2612 ')} ${Chalk.black(`${text} `)}`)); |
@@ -17,10 +17,13 @@ /*************************************************************************************************************************************************************** | ||
var _require = require('./constants.js'), | ||
CLIOPTIONS = _require.CLIOPTIONS; | ||
const { | ||
CLIOPTIONS | ||
} = require('./constants.js'); | ||
var _require2 = require('./Render.js'), | ||
Render = _require2.Render; | ||
const { | ||
Render | ||
} = require('./Render.js'); | ||
var _require3 = require('./Chalk.js'), | ||
Chalk = _require3.Chalk; | ||
const { | ||
Chalk | ||
} = require('./Chalk.js'); | ||
/** | ||
@@ -31,3 +34,3 @@ * Display the help generated from our CLIOPTIONS | ||
var DisplayHelp = function DisplayHelp() { | ||
const DisplayHelp = () => { | ||
console.log(` ${Render('cfonts', { | ||
@@ -37,5 +40,5 @@ align: 'left', | ||
}).string}` + `This is a tool for sexy fonts in the console. Give your cli some love.\n\n` + `Usage: cfonts "<value>" [option1] <input1> [option2] <input1>,<input2> [option3]\n` + `Example: ${Chalk.bold('$ cfonts "sexy font" -f chrome -a center -c red,green,gray')}\n\n` + `Options:\n`); | ||
var command = []; | ||
var largestSize = 0; | ||
Object.keys(CLIOPTIONS).forEach(function (option) { | ||
let command = []; | ||
let largestSize = 0; | ||
Object.keys(CLIOPTIONS).forEach(option => { | ||
console.log(Chalk.bold(`${option}, ${CLIOPTIONS[option].short}`)); | ||
@@ -42,0 +45,0 @@ console.log(CLIOPTIONS[option].description); |
@@ -17,4 +17,5 @@ /*************************************************************************************************************************************************************** | ||
var _require = require('./constants.js'), | ||
PACKAGE = _require.PACKAGE; | ||
const { | ||
PACKAGE | ||
} = require('./constants.js'); | ||
/** | ||
@@ -25,3 +26,3 @@ * Display the version of this package | ||
var DisplayVersion = function DisplayVersion() { | ||
const DisplayVersion = () => { | ||
console.log(PACKAGE.version); | ||
@@ -28,0 +29,0 @@ }; |
@@ -25,5 +25,3 @@ /*************************************************************************************************************************************************************** | ||
function GetFirstCharacterPosition(lines) { | ||
var earliest = lines.reduce(function (prevLine, line) { | ||
return line.length - line.trimStart().length < prevLine.length - prevLine.trimStart().length && line !== '' ? line : prevLine; | ||
}, lines[0]); | ||
const earliest = lines.reduce((prevLine, line) => line.length - line.trimStart().length < prevLine.length - prevLine.trimStart().length && line !== '' ? line : prevLine, lines[0]); | ||
return earliest.length - earliest.trimStart().length; | ||
@@ -30,0 +28,0 @@ } |
@@ -17,4 +17,5 @@ /*************************************************************************************************************************************************************** | ||
var _require = require('./Debugging.js'), | ||
Debugging = _require.Debugging; | ||
const { | ||
Debugging | ||
} = require('./Debugging.js'); | ||
/** | ||
@@ -29,7 +30,7 @@ * Get a selected JSON font-file object | ||
var GetFont = function GetFont(font) { | ||
const GetFont = font => { | ||
Debugging.report(`Running GetFont`, 1); // try loading the font file | ||
try { | ||
var FONTFACE = require(`../fonts/${font}.json`); // read font file | ||
let FONTFACE = require(`../fonts/${font}.json`); // read font file | ||
@@ -36,0 +37,0 @@ |
@@ -24,7 +24,3 @@ /*************************************************************************************************************************************************************** | ||
var GetLongestLine = function GetLongestLine(lines) { | ||
return lines.reduce(function (longestLine, line) { | ||
return line.length > longestLine.length && line.length !== 0 ? line : longestLine; | ||
}, ''); | ||
}; | ||
const GetLongestLine = lines => lines.reduce((longestLine, line) => line.length > longestLine.length && line.length !== 0 ? line : longestLine, ''); | ||
@@ -31,0 +27,0 @@ module.exports = exports = { |
@@ -17,6 +17,7 @@ /*************************************************************************************************************************************************************** | ||
var _require = require('./constants.js'), | ||
COLORS = _require.COLORS, | ||
BGCOLORS = _require.BGCOLORS, | ||
FONTFACES = _require.FONTFACES; | ||
const { | ||
COLORS, | ||
BGCOLORS, | ||
FONTFACES | ||
} = require('./constants.js'); | ||
/** | ||
@@ -45,32 +46,26 @@ * Merge user settings with default options | ||
var GetOptions = function GetOptions(_ref) { | ||
var font = _ref.font, | ||
align = _ref.align, | ||
colors = _ref.colors, | ||
background = _ref.background, | ||
backgroundColor = _ref.backgroundColor, | ||
letterSpacing = _ref.letterSpacing, | ||
lineHeight = _ref.lineHeight, | ||
space = _ref.space, | ||
maxLength = _ref.maxLength, | ||
gradient = _ref.gradient, | ||
independentGradient = _ref.independentGradient; | ||
var allowedColors = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : COLORS; | ||
var allowedBG = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : BGCOLORS; | ||
var allowedFont = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : FONTFACES; | ||
return { | ||
font: font === undefined ? 'block' : allowedFont[font.toLowerCase()] || font, | ||
align: align === undefined ? 'left' : align.toLowerCase(), | ||
colors: Array.isArray(colors) ? colors.map(function (color) { | ||
return allowedColors[color.toLowerCase()] || color; | ||
}) : [], | ||
background: background === undefined && backgroundColor === undefined ? 'transparent' : background === undefined ? allowedBG[backgroundColor.toLowerCase()] || backgroundColor : allowedBG[background.toLowerCase()] || background, | ||
letterSpacing: typeof parseInt(letterSpacing) === 'number' && letterSpacing > 0 ? letterSpacing : 1, | ||
lineHeight: lineHeight === undefined ? 1 : parseInt(lineHeight), | ||
space: typeof space === 'boolean' ? space : true, | ||
maxLength: maxLength || 0, | ||
gradient: gradient ? Array.isArray(gradient) ? gradient : gradient.split(',') : false, | ||
independentGradient: independentGradient || false | ||
}; | ||
}; | ||
const GetOptions = ({ | ||
font, | ||
align, | ||
colors, | ||
background, | ||
backgroundColor, | ||
letterSpacing, | ||
lineHeight, | ||
space, | ||
maxLength, | ||
gradient, | ||
independentGradient | ||
}, allowedColors = COLORS, allowedBG = BGCOLORS, allowedFont = FONTFACES) => ({ | ||
font: font === undefined ? 'block' : allowedFont[font.toLowerCase()] || font, | ||
align: align === undefined ? 'left' : align.toLowerCase(), | ||
colors: Array.isArray(colors) ? colors.map(color => allowedColors[color.toLowerCase()] || color) : [], | ||
background: background === undefined && backgroundColor === undefined ? 'transparent' : background === undefined ? allowedBG[backgroundColor.toLowerCase()] || backgroundColor : allowedBG[background.toLowerCase()] || background, | ||
letterSpacing: typeof parseInt(letterSpacing) === 'number' && letterSpacing > 0 ? letterSpacing : 1, | ||
lineHeight: lineHeight === undefined ? 1 : parseInt(lineHeight), | ||
space: typeof space === 'boolean' ? space : true, | ||
maxLength: maxLength || 0, | ||
gradient: gradient ? Array.isArray(gradient) ? gradient : gradient.split(',') : false, | ||
independentGradient: independentGradient || false | ||
}); | ||
@@ -77,0 +72,0 @@ module.exports = exports = { |
@@ -17,29 +17,17 @@ /*************************************************************************************************************************************************************** | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } | ||
const { | ||
GetFirstCharacterPosition | ||
} = require('./GetFirstCharacterPosition.js'); | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } | ||
const { | ||
GetLongestLine | ||
} = require('./GetLongestLine.js'); | ||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } | ||
const { | ||
Debugging | ||
} = require('./Debugging.js'); | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } | ||
function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
var _require = require('./GetFirstCharacterPosition.js'), | ||
GetFirstCharacterPosition = _require.GetFirstCharacterPosition; | ||
var _require2 = require('./GetLongestLine.js'), | ||
GetLongestLine = _require2.GetLongestLine; | ||
var _require3 = require('./Debugging.js'), | ||
Debugging = _require3.Debugging; | ||
var _require4 = require('./Color.js'), | ||
Color = _require4.Color; | ||
const { | ||
Color | ||
} = require('./Color.js'); | ||
/** | ||
@@ -58,15 +46,16 @@ * Converts an RGB color value to HSV. | ||
function Rgb2hsv(_ref) { | ||
var r = _ref.r, | ||
g = _ref.g, | ||
b = _ref.b; | ||
function Rgb2hsv({ | ||
r, | ||
g, | ||
b | ||
}) { | ||
r /= 255; | ||
g /= 255; | ||
b /= 255; | ||
var max = Math.max(r, g, b); | ||
var min = Math.min(r, g, b); | ||
var diff = max - min; | ||
var h = 0; | ||
var v = max; | ||
var s = max === 0 ? 0 : diff / max; // h | ||
const max = Math.max(r, g, b); | ||
const min = Math.min(r, g, b); | ||
const diff = max - min; | ||
let h = 0; | ||
let v = max; | ||
let s = max === 0 ? 0 : diff / max; // h | ||
@@ -109,7 +98,7 @@ if (max === min) { | ||
v /= 100; | ||
var hi = Math.floor(h) % 6; | ||
var f = h - Math.floor(h); | ||
var p = 255 * v * (1 - s); | ||
var q = 255 * v * (1 - s * f); | ||
var t = 255 * v * (1 - s * (1 - f)); | ||
const hi = Math.floor(h) % 6; | ||
const f = h - Math.floor(h); | ||
const p = 255 * v * (1 - s); | ||
const q = 255 * v * (1 - s * f); | ||
const t = 255 * v * (1 - s * (1 - f)); | ||
v *= 255; | ||
@@ -173,3 +162,3 @@ | ||
function Rgb2hex(r, g, b) { | ||
var val = (b | g << 8 | r << 16 | 1 << 24).toString(16).slice(1); | ||
const val = (b | g << 8 | r << 16 | 1 << 24).toString(16).slice(1); | ||
return '#' + val.toLowerCase(); | ||
@@ -201,7 +190,7 @@ } | ||
var num = parseInt(hex, 16); | ||
var r = num >> 16; | ||
var g = num >> 8 & 255; | ||
var b = num & 255; | ||
var rgb = [r, g, b]; | ||
const num = parseInt(hex, 16); | ||
const r = num >> 16; | ||
const g = num >> 8 & 255; | ||
const b = num & 255; | ||
const rgb = [r, g, b]; | ||
return rgb; | ||
@@ -221,8 +210,3 @@ } | ||
function Hsv2hsvRad(_ref2) { | ||
var _ref3 = _slicedToArray(_ref2, 3), | ||
h = _ref3[0], | ||
s = _ref3[1], | ||
v = _ref3[2]; | ||
function Hsv2hsvRad([h, s, v]) { | ||
return [h * Math.PI / 180, s, v]; | ||
@@ -255,9 +239,4 @@ } | ||
function Hex2hsvRad(hex) { | ||
var _Hex2rgb = Hex2rgb(hex), | ||
_Hex2rgb2 = _slicedToArray(_Hex2rgb, 3), | ||
r = _Hex2rgb2[0], | ||
g = _Hex2rgb2[1], | ||
b = _Hex2rgb2[2]; | ||
var hsv = Rgb2hsv({ | ||
const [r, g, b] = Hex2rgb(hex); | ||
const hsv = Rgb2hsv({ | ||
r, | ||
@@ -267,3 +246,3 @@ g, | ||
}); | ||
var hsvRad = Hsv2hsvRad(hsv); | ||
const hsvRad = Hsv2hsvRad(hsv); | ||
return hsvRad; | ||
@@ -283,12 +262,9 @@ } | ||
function HsvRad2hex(hRad, s, v) { | ||
var _HsvRad2hsv = HsvRad2hsv(hRad, s, v), | ||
_HsvRad2hsv2 = _slicedToArray(_HsvRad2hsv, 1), | ||
h = _HsvRad2hsv2[0]; | ||
var _Hsv2rgb = Hsv2rgb(h, s, v), | ||
r = _Hsv2rgb.r, | ||
g = _Hsv2rgb.g, | ||
b = _Hsv2rgb.b; | ||
var hex = Rgb2hex(r, g, b); | ||
const [h] = HsvRad2hsv(hRad, s, v); | ||
const { | ||
r, | ||
g, | ||
b | ||
} = Hsv2rgb(h, s, v); | ||
const hex = Rgb2hex(r, g, b); | ||
return hex; | ||
@@ -328,4 +304,4 @@ } | ||
function GetTheta(fromTheta, toTheta, n, steps) { | ||
var TAU = 2 * Math.PI; | ||
var longDistance; | ||
const TAU = 2 * Math.PI; | ||
let longDistance; | ||
@@ -350,3 +326,3 @@ if (steps === 0) { | ||
var result = fromTheta + n * (longDistance / steps); | ||
let result = fromTheta + n * (longDistance / steps); | ||
@@ -375,20 +351,10 @@ if (result < 0) { | ||
function GetGradientColors(fromColor, toColor, steps) { | ||
var _Hex2hsvRad = Hex2hsvRad(fromColor), | ||
_Hex2hsvRad2 = _slicedToArray(_Hex2hsvRad, 3), | ||
fromHRad = _Hex2hsvRad2[0], | ||
fromS = _Hex2hsvRad2[1], | ||
fromV = _Hex2hsvRad2[2]; | ||
const [fromHRad, fromS, fromV] = Hex2hsvRad(fromColor); | ||
const [toHRad, toS, toV] = Hex2hsvRad(toColor); | ||
const hexColors = []; | ||
var _Hex2hsvRad3 = Hex2hsvRad(toColor), | ||
_Hex2hsvRad4 = _slicedToArray(_Hex2hsvRad3, 3), | ||
toHRad = _Hex2hsvRad4[0], | ||
toS = _Hex2hsvRad4[1], | ||
toV = _Hex2hsvRad4[2]; | ||
var hexColors = []; | ||
for (var n = 0; n < steps; n++) { | ||
var hRad = GetTheta(fromHRad, toHRad, n, steps - 1); | ||
var s = GetLinear(fromS, toS, n, steps - 1); | ||
var v = GetLinear(fromV, toV, n, steps - 1); | ||
for (let n = 0; n < steps; n++) { | ||
const hRad = GetTheta(fromHRad, toHRad, n, steps - 1); | ||
const s = GetLinear(fromS, toS, n, steps - 1); | ||
const v = GetLinear(fromV, toV, n, steps - 1); | ||
hexColors.push(HsvRad2hex(hRad, s, v)); | ||
@@ -413,10 +379,10 @@ } | ||
Debugging.report(colors, 2); | ||
var output = []; | ||
var space = ' '.repeat(firstCharacterPosition); | ||
return lines.map(function (line) { | ||
var coloredLine = line.slice(firstCharacterPosition).split('').map(function (char, i) { | ||
var _Color = Color(colors[i]), | ||
open = _Color.open, | ||
close = _Color.close; | ||
const output = []; | ||
const space = ' '.repeat(firstCharacterPosition); | ||
return lines.map(line => { | ||
const coloredLine = line.slice(firstCharacterPosition).split('').map((char, i) => { | ||
const { | ||
open, | ||
close | ||
} = Color(colors[i]); | ||
return `${open}${char}${close}`; | ||
@@ -437,3 +403,3 @@ }).join(''); | ||
function Color2hex(color) { | ||
var colorMap = { | ||
const colorMap = { | ||
black: '#000000', | ||
@@ -455,27 +421,28 @@ red: '#ff0000', | ||
* | ||
* @param {array} options.output - The output to be painted | ||
* @param {array} options.gradient - An array of two colors for start and end of gradient | ||
* @param {integer} options.lines - How many lines the output contains | ||
* @param {integer} options.lineHeight - The line height between lines | ||
* @param {integer} options.fontLines - The line height (line breaks) of a single font line | ||
* @param {boolean} options.independentGradient - A switch to calculate gradient per line or not | ||
* @param {array} options.output - The output to be painted | ||
* @param {array} options.gradient - An array of two colors for start and end of gradient | ||
* @param {integer} options.lines - How many lines the output contains | ||
* @param {integer} options.lineHeight - The line height between lines | ||
* @param {integer} options.fontLines - The line height (line breaks) of a single font line | ||
* @param {boolean} options.independentGradient - A switch to calculate gradient per line or not | ||
* | ||
* @return {string} - The output array painted in ANSI colors and joint into a string | ||
* @return {array} - The output array painted in ANSI colors | ||
*/ | ||
function PaintGradient(_ref4) { | ||
var output = _ref4.output, | ||
gradient = _ref4.gradient, | ||
lines = _ref4.lines, | ||
lineHeight = _ref4.lineHeight, | ||
fontLines = _ref4.fontLines, | ||
independentGradient = _ref4.independentGradient; | ||
function PaintGradient({ | ||
output, | ||
gradient, | ||
lines, | ||
lineHeight, | ||
fontLines, | ||
independentGradient | ||
}) { | ||
Debugging.report(`Running PaintGradient`, 1); | ||
var gradientStart = Color2hex(gradient[0]); | ||
var gradientEnd = Color2hex(gradient[1]); | ||
var newOutput = []; | ||
const gradientStart = Color2hex(gradient[0]); | ||
const gradientEnd = Color2hex(gradient[1]); | ||
let newOutput = []; | ||
Debugging.report(`Gradient start: ${gradientStart} | Gradient end: ${gradientEnd}`, 2); | ||
var firstCharacterPosition; | ||
var longestLine; | ||
let firstCharacterPosition; | ||
let longestLine; | ||
@@ -487,6 +454,6 @@ if (!independentGradient) { | ||
for (var i = 0; i < lines; i++) { | ||
var start = i * (fontLines + lineHeight); | ||
var end = fontLines + start; | ||
var thisLine = output.slice(start, end); | ||
for (let i = 0; i < lines; i++) { | ||
const start = i * (fontLines + lineHeight); | ||
const end = fontLines + start; | ||
const thisLine = output.slice(start, end); | ||
@@ -498,10 +465,10 @@ if (independentGradient) { | ||
var colorsNeeded = longestLine - firstCharacterPosition; | ||
var linesInbetween = i === 0 ? [] : Array(lineHeight).fill('\n'); | ||
const colorsNeeded = longestLine - firstCharacterPosition; | ||
const linesInbetween = i === 0 ? [] : Array(lineHeight).fill('\n'); | ||
Debugging.report(`longestLine: ${longestLine} | firstCharacterPosition: ${firstCharacterPosition}`, 2); | ||
var colors = GetGradientColors(gradientStart, gradientEnd, colorsNeeded); | ||
newOutput = [].concat(_toConsumableArray(newOutput), _toConsumableArray(linesInbetween), _toConsumableArray(PaintLines(thisLine, colors, firstCharacterPosition))); | ||
const colors = GetGradientColors(gradientStart, gradientEnd, colorsNeeded); | ||
newOutput = [...newOutput, ...linesInbetween, ...PaintLines(thisLine, colors, firstCharacterPosition)]; | ||
} | ||
return newOutput.join(`\n`); | ||
return newOutput; | ||
} | ||
@@ -508,0 +475,0 @@ |
@@ -17,31 +17,41 @@ /*************************************************************************************************************************************************************** | ||
var _require = require('./AddLetterSpacing.js'), | ||
AddLetterSpacing = _require.AddLetterSpacing; | ||
const { | ||
AddLetterSpacing | ||
} = require('./AddLetterSpacing.js'); | ||
var _require2 = require('./DisplayVersion.js'), | ||
DisplayVersion = _require2.DisplayVersion; | ||
const { | ||
DisplayVersion | ||
} = require('./DisplayVersion.js'); | ||
var _require3 = require('./DisplayHelp.js'), | ||
DisplayHelp = _require3.DisplayHelp; | ||
const { | ||
DisplayHelp | ||
} = require('./DisplayHelp.js'); | ||
var _require4 = require('./constants.js'), | ||
CLIOPTIONS = _require4.CLIOPTIONS; | ||
const { | ||
CLIOPTIONS | ||
} = require('./constants.js'); | ||
var _require5 = require('./Debugging.js'), | ||
Debugging = _require5.Debugging; | ||
const { | ||
Debugging | ||
} = require('./Debugging.js'); | ||
var _require6 = require('./ParseArgs.js'), | ||
ParseArgs = _require6.ParseArgs; | ||
const { | ||
ParseArgs | ||
} = require('./ParseArgs.js'); | ||
var _require7 = require('./Render.js'), | ||
Render = _require7.Render; | ||
const { | ||
Render | ||
} = require('./Render.js'); | ||
var _require8 = require('./Chalk.js'), | ||
Chalk = _require8.Chalk; | ||
const { | ||
Chalk | ||
} = require('./Chalk.js'); | ||
var _require9 = require('./Log.js'), | ||
Log = _require9.Log; | ||
const { | ||
Log | ||
} = require('./Log.js'); | ||
var _require10 = require('./Say.js'), | ||
Say = _require10.Say; | ||
const { | ||
Say | ||
} = require('./Say.js'); | ||
/** | ||
@@ -55,6 +65,4 @@ * Run cli commands | ||
var Cli = function Cli() { | ||
var inputOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : CLIOPTIONS; | ||
var inputArgs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : process.argv; | ||
var args = ParseArgs(inputOptions, inputArgs); | ||
const Cli = (inputOptions = CLIOPTIONS, inputArgs = process.argv) => { | ||
const args = ParseArgs(inputOptions, inputArgs); | ||
Debugging.report(`OPTIONS:\n` + ` CFonts.say("${args.text}", {\n` + ` font: "${args.font}",\n` + ` align: "${args.align}",\n` + ` colors: ${args.colors ? JSON.stringify(args.colors.split(',')) : []},\n` + ` background: "${args.background}",\n` + ` letterSpacing: ${args['letter-spacing']},\n` + ` lineHeight: ${args['line-height']},\n` + ` space: ${!args.spaceless},\n` + ` maxLength: ${args['max-length']}\n` + ` }, ${args.debug}, ${args.debugLevel} );`, 3, args.debug, args.debugLevel); | ||
@@ -61,0 +69,0 @@ |
@@ -17,4 +17,5 @@ /*************************************************************************************************************************************************************** | ||
var _require = require('./Chalk.js'), | ||
Chalk = _require.Chalk; | ||
const { | ||
Chalk | ||
} = require('./Chalk.js'); | ||
/** | ||
@@ -27,3 +28,3 @@ * Logging prettiness | ||
var Log = { | ||
const Log = { | ||
/** | ||
@@ -34,3 +35,3 @@ * Print error message to console. | ||
*/ | ||
error: function error(text) { | ||
error: text => { | ||
text = text.replace(/(?:\r\n|\r|\n)/g, '\n '); // indent each line | ||
@@ -37,0 +38,0 @@ |
@@ -17,10 +17,13 @@ /*************************************************************************************************************************************************************** | ||
var _require = require('./AddShortcuts.js'), | ||
AddShortcuts = _require.AddShortcuts; | ||
const { | ||
AddShortcuts | ||
} = require('./AddShortcuts.js'); | ||
var _require2 = require('./constants.js'), | ||
CLIOPTIONS = _require2.CLIOPTIONS; | ||
const { | ||
CLIOPTIONS | ||
} = require('./constants.js'); | ||
var _require3 = require('./Debugging.js'), | ||
Debugging = _require3.Debugging; | ||
const { | ||
Debugging | ||
} = require('./Debugging.js'); | ||
/** | ||
@@ -36,11 +39,9 @@ * Parse cli arguments into a nice object | ||
var ParseArgs = function ParseArgs() { | ||
var inputOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : CLIOPTIONS; | ||
var inputArgs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : process.argv; | ||
var parsedArgs = { | ||
const ParseArgs = (inputOptions = CLIOPTIONS, inputArgs = process.argv) => { | ||
const parsedArgs = { | ||
text: inputArgs[2] | ||
}; // create defaults | ||
Object.keys(inputOptions).forEach(function (option) { | ||
var name = option.replace('--', ''); | ||
Object.keys(inputOptions).forEach(option => { | ||
const name = option.replace('--', ''); | ||
parsedArgs[name] = inputOptions[option].default; | ||
@@ -57,15 +58,15 @@ }); | ||
var args = inputArgs.splice(3); // the first two are node specific, the third is our text | ||
const args = inputArgs.splice(3); // the first two are node specific, the third is our text | ||
var options = AddShortcuts(inputOptions); | ||
const options = AddShortcuts(inputOptions); | ||
for (var index = 0; args.length > index; index++) { | ||
var option = options[args[index]]; | ||
for (let index = 0; args.length > index; index++) { | ||
const option = options[args[index]]; | ||
if (option) { | ||
var name = option._name.replace('--', ''); | ||
const name = option._name.replace('--', ''); | ||
if (option.options !== undefined) { | ||
index++; | ||
var value = args[index]; | ||
const value = args[index]; | ||
parsedArgs[name] = value; | ||
@@ -72,0 +73,0 @@ } else { |
@@ -17,53 +17,70 @@ /*************************************************************************************************************************************************************** | ||
var _require = require('./AddLetterSpacing.js'), | ||
AddLetterSpacing = _require.AddLetterSpacing; | ||
const { | ||
AddLetterSpacing | ||
} = require('./AddLetterSpacing.js'); | ||
var _require2 = require('./RenderConsole.js'), | ||
RenderConsole = _require2.RenderConsole; | ||
const { | ||
RenderConsole | ||
} = require('./RenderConsole.js'); | ||
var _require3 = require('./Debugging.js'), | ||
Debugging = _require3.Debugging, | ||
DEBUG = _require3.DEBUG; | ||
const { | ||
Debugging, | ||
DEBUG | ||
} = require('./Debugging.js'); | ||
var _require4 = require('./Gradient.js'), | ||
PaintGradient = _require4.PaintGradient; | ||
const { | ||
PaintGradient | ||
} = require('./Gradient.js'); | ||
var _require5 = require('./CharLength.js'), | ||
CharLength = _require5.CharLength; | ||
const { | ||
CharLength | ||
} = require('./CharLength.js'); | ||
var _require6 = require('./CheckInput.js'), | ||
CheckInput = _require6.CheckInput; | ||
const { | ||
CheckInput | ||
} = require('./CheckInput.js'); | ||
var _require7 = require('./CleanInput.js'), | ||
CleanInput = _require7.CleanInput; | ||
const { | ||
CleanInput | ||
} = require('./CleanInput.js'); | ||
var _require8 = require('./GetOptions.js'), | ||
GetOptions = _require8.GetOptions; | ||
const { | ||
GetOptions | ||
} = require('./GetOptions.js'); | ||
var _require9 = require('./AlignText.js'), | ||
AlignText = _require9.AlignText; | ||
const { | ||
AlignText | ||
} = require('./AlignText.js'); | ||
var _require10 = require('./Colorize.js'), | ||
Colorize = _require10.Colorize; | ||
const { | ||
Colorize | ||
} = require('./Colorize.js'); | ||
var _require11 = require('./AddLine.js'), | ||
AddLine = _require11.AddLine; | ||
const { | ||
AddLine | ||
} = require('./AddLine.js'); | ||
var _require12 = require('./AddChar.js'), | ||
AddChar = _require12.AddChar; | ||
const { | ||
AddChar | ||
} = require('./AddChar.js'); | ||
var _require13 = require('./GetFont.js'), | ||
GetFont = _require13.GetFont; | ||
const { | ||
GetFont | ||
} = require('./GetFont.js'); | ||
var _require14 = require('./constants.js'), | ||
CHARS = _require14.CHARS; | ||
const { | ||
CHARS | ||
} = require('./constants.js'); | ||
var _require15 = require('./Color.js'), | ||
Color = _require15.Color; | ||
const { | ||
Color | ||
} = require('./Color.js'); | ||
var _require16 = require('./Size.js'), | ||
Size = _require16.Size; | ||
const { | ||
Size | ||
} = require('./Size.js'); | ||
var _require17 = require('./Log.js'), | ||
Log = _require17.Log; | ||
const { | ||
Log | ||
} = require('./Log.js'); | ||
/** | ||
@@ -90,19 +107,15 @@ * Main method to get the ANSI output for a string | ||
var Render = function Render(input) { | ||
var SETTINGS = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var debug = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEBUG.enabled; | ||
var debuglevel = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEBUG.level; | ||
var size = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : Size; | ||
const Render = (input, SETTINGS = {}, debug = DEBUG.enabled, debuglevel = DEBUG.level, size = Size) => { | ||
Debugging.report(`Running render`, 1); | ||
DEBUG.enabled = debug; | ||
DEBUG.level = debuglevel; | ||
var INPUT = CleanInput(input, CHARS); | ||
var OPTIONS = GetOptions(SETTINGS); | ||
var output = []; // for output where each line is an output line | ||
const INPUT = CleanInput(input, CHARS); | ||
const OPTIONS = GetOptions(SETTINGS); | ||
let output = []; // for output where each line is an output line | ||
var lines = 0; // for counting each line | ||
let lines = 0; // for counting each line | ||
var FONTFACE = {}; // scoping the fontface object higher for fonts with just one color | ||
let FONTFACE = {}; // scoping the fontface object higher for fonts with just one color | ||
var _isGoodHuman = CheckInput(INPUT, OPTIONS.font, OPTIONS.colors, OPTIONS.background, OPTIONS.align, OPTIONS.gradient); | ||
const _isGoodHuman = CheckInput(INPUT, OPTIONS.font, OPTIONS.colors, OPTIONS.background, OPTIONS.align, OPTIONS.gradient); | ||
@@ -121,5 +134,5 @@ if (!_isGoodHuman.pass) { | ||
if (DEBUG.enabled) { | ||
var outOption = `OPTIONS:\n Text: ${INPUT}`; | ||
let outOption = `OPTIONS:\n Text: ${INPUT}`; | ||
for (var key in OPTIONS) { | ||
for (let key in OPTIONS) { | ||
outOption += `\n Options.${key}: ${OPTIONS[key]}`; | ||
@@ -137,3 +150,3 @@ } | ||
}; | ||
var consoleOutput = RenderConsole(INPUT, OPTIONS, size); | ||
const consoleOutput = RenderConsole(INPUT, OPTIONS, size); | ||
output = consoleOutput.output; | ||
@@ -153,5 +166,5 @@ lines = consoleOutput.lines; | ||
Debugging.report(`Looking up letter spacing from font face`, 1); | ||
var width = 0; | ||
FONTFACE.letterspace.forEach(function (item) { | ||
var char = item.replace(/(<([^>]+)>)/ig, ''); // get character and strip color infos | ||
let width = 0; | ||
FONTFACE.letterspace.forEach(item => { | ||
let char = item.replace(/(<([^>]+)>)/ig, ''); // get character and strip color infos | ||
@@ -166,5 +179,5 @@ if (width < char.length) { | ||
var lineLength = CharLength(FONTFACE.buffer, FONTFACE.lines, OPTIONS); // count each output character per line and start with the buffer | ||
let lineLength = CharLength(FONTFACE.buffer, FONTFACE.lines, OPTIONS); // count each output character per line and start with the buffer | ||
var maxChars = 0; // count each character we print for maxLength option | ||
let maxChars = 0; // count each character we print for maxLength option | ||
@@ -178,7 +191,7 @@ output = AddLine([], FONTFACE.lines, FONTFACE.buffer, OPTIONS.lineHeight); // create first lines with buffer | ||
for (var i = 0; i < INPUT.length; i++) { | ||
for (let i = 0; i < INPUT.length; i++) { | ||
// iterate through the message | ||
var CHAR = INPUT.charAt(i).toUpperCase(); // the current character we convert, only upper case is supported at this time | ||
let CHAR = INPUT.charAt(i).toUpperCase(); // the current character we convert, only upper case is supported at this time | ||
var lastLineLength = lineLength; // we need the lineLength for alignment before we look up if the next char fits | ||
let lastLineLength = lineLength; // we need the lineLength for alignment before we look up if the next char fits | ||
@@ -233,10 +246,4 @@ Debugging.report(`Character found in font: "${CHAR}"`, 2); | ||
var write = output.join(`\n`); | ||
if (FONTFACE.colors <= 1) { | ||
write = Colorize(write, FONTFACE.colors, OPTIONS.colors); | ||
} | ||
if (OPTIONS.gradient) { | ||
write = PaintGradient({ | ||
output = PaintGradient({ | ||
output, | ||
@@ -253,13 +260,16 @@ gradient: OPTIONS.gradient, | ||
// add space | ||
write = `\n\n${write}\n\n`; | ||
output[0] = `\n\n${output[0]}`; | ||
output[output.length - 1] = `${output[output.length - 1]}\n\n`; | ||
} | ||
if (OPTIONS.background !== 'transparent') { | ||
var _Color = Color(OPTIONS.background, true), | ||
openNew = _Color.open, | ||
closeNew = _Color.close; | ||
write = openNew + '\n' + write + closeNew; // result in one string with background | ||
const { | ||
open: openNew, | ||
close: closeNew | ||
} = Color(OPTIONS.background, true); | ||
output[0] = `${openNew}\n${output[0]}`; | ||
output[output.length - 1] = `${output[output.length - 1]}${closeNew}`; | ||
} | ||
let write = output.join(`\n`); | ||
return { | ||
@@ -266,0 +276,0 @@ string: write, |
@@ -17,16 +17,21 @@ /*************************************************************************************************************************************************************** | ||
var _require = require('./AlignText.js'), | ||
AlignText = _require.AlignText; | ||
const { | ||
AlignText | ||
} = require('./AlignText.js'); | ||
var _require2 = require('./Debugging.js'), | ||
Debugging = _require2.Debugging; | ||
const { | ||
Debugging | ||
} = require('./Debugging.js'); | ||
var _require3 = require('./Colorize.js'), | ||
Colorize = _require3.Colorize; | ||
const { | ||
Colorize | ||
} = require('./Colorize.js'); | ||
var _require4 = require('./AddLine.js'), | ||
AddLine = _require4.AddLine; | ||
const { | ||
AddLine | ||
} = require('./AddLine.js'); | ||
var _require5 = require('./Size.js'), | ||
Size = _require5.Size; | ||
const { | ||
Size | ||
} = require('./Size.js'); | ||
/** | ||
@@ -49,10 +54,9 @@ * Render our input with the console font | ||
var RenderConsole = function RenderConsole(INPUT, OPTIONS) { | ||
var size = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Size; | ||
var output = []; | ||
var i = 0; // the defaults need to cramp a little so console doesn't look silly | ||
const RenderConsole = (INPUT, OPTIONS, size = Size) => { | ||
let output = []; | ||
let i = 0; // the defaults need to cramp a little so console doesn't look silly | ||
OPTIONS.letterSpacing = OPTIONS.letterSpacing <= 1 ? 0 : OPTIONS.letterSpacing - 1; | ||
OPTIONS.lineHeight = OPTIONS.lineHeight <= 1 ? 0 : OPTIONS.lineHeight - 1; | ||
var space = ''; | ||
let space = ''; | ||
@@ -64,8 +68,6 @@ if (OPTIONS.letterSpacing > 0) { | ||
var outputLines = INPUT.replace(/(?:\r\n|\r|\n)/g, '|').split('|').map(function (line) { | ||
return line.trim().split('').join(space); | ||
}); // now we check each line for it's length and split them if too long | ||
let outputLines = INPUT.replace(/(?:\r\n|\r|\n)/g, '|').split('|').map(line => line.trim().split('').join(space)); // now we check each line for it's length and split them if too long | ||
while (i < outputLines.length) { | ||
var line = outputLines[i]; | ||
let line = outputLines[i]; | ||
@@ -79,7 +81,5 @@ if (line.length > size.width) { | ||
if (OPTIONS.colors[0] === 'candy') { | ||
output.push(line.split('').map(function (character) { | ||
return Colorize(character, 1, OPTIONS.colors); | ||
}).join('')); | ||
output.push(line.split('').map(character => Colorize(character, 1, OPTIONS.colors)).join('')); | ||
} else { | ||
output.push(line); | ||
output.push(Colorize(line, 1, OPTIONS.colors)); | ||
} | ||
@@ -86,0 +86,0 @@ |
@@ -17,14 +17,18 @@ /*************************************************************************************************************************************************************** | ||
var _require = require('./Debugging.js'), | ||
Debugging = _require.Debugging, | ||
DEBUG = _require.DEBUG; | ||
const { | ||
Debugging, | ||
DEBUG | ||
} = require('./Debugging.js'); | ||
var _require2 = require('./Render.js'), | ||
Render = _require2.Render; | ||
const { | ||
Render | ||
} = require('./Render.js'); | ||
var _require3 = require('./Chalk.js'), | ||
Chalk = _require3.Chalk; | ||
const { | ||
Chalk | ||
} = require('./Chalk.js'); | ||
var _require4 = require('./Size.js'), | ||
Size = _require4.Size; | ||
const { | ||
Size | ||
} = require('./Size.js'); | ||
/** | ||
@@ -37,11 +41,7 @@ * Print to console | ||
var Say = function Say(INPUT) { | ||
var SETTINGS = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var debug = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEBUG.enabled; | ||
var debuglevel = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEBUG.level; | ||
var size = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : Size; | ||
const Say = (INPUT, SETTINGS = {}, debug = DEBUG.enabled, debuglevel = DEBUG.level, size = Size) => { | ||
Debugging.report(`Running say`, 1); | ||
DEBUG.enabled = debug; | ||
DEBUG.level = debuglevel; | ||
var write = Render(INPUT, SETTINGS, debug, debuglevel, size); | ||
const write = Render(INPUT, SETTINGS, debug, debuglevel, size); | ||
@@ -48,0 +48,0 @@ if (write) { |
@@ -17,3 +17,3 @@ /*************************************************************************************************************************************************************** | ||
var WinSize = require('window-size'); | ||
const WinSize = require('window-size'); | ||
/** | ||
@@ -26,3 +26,3 @@ * Abstraction for windows size | ||
var Size = { | ||
const Size = { | ||
width: WinSize ? WinSize.width > 0 ? WinSize.width : 80 : 80, | ||
@@ -29,0 +29,0 @@ height: WinSize ? WinSize.height > 0 ? WinSize.height : 24 : 24 |
@@ -26,5 +26,3 @@ /*************************************************************************************************************************************************************** | ||
var UpperCaseFirst = function UpperCaseFirst(input) { | ||
return typeof input === 'string' ? input.charAt(0).toUpperCase() + input.substr(1) : input; | ||
}; | ||
const UpperCaseFirst = input => typeof input === 'string' ? input.charAt(0).toUpperCase() + input.substr(1) : input; | ||
@@ -31,0 +29,0 @@ module.exports = exports = { |
{ | ||
"name": "cfonts", | ||
"description": "Sexy fonts for the console", | ||
"version": "2.5.0", | ||
"version": "2.5.1", | ||
"homepage": "https://github.com/dominikwilkowski/cfonts", | ||
@@ -30,3 +30,3 @@ "author": { | ||
"engines": { | ||
"node": ">=0.12.15" | ||
"node": ">=10" | ||
}, | ||
@@ -79,3 +79,3 @@ "scripts": { | ||
"browserslist": [ | ||
"node >= 0.12.15" | ||
"node >= 10" | ||
], | ||
@@ -82,0 +82,0 @@ "keywords": [ |
@@ -49,2 +49,4 @@ ```shell | ||
maxLength: '0', // define how many character can be on one line | ||
gradient: false, // define your two gradient colors | ||
independentGradient: false, // define if you want to recalculate the gradient for each new line | ||
}); | ||
@@ -423,2 +425,3 @@ ``` | ||
## Release History | ||
* 2.5.1 - fixed array output to include everything including colors | ||
* 2.5.0 - added gradient option, separated code into files, added 100% unit testing coverage | ||
@@ -425,0 +428,0 @@ * 2.4.8 - removed `ansi-styles` from direct dependencies |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
472
229060
6279