├── .github └── FUNDING.yml ├── .gitignore ├── CONTRIBUTING.md ├── DOCUMENTATION.md ├── LICENSE ├── README.md ├── example └── index.js ├── lib ├── animations │ ├── bottom-top.js │ └── top-bottom.js └── index.js └── package.json /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: ionicabizau 2 | patreon: ionicabizau 3 | open_collective: ionicabizau 4 | custom: https://www.buymeacoffee.com/h96wwchmy -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.swo 3 | *~ 4 | *.log 5 | node_modules 6 | *.env 7 | .DS_Store 8 | package-lock.json 9 | .bloggify/* 10 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # 🌟 Contributing 2 | 3 | Want to contribute to this project? Great! Please read these quick steps to streamline the process and avoid unnecessary tasks. ✨ 4 | 5 | ## 💬 Discuss Changes 6 | Start by opening an issue in the repository using the [bug tracker][1]. Describe your proposed contribution or the bug you've found. If relevant, include platform info and screenshots. 🖼️ 7 | 8 | Wait for feedback before proceeding unless the fix is straightforward, like a typo. 📝 9 | 10 | ## 🔧 Fixing Issues 11 | 12 | Fork the project and create a branch for your fix, naming it `some-great-feature` or `some-issue-fix`. Commit changes while following the [code style][2]. If the project has tests, add one. ✅ 13 | 14 | If a `package.json` or `bower.json` exists, add yourself to the `contributors` array; create it if it doesn't. 🙌 15 | 16 | ```json 17 | { 18 | "contributors": [ 19 | "Your Name (http://your.website)" 20 | ] 21 | } 22 | ``` 23 | 24 | ## 📬 Creating a Pull Request 25 | Open a pull request and reference the initial issue (e.g., *fixes #*). Provide a clear title and consider adding visual aids for clarity. 📊 26 | 27 | ## ⏳ Wait for Feedback 28 | Your contributions will be reviewed. If feedback is given, update your branch as needed, and the pull request will auto-update. 🔄 29 | 30 | ## 🎉 Everyone Is Happy! 31 | Your contributions will be merged, and everyone will appreciate your effort! 😄❤️ 32 | 33 | Thanks! 🤩 34 | 35 | [1]: /issues 36 | [2]: https://github.com/IonicaBizau/code-style -------------------------------------------------------------------------------- /DOCUMENTATION.md: -------------------------------------------------------------------------------- 1 | ## Documentation 2 | 3 | You can see below the API reference of this module. 4 | 5 | ### `TextAnimation(options, callback)` 6 | Creates the animation with provided text. 7 | 8 | #### Params 9 | 10 | - **String|Object** `options`: The string value with the text that you want to animate or an object containing the following fields: 11 | 12 | - `text` (String): The text that you want to animate. 13 | 14 | - `end` (Function): The handler that will be called when the animation 15 | is eneded. If the `callback` parameter is provided, then this 16 | field will be overridden (default: an empty function). 17 | 18 | - `animation` (String): The animation type. Actually, this is one of 19 | filenames from `lib/animations` directory (default: `"bottom-top"`). 20 | 21 | - `delay` (Number): The frame delay in milliseconds (default: `100`). 22 | 23 | - `size` (String): The size of the box in the following format: `WIDTHxHEIGHT`. 24 | If this is not provided, the box will take the fullscreen size. 25 | 26 | - `font` (String): The text font (default: `"Graffiti"`). 27 | 28 | Additional fields are added to `options` object: 29 | 30 | - `size` (Array): The provided string is splitted and the value will be an array. 31 | - `box` (CliBox): The CliBox wrapper object. 32 | - `rText` (String): The rendered text using the Figlet lirary. This is added asynchronously. 33 | - **Function** `callback`: The callback function. 34 | 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-25 Ionică Bizău (https://ionicabizau.net) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | # text-animation 21 | 22 | [![Support me on Patreon][badge_patreon]][patreon] [![Buy me a book][badge_amazon]][amazon] [![PayPal][badge_paypal_donate]][paypal-donations] [![Ask me anything](https://img.shields.io/badge/ask%20me-anything-1abc9c.svg)](https://github.com/IonicaBizau/ama) [![Version](https://img.shields.io/npm/v/text-animation.svg)](https://www.npmjs.com/package/text-animation) [![Downloads](https://img.shields.io/npm/dt/text-animation.svg)](https://www.npmjs.com/package/text-animation) [![Get help on Codementor](https://cdn.codementor.io/badges/get_help_github.svg)](https://www.codementor.io/@johnnyb?utm_source=github&utm_medium=button&utm_term=johnnyb&utm_campaign=github) 23 | 24 | Buy Me A Coffee 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | > Create beautiful ASCII text animations using NodeJS. 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | ## :cloud: Installation 51 | 52 | ```sh 53 | # Using npm 54 | npm install --save text-animation 55 | 56 | # Using yarn 57 | yarn add text-animation 58 | ``` 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | ## :clipboard: Example 73 | 74 | 75 | 76 | ```js 77 | // Dependencies 78 | var TextAnimation = require("text-animation"); 79 | 80 | // Animate bottom-top 81 | TextAnimation("Hello...", function (err) { 82 | if (err) throw err; 83 | // And then, top-bottom 84 | TextAnimation({ 85 | text: "...World!" 86 | , animation: "top-bottom" 87 | }); 88 | }); 89 | ``` 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | ## :question: Get Help 103 | 104 | There are few ways to get help: 105 | 106 | 107 | 108 | 1. Please [post questions on Stack Overflow](https://stackoverflow.com/questions/ask). You can open issues with questions, as long you add a link to your Stack Overflow question. 109 | 2. For bug reports and feature requests, open issues. :bug: 110 | 3. For direct and quick help, you can [use Codementor](https://www.codementor.io/johnnyb). :rocket: 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | ## :memo: Documentation 119 | 120 | 121 | ### `TextAnimation(options, callback)` 122 | Creates the animation with provided text. 123 | 124 | #### Params 125 | 126 | - **String|Object** `options`: The string value with the text that you want to animate or an object containing the following fields: 127 | 128 | - `text` (String): The text that you want to animate. 129 | 130 | - `end` (Function): The handler that will be called when the animation 131 | is eneded. If the `callback` parameter is provided, then this 132 | field will be overridden (default: an empty function). 133 | 134 | - `animation` (String): The animation type. Actually, this is one of 135 | filenames from `lib/animations` directory (default: `"bottom-top"`). 136 | 137 | - `delay` (Number): The frame delay in milliseconds (default: `100`). 138 | 139 | - `size` (String): The size of the box in the following format: `WIDTHxHEIGHT`. 140 | If this is not provided, the box will take the fullscreen size. 141 | 142 | - `font` (String): The text font (default: `"Graffiti"`). 143 | 144 | Additional fields are added to `options` object: 145 | 146 | - `size` (Array): The provided string is splitted and the value will be an array. 147 | - `box` (CliBox): The CliBox wrapper object. 148 | - `rText` (String): The rendered text using the Figlet lirary. This is added asynchronously. 149 | - **Function** `callback`: The callback function. 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | ## :yum: How to contribute 165 | Have an idea? Found a bug? See [how to contribute][contributing]. 166 | 167 | 168 | ## :sparkling_heart: Support my projects 169 | I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously, 170 | this takes time. You can integrate and use these projects in your applications *for free*! You can even change the source code and redistribute (even resell it). 171 | 172 | However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it: 173 | 174 | 175 | - Starring and sharing the projects you like :rocket: 176 | - [![Buy me a book][badge_amazon]][amazon]—I love books! I will remember you after years if you buy me one. :grin: :book: 177 | - [![PayPal][badge_paypal]][paypal-donations]—You can make one-time donations via PayPal. I'll probably buy a ~~coffee~~ tea. :tea: 178 | - [![Support me on Patreon][badge_patreon]][patreon]—Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone). 179 | - **Bitcoin**—You can send me bitcoins at this address (or scanning the code below): `1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6` 180 | 181 | ![](https://i.imgur.com/z6OQI95.png) 182 | 183 | 184 | Thanks! :heart: 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | ## :scroll: License 210 | 211 | [MIT][license] © [Ionică Bizău][website] 212 | 213 | 214 | 215 | 216 | 217 | 218 | [license]: /LICENSE 219 | [website]: https://ionicabizau.net 220 | [contributing]: /CONTRIBUTING.md 221 | [docs]: /DOCUMENTATION.md 222 | [badge_patreon]: https://ionicabizau.github.io/badges/patreon.svg 223 | [badge_amazon]: https://ionicabizau.github.io/badges/amazon.svg 224 | [badge_paypal]: https://ionicabizau.github.io/badges/paypal.svg 225 | [badge_paypal_donate]: https://ionicabizau.github.io/badges/paypal_donate.svg 226 | [patreon]: https://www.patreon.com/ionicabizau 227 | [amazon]: http://amzn.eu/hRo9sIZ 228 | [paypal-donations]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RVXDDLKKLQRJW 229 | -------------------------------------------------------------------------------- /example/index.js: -------------------------------------------------------------------------------- 1 | // Dependencies 2 | var TextAnimation = require("../lib"); 3 | 4 | // Animate bottom-top 5 | TextAnimation("Hello...", function (err) { 6 | if (err) throw err; 7 | // And then, top-bottom 8 | TextAnimation({ 9 | text: "...World!" 10 | , animation: "top-bottom" 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /lib/animations/bottom-top.js: -------------------------------------------------------------------------------- 1 | // Dependencies 2 | var Overlap = require("overlap"); 3 | 4 | // Bottom Top Animation 5 | module.exports = function (options) { 6 | var box = options.box.toString() 7 | , frames = [] 8 | , splits = options.rText.split("\n") 9 | , x = options.box.settings.width / 2 - splits[0].length / 2 10 | , y = options.box.settings.height - splits.length + 2 11 | ; 12 | 13 | for (; y > 1; --y) { 14 | frames.push(Overlap({ 15 | who: box 16 | , with: options.rText 17 | , where: { 18 | x: x 19 | , y: y 20 | } 21 | }).trim()); 22 | } 23 | 24 | return frames; 25 | }; 26 | -------------------------------------------------------------------------------- /lib/animations/top-bottom.js: -------------------------------------------------------------------------------- 1 | // Dependencies 2 | var Overlap = require("overlap"); 3 | 4 | // Top Bottom Animation 5 | module.exports = function (options) { 6 | var box = options.box.toString() 7 | , frames = [] 8 | , splits = options.rText.split("\n") 9 | , x = options.box.settings.width / 2 - splits[0].length / 2 10 | ; 11 | 12 | for (var y = 1; y < options.box.settings.height - splits.length + 2; ++y) { 13 | frames.push(Overlap({ 14 | who: box 15 | , with: options.rText 16 | , where: { 17 | x: x 18 | , y: y 19 | } 20 | }).trim()); 21 | } 22 | 23 | return frames; 24 | }; 25 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | // Dependencies 2 | var Figlet = require("figlet") 3 | , CliFrames = require("cli-frames") 4 | , CliBox = require("cli-box") 5 | ; 6 | 7 | /** 8 | * TextAnimation 9 | * Creates the animation with provided text. 10 | * 11 | * @name TextAnimation 12 | * @function 13 | * @param {String|Object} options The string value with the text that 14 | * you want to animate or an object containing the following fields: 15 | * 16 | * - `text` (String): The text that you want to animate. 17 | * 18 | * - `end` (Function): The handler that will be called when the animation 19 | * is eneded. If the `callback` parameter is provided, then this 20 | * field will be overridden (default: an empty function). 21 | * 22 | * - `animation` (String): The animation type. Actually, this is one of 23 | * filenames from `lib/animations` directory (default: `"bottom-top"`). 24 | * 25 | * - `delay` (Number): The frame delay in milliseconds (default: `100`). 26 | * 27 | * - `size` (String): The size of the box in the following format: `WIDTHxHEIGHT`. 28 | * If this is not provided, the box will take the fullscreen size. 29 | * 30 | * - `font` (String): The text font (default: `"Graffiti"`). 31 | * 32 | * Additional fields are added to `options` object: 33 | * 34 | * - `size` (Array): The provided string is splitted and the value will be an array. 35 | * - `box` (CliBox): The CliBox wrapper object. 36 | * - `rText` (String): The rendered text using the Figlet lirary. This is added asynchronously. 37 | * 38 | * @param {Function} callback The callback function. 39 | */ 40 | var TextAnimation = module.exports = function (options, callback) { 41 | 42 | // TextAnimation("foo", callback); 43 | if (typeof options === "string") { 44 | options = { 45 | text: options 46 | }; 47 | } else { 48 | options = Object(options); 49 | } 50 | 51 | // Add the end handler 52 | options.end = options.end || function (err) { 53 | if (err) { 54 | console.log(err); 55 | } 56 | }; 57 | if (typeof callback === "function") { 58 | options.end = callback; 59 | } 60 | 61 | // Create the boxOptions 62 | var boxOptions = { 63 | marks: { 64 | nw: "╔" 65 | , n: "═" 66 | , ne: "╗" 67 | , e: "║" 68 | , se: "╝" 69 | , s: "═" 70 | , sw: "╚" 71 | , w: "║" 72 | , b: " " 73 | } 74 | }; 75 | 76 | options.animation = options.animation || "bottom-top"; 77 | options.delay = options.delay || 100; 78 | 79 | // Handle the provided size 80 | if (/^[0-9]+x[0-9]+$/.test(options.size)) { 81 | options.size = options.size.split("x").map(function (c) { 82 | return parseInt(c); 83 | }); 84 | boxOptions.width = options.size[0]; 85 | boxOptions.height = options.size[1]; 86 | } else { 87 | boxOptions.fullscreen = true; 88 | process.stdout.columns = process.stdout.columns || 80; 89 | process.stdout.rows = process.stdout.rows || 60; 90 | } 91 | 92 | var box = options.box = new CliBox(boxOptions) 93 | , font = options.font || "Graffiti" 94 | , text = options.text 95 | , frames = [] 96 | ; 97 | 98 | 99 | // Render the text 100 | Figlet.text(text, { 101 | font: font, 102 | }, function(err, data) { 103 | 104 | if (err) { 105 | return options.end(err, data); 106 | } 107 | 108 | options.rText = data; 109 | 110 | try { 111 | frames = require("./animations/" + options.animation)(options); 112 | } catch (e) { 113 | return options.end(e); 114 | } 115 | 116 | new CliFrames({ 117 | frames: frames 118 | , autostart: { 119 | delay: options.delay 120 | , end: function (err) { 121 | options.end(err, frames); 122 | } 123 | } 124 | }); 125 | }); 126 | }; 127 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "text-animation", 3 | "version": "1.2.11", 4 | "description": "Create beautiful ASCII text animations using NodeJS.", 5 | "main": "lib/index.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "node test/index.js" 12 | }, 13 | "keywords": [ 14 | "ascii", 15 | "animate", 16 | "node", 17 | "npm" 18 | ], 19 | "author": "Ionică Bizău (https://ionicabizau.net)", 20 | "contributors": [ 21 | "Ionică Bizău ", 22 | "Radu-Bogdan Croitoru " 23 | ], 24 | "license": "MIT", 25 | "dependencies": { 26 | "figlet": "1.1.0", 27 | "cli-box": "2.1.1", 28 | "cli-frames": "1.0.0", 29 | "overlap": "1.4.0" 30 | }, 31 | "repository": { 32 | "type": "git", 33 | "url": "https://github.com/IonicaBizau/text-animation.git" 34 | }, 35 | "bugs": { 36 | "url": "https://github.com/IonicaBizau/text-animation/issues" 37 | }, 38 | "homepage": "https://github.com/IonicaBizau/text-animation", 39 | "files": [ 40 | "bin/", 41 | "app/", 42 | "lib/", 43 | "dist/", 44 | "src/", 45 | "scripts/", 46 | "resources/", 47 | "menu/", 48 | "cli.js", 49 | "index.js", 50 | "index.d.ts", 51 | "package-lock.json", 52 | "bloggify.js", 53 | "bloggify.json", 54 | "bloggify/" 55 | ] 56 | } --------------------------------------------------------------------------------