chalk-animation
Advanced tools
Comparing version 1.3.0 to 1.4.0
43
cli.js
#!/usr/bin/env node | ||
const meow = require('meow'); | ||
const chalkAnim = require('.'); | ||
if (process.argv.length < 4) { | ||
console.error('Usage\n $ chalk-animation <name> [text...]'); | ||
console.error('\nAvailable animations\n ' + Object.keys(chalkAnim).join('\n ')); | ||
console.error('\nExample\n $ chalk-animation rainbow Hello world!'); | ||
// eslint-disable-next-line no-process-exit | ||
process.exit(2); | ||
const names = Object.keys(chalkAnim); | ||
const cli = meow(` | ||
Usage | ||
$ chalk-animation <name> [options] [text...] | ||
Options | ||
--duration Duration of the animation in ms, defaults to Infinity | ||
--speed Animation speed as number > 0, defaults to 1 | ||
Available animations | ||
${names.join('\n ')} | ||
Example | ||
$ chalk-animation rainbow Hello world! | ||
`); | ||
if (cli.input.length < 2) { | ||
cli.showHelp(2); | ||
} | ||
if (!(process.argv[2] in chalkAnim)) { | ||
console.error('error: unknown animation name:', process.argv[2]); | ||
// eslint-disable-next-line no-process-exit | ||
const name = cli.input[0]; | ||
const payload = cli.input.slice(1); | ||
const effect = chalkAnim[name]; | ||
if (typeof effect === 'undefined') { | ||
console.error(`error: unknown animation name: "${name}", must be one of: ${names.join(', ')}`); | ||
process.exit(1); | ||
} | ||
const effect = chalkAnim[process.argv[2]]; | ||
const animation = effect(payload.join(' '), cli.flags.speed); | ||
effect(process.argv.slice(3).join(' ')); | ||
if (typeof cli.flags.duration === 'number') { | ||
setTimeout(() => { | ||
animation.stop(); | ||
}, cli.flags.duration); | ||
} |
16
index.js
'use strict'; | ||
const chalk = require('chalk'); | ||
@@ -9,3 +10,3 @@ const gradient = require('gradient-string'); | ||
const consoleFunctions = { | ||
log: console.log.bind(console), | ||
log: log.bind(console), | ||
info: console.info.bind(console), | ||
@@ -72,2 +73,3 @@ warn: console.warn.bind(console), | ||
const chunks = []; | ||
for (let i = 0, length = str.length; i < length; i++) { | ||
@@ -176,6 +178,8 @@ const skip = Math.round(Math.max(0, (Math.random() - 0.8) * chunkSize)); | ||
module.exports.rainbow = (str, speed) => animateString(str, effects.rainbow, 15, speed); | ||
module.exports.pulse = (str, speed) => animateString(str, effects.pulse, 16, speed); | ||
module.exports.glitch = (str, speed) => animateString(str, effects.glitch, 55, speed); | ||
module.exports.radar = (str, speed) => animateString(str, effects.radar, 50, speed); | ||
module.exports.neon = (str, speed) => animateString(str, effects.neon, 500, speed); | ||
module.exports = { | ||
rainbow: (str, speed) => animateString(str, effects.rainbow, 15, speed), | ||
pulse: (str, speed) => animateString(str, effects.pulse, 16, speed), | ||
glitch: (str, speed) => animateString(str, effects.glitch, 55, speed), | ||
radar: (str, speed) => animateString(str, effects.radar, 50, speed), | ||
neon: (str, speed) => animateString(str, effects.neon, 500, speed) | ||
}; |
{ | ||
"name": "chalk-animation", | ||
"description": "Colorful animations in terminal output", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"author": "Boris K", | ||
@@ -10,3 +10,4 @@ "bugs": "https://github.com/bokub/chalk-animation/issues", | ||
"chalk": "^2.1.0", | ||
"gradient-string": "^0.1.2" | ||
"gradient-string": "^0.1.2", | ||
"meow": "^4.0.0" | ||
}, | ||
@@ -13,0 +14,0 @@ "devDependencies": { |
@@ -6,3 +6,4 @@ # chalk-animation | ||
[](https://github.com/sindresorhus/xo) | ||
[](https://codeclimate.com/github/bokub/chalk-animation) | ||
[](https://codeclimate.com/github/bokub/chalk-animation/maintainability) | ||
[](https://www.npmjs.com/package/chalk-animation) | ||
@@ -26,3 +27,3 @@ > Colorful animations in terminal output | ||
```bash | ||
$ npm install --save chalk-animation | ||
$ npm i chalk-animation | ||
``` | ||
@@ -116,14 +117,20 @@ | ||
Usage | ||
$ chalk-animation <name> [text...] | ||
Colorful animations in terminal output | ||
Available animations | ||
rainbow | ||
pulse | ||
glitch | ||
radar | ||
neon | ||
Usage | ||
$ chalk-animation <name> [options] [text...] | ||
Example | ||
$ chalk-animation rainbow Hello world! | ||
Options | ||
--duration Duration of the animation in ms, defaults to Infinity | ||
--speed Animation speed as number > 0, defaults to 1 | ||
Available animations | ||
rainbow | ||
pulse | ||
glitch | ||
radar | ||
neon | ||
Example | ||
$ chalk-animation rainbow Hello world! | ||
``` | ||
@@ -130,0 +137,0 @@ |
Sorry, the diff of this file is not supported yet
202
145
11759
3
9
+ Addedmeow@^4.0.0
+ Addedarray-find-index@1.0.2(transitive)
+ Addedarrify@1.0.1(transitive)
+ Addedcamelcase@4.1.0(transitive)
+ Addedcamelcase-keys@4.2.0(transitive)
+ Addedcurrently-unhandled@0.4.1(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addeddecamelize-keys@1.1.1(transitive)
+ Addederror-ex@1.3.2(transitive)
+ Addedfind-up@2.1.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhosted-git-info@2.8.9(transitive)
+ Addedindent-string@3.2.0(transitive)
+ Addedis-arrayish@0.2.1(transitive)
+ Addedis-core-module@2.16.1(transitive)
+ Addedis-plain-obj@1.1.0(transitive)
+ Addedjson-parse-better-errors@1.0.2(transitive)
+ Addedload-json-file@4.0.0(transitive)
+ Addedlocate-path@2.0.0(transitive)
+ Addedloud-rejection@1.6.0(transitive)
+ Addedmap-obj@1.0.12.0.0(transitive)
+ Addedmeow@4.0.1(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedminimist-options@3.0.2(transitive)
+ Addednormalize-package-data@2.5.0(transitive)
+ Addedp-limit@1.3.0(transitive)
+ Addedp-locate@2.0.0(transitive)
+ Addedp-try@1.0.0(transitive)
+ Addedparse-json@4.0.0(transitive)
+ Addedpath-exists@3.0.0(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpath-type@3.0.0(transitive)
+ Addedpify@3.0.0(transitive)
+ Addedquick-lru@1.1.0(transitive)
+ Addedread-pkg@3.0.0(transitive)
+ Addedread-pkg-up@3.0.0(transitive)
+ Addedredent@2.0.0(transitive)
+ Addedresolve@1.22.10(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedspdx-correct@3.2.0(transitive)
+ Addedspdx-exceptions@2.5.0(transitive)
+ Addedspdx-expression-parse@3.0.1(transitive)
+ Addedspdx-license-ids@3.0.21(transitive)
+ Addedstrip-bom@3.0.0(transitive)
+ Addedstrip-indent@2.0.0(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedtrim-newlines@2.0.0(transitive)
+ Addedvalidate-npm-package-license@3.0.4(transitive)