Comparing version 1.2.1 to 2.0.0
32
cli.js
#!/usr/bin/env node | ||
'use strict'; | ||
var pkg = require('./package.json'); | ||
var yosay = require('./'); | ||
const pkg = require('./package.json'); | ||
const yosay = require('.'); | ||
require('taketalk')({ | ||
init: function (input, options) { | ||
init(input, options) { | ||
console.log(yosay(input, options)); | ||
}, | ||
help: function () { | ||
console.log([ | ||
'', | ||
' ' + pkg.description, | ||
'', | ||
' Usage', | ||
' yosay <string>', | ||
' yosay <string> --maxLength 8', | ||
' echo <string> | yosay', | ||
'', | ||
' Example', | ||
' yosay "Sindre is a horse"', | ||
yosay('Sindre is a horse') | ||
].join('\n')); | ||
help() { | ||
console.log(` | ||
${pkg.description} | ||
Usage | ||
$ yosay <string> | ||
$ yosay <string> --maxLength 8 | ||
$ echo <string> | yosay | ||
Example | ||
$ yosay 'Sindre is a horse' | ||
${yosay('Sindre is a horse')}`); | ||
}, | ||
version: pkg.version | ||
}); |
74
index.js
'use strict'; | ||
var chalk = require('chalk'); | ||
var pad = require('pad-component'); | ||
var wrap = require('wrap-ansi'); | ||
var stringWidth = require('string-width'); | ||
var stripAnsi = require('strip-ansi'); | ||
var ansiStyles = require('ansi-styles'); | ||
var ansiRegex = require('ansi-regex')(); | ||
var repeating = require('repeating'); | ||
var cliBoxes = require('cli-boxes'); | ||
const chalk = require('chalk'); | ||
const pad = require('pad-component'); | ||
const wrap = require('wrap-ansi'); | ||
const stringWidth = require('string-width'); | ||
const stripAnsi = require('strip-ansi'); | ||
const ansiStyles = require('ansi-styles'); | ||
const ansiRegex = require('ansi-regex')(); | ||
const cliBoxes = require('cli-boxes'); | ||
var border = cliBoxes.round; | ||
var leftOffset = 17; | ||
var defaultGreeting = | ||
const border = cliBoxes.round; | ||
const leftOffset = 17; | ||
const defaultGreeting = | ||
'\n _-----_ ' + | ||
@@ -25,3 +24,3 @@ '\n | | ' + | ||
module.exports = function (message, options) { | ||
module.exports = (message, options) => { | ||
message = (message || 'Welcome to Yeoman, ladies and gentlemen!').trim(); | ||
@@ -46,20 +45,18 @@ options = options || {}; | ||
var maxLength = 24; | ||
var frame; | ||
var styledIndexes = {}; | ||
var completedString = ''; | ||
var regExNewLine; | ||
var topOffset = 4; | ||
let maxLength = 24; | ||
const styledIndexes = {}; | ||
let completedString = ''; | ||
let topOffset = 4; | ||
// Amount of characters of the yeoman character »column« → ` /___A___\ /` | ||
var YEOMAN_CHARACTER_WIDTH = 17; | ||
const YEOMAN_CHARACTER_WIDTH = 17; | ||
// Amount of characters of the default top frame of the speech bubble → `╭──────────────────────────╮` | ||
var DEFAULT_TOP_FRAME_WIDTH = 28; | ||
const DEFAULT_TOP_FRAME_WIDTH = 28; | ||
// Amount of characters of a total line | ||
var TOTAL_CHARACTERS_PER_LINE = YEOMAN_CHARACTER_WIDTH + DEFAULT_TOP_FRAME_WIDTH; | ||
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. | ||
var MAX_MESSAGE_LINES_BEFORE_OVERFLOW = 7; | ||
const MAX_MESSAGE_LINES_BEFORE_OVERFLOW = 7; | ||
@@ -75,7 +72,6 @@ if (options.maxLength) { | ||
regExNewLine = new RegExp('\\s{' + maxLength + '}'); | ||
const regExNewLine = new RegExp(`\\s{${maxLength}}`); | ||
const borderHorizontal = border.horizontal.repeat(maxLength + 2); | ||
var borderHorizontal = repeating(border.horizontal, maxLength + 2); | ||
frame = { | ||
const frame = { | ||
top: border.topLeft + borderHorizontal + border.topRight, | ||
@@ -86,4 +82,4 @@ side: ansiStyles.reset.open + border.vertical + ansiStyles.reset.open, | ||
message.replace(ansiRegex, function (match, offset) { | ||
Object.keys(styledIndexes).forEach(function (key) { | ||
message.replace(ansiRegex, (match, offset) => { | ||
Object.keys(styledIndexes).forEach(key => { | ||
offset -= styledIndexes[key].length; | ||
@@ -97,5 +93,3 @@ }); | ||
.split(/\n/) | ||
.reduce(function (greeting, str, index, array) { | ||
var paddedString; | ||
.reduce((greeting, str, index, array) => { | ||
if (!regExNewLine.test(str)) { | ||
@@ -109,3 +103,3 @@ str = str.trim(); | ||
.substr(completedString.length - str.length) | ||
.replace(/./g, function (char, charIndex) { | ||
.replace(/./g, (char, charIndex) => { | ||
if (index > 0) { | ||
@@ -115,6 +109,6 @@ charIndex += completedString.length - str.length + index; | ||
var hasContinuedStyle = 0; | ||
var continuedStyle; | ||
let hasContinuedStyle = 0; | ||
let continuedStyle; | ||
Object.keys(styledIndexes).forEach(function (offset) { | ||
Object.keys(styledIndexes).forEach(offset => { | ||
if (charIndex > offset) { | ||
@@ -140,5 +134,5 @@ hasContinuedStyle++; | ||
paddedString = pad({ | ||
const paddedString = pad({ | ||
length: stringWidth(str), | ||
valueOf: function () { | ||
valueOf() { | ||
return ansiStyles.reset.open + str + ansiStyles.reset.open; | ||
@@ -163,5 +157,5 @@ } | ||
if (array.length > MAX_MESSAGE_LINES_BEFORE_OVERFLOW) { | ||
var emptyLines = Math.ceil((array.length - MAX_MESSAGE_LINES_BEFORE_OVERFLOW) / 2); | ||
const emptyLines = Math.ceil((array.length - MAX_MESSAGE_LINES_BEFORE_OVERFLOW) / 2); | ||
for (var i = 0; i < emptyLines; i++) { | ||
for (let i = 0; i < emptyLines; i++) { | ||
greeting.unshift(''); | ||
@@ -168,0 +162,0 @@ } |
{ | ||
"name": "yosay", | ||
"version": "1.2.1", | ||
"version": "2.0.0", | ||
"description": "Tell Yeoman what to say", | ||
"license": "BSD-2-Clause", | ||
"repository": "yeoman/yosay", | ||
"homepage": "yeoman.io", | ||
"author": "Yeoman", | ||
"bin": "cli.js", | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && mocha" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"cli.js" | ||
], | ||
"keywords": [ | ||
"cli-app", | ||
"cli", | ||
"bin", | ||
"yeoman", | ||
@@ -18,24 +31,9 @@ "yo", | ||
], | ||
"homepage": "yeoman.io", | ||
"author": "Yeoman", | ||
"repository": "yeoman/yosay", | ||
"bin": "cli.js", | ||
"files": [ | ||
"index.js", | ||
"cli.js" | ||
], | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"scripts": { | ||
"test": "xo && mocha" | ||
}, | ||
"dependencies": { | ||
"ansi-regex": "^2.0.0", | ||
"ansi-styles": "^2.0.0", | ||
"ansi-styles": "^3.0.0", | ||
"chalk": "^1.0.0", | ||
"cli-boxes": "^1.0.0", | ||
"pad-component": "0.0.1", | ||
"repeating": "^2.0.0", | ||
"string-width": "^1.0.0", | ||
"string-width": "^2.0.0", | ||
"strip-ansi": "^3.0.0", | ||
@@ -46,4 +44,4 @@ "taketalk": "^1.0.0", | ||
"devDependencies": { | ||
"mocha": "*", | ||
"xo": "*" | ||
"mocha": "^3.2.0", | ||
"xo": "^0.17.0" | ||
}, | ||
@@ -50,0 +48,0 @@ "xo": { |
@@ -37,3 +37,3 @@ # yosay [![Build Status](https://travis-ci.org/yeoman/yosay.svg?branch=master)](https://travis-ci.org/yeoman/yosay) | ||
*You can style your text with [chalk](https://github.com/sindresorhus/chalk) before passing it to `yosay`.* | ||
*You can style your text with [`chalk`](https://github.com/sindresorhus/chalk) before passing it to `yosay`.* | ||
@@ -51,8 +51,8 @@ | ||
Usage | ||
yosay <string> | ||
yosay <string> --maxLength 8 | ||
echo <string> | yosay | ||
$ yosay <string> | ||
$ yosay <string> --maxLength 8 | ||
$ echo <string> | yosay | ||
Example | ||
yosay 'Sindre is a horse' | ||
$ yosay 'Sindre is a horse' | ||
@@ -59,0 +59,0 @@ _-----_ |
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
9
8872
163
+ Addedansi-regex@3.0.1(transitive)
+ Addedansi-styles@3.2.1(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedis-fullwidth-code-point@2.0.0(transitive)
+ Addedstring-width@2.1.1(transitive)
+ Addedstrip-ansi@4.0.0(transitive)
- Removedrepeating@^2.0.0
- Removedis-finite@1.1.0(transitive)
- Removedrepeating@2.0.1(transitive)
Updatedansi-styles@^3.0.0
Updatedstring-width@^2.0.0