diff --git a/.travis.yml b/.travis.yml index 7d69d74..f98fed0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: node_js node_js: + - '12' + - '10' - '8' - - '6' - - '4' diff --git a/index.js b/index.js index e5c6944..714e89b 100644 --- a/index.js +++ b/index.js @@ -41,10 +41,10 @@ module.exports = (message, options) => { * Better implementations welcome :) */ - let maxLength = 24; const styledIndexes = {}; - let completedString = ''; + let maxLength = 24; let topOffset = 4; + let completedString = ''; // Amount of characters of the yeoman character »column« → ` /___A___\ /` const YEOMAN_CHARACTER_WIDTH = 17; @@ -52,12 +52,12 @@ module.exports = (message, options) => { // Amount of characters of the default top frame of the speech bubble → `╭──────────────────────────╮` const DEFAULT_TOP_FRAME_WIDTH = 28; - // Amount of characters of a total line - let TOTAL_CHARACTERS_PER_LINE = YEOMAN_CHARACTER_WIDTH + DEFAULT_TOP_FRAME_WIDTH; - // The speech bubble will overflow the Yeoman character if the message is too long. const MAX_MESSAGE_LINES_BEFORE_OVERFLOW = 7; + // Amount of characters of a total line + let TOTAL_CHARACTERS_PER_LINE = YEOMAN_CHARACTER_WIDTH + DEFAULT_TOP_FRAME_WIDTH; + if (options.maxLength) { maxLength = stripAnsi(message).toLowerCase().split(' ').sort()[0].length; @@ -104,7 +104,7 @@ module.exports = (message, options) => { let offset = 0; for (let i = 0; i < spacesIndex.length; i++) { - let char = completedString[spacesIndex[i] - offset]; + const char = completedString[spacesIndex[i] - offset]; if (char) { if (char !== ' ') { offset += 1; @@ -135,7 +135,9 @@ module.exports = (message, options) => { if (styledIndexes[charIndex]) { return styledIndexes[charIndex] + char; - } else if (hasContinuedStyle >= 2) { + } + + if (hasContinuedStyle >= 2) { return continuedStyle + char; } diff --git a/package.json b/package.json index d835713..128739a 100644 --- a/package.json +++ b/package.json @@ -29,19 +29,19 @@ "ansi" ], "dependencies": { - "ansi-regex": "^2.0.0", - "ansi-styles": "^3.0.0", - "chalk": "^1.0.0", - "cli-boxes": "^1.0.0", + "ansi-regex": "^4.1.0", + "ansi-styles": "^4.0.0", + "chalk": "^2.4.2", + "cli-boxes": "^2.2.0", "pad-component": "0.0.1", - "string-width": "^2.0.0", - "strip-ansi": "^3.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^5.2.0", "taketalk": "^1.0.0", - "wrap-ansi": "^2.0.0" + "wrap-ansi": "^6.0.0" }, "devDependencies": { - "mocha": "^3.2.0", - "xo": "^0.17.0" + "mocha": "^6.2.0", + "xo": "^0.24.0" }, "xo": { "space": true diff --git a/test/manual-test.js b/test/manual-test.js index 1e6939b..f96cdf6 100644 --- a/test/manual-test.js +++ b/test/manual-test.js @@ -1,6 +1,6 @@ 'use strict'; const chalk = require('chalk'); -const yosay = require('../'); +const yosay = require('..'); /* * Yo. Fire this file locally with `node test/manual-test.js` at least after you diff --git a/test/test.js b/test/test.js index c2ed86f..b8d970e 100644 --- a/test/test.js +++ b/test/test.js @@ -4,13 +4,13 @@ const assert = require('assert'); const fs = require('fs'); const path = require('path'); const chalk = require('chalk'); -const yosay = require('../'); +const yosay = require('..'); const getFixturePath = testName => path.join(__dirname, 'fixture', `${testName}.json`); const getAssertResult = (testName, expected, done) => fs.readFile(getFixturePath(testName), (err, data) => { assert.ifError(err); - assert.equal(JSON.parse(data), expected); + assert.strict.equal(JSON.parse(data), expected); done(); });