Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

asciify

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asciify - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

.idea/.name

39

bin/asciify.js

@@ -15,4 +15,2 @@ #!/usr/bin/env node

var asciify = require('../');
var fs = require('fs');
var path = require('path');
var pad = require('pad');

@@ -58,4 +56,6 @@ var argv = require('optimist')

console.log('');
argv._.forEach(function(arg){
asciify(arg, argv.font, function(err, result){
argv._.forEach(function (arg) {
asciify(arg, argv.font, function (err, result) {
if (err) { return console.error(err); }
console.log(result);

@@ -68,8 +68,10 @@ });

*/
function listFonts(){
getFonts(function(fonts){
function listFonts () {
asciify.getFonts(function (err, fonts) {
if (err) { return console.error(err); }
var padSize = ('' + fonts.length).length;
fonts.forEach(function(font, index){
fonts.forEach(function (font, index) {
console.log(pad(padSize, index+1, '0') + ': ' + font);

@@ -83,5 +85,6 @@ });

*/
function showAll(text){
function showAll (text) {
getFonts(function(fonts){
asciify.getFonts(function (err, fonts) {
if (err) { return console.error(err); }

@@ -92,3 +95,3 @@ var padSize = ('' + fonts.length).length;

asciify(exampleText, font, function(err, result){
asciify(exampleText, font, function (err, result) {
console.log(pad(padSize, index+1, '0') + ': ' + font);

@@ -101,17 +104,1 @@ console.log(result);

}
/*
* Privide the callback with the list of fontnames, sans file extention.
*/
function getFonts(callback){
var fontsDir = path.resolve(__dirname, '..', 'lib', 'figlet-js', 'fonts');
fs.readdir(fontsDir, function(err, files){
var fonts = files.map(function(file){
return file.slice(0, file.length - 4); // chop off the '.flf' extension
});
callback(fonts);
});
}

@@ -7,3 +7,3 @@ /*

\____|__ //_______ / \______ /|___||___| \___ / / ______| __
\/ \/ \/ \/ \/ \/
\/ \/ \/ \/ \/ \/

@@ -15,8 +15,12 @@ Usage: node example.js

asciify('ASCIIFY!', function(err, result){
console.log(result);
asciify.getFonts(function (err, fonts) {
console.log('Available fonts',fonts);
});
asciify('Got Fonts?', '3-d', function(err, result){
console.log(result);
asciify('ASCIIFY!', function (err, result) {
console.log('\nASCIIFY!\n', result);
});
asciify('Got Fonts?', '3-d', function (err, result) {
console.log('\nGot Fonts?\n', result);
});

@@ -10,7 +10,14 @@ /*

Install: npm install asciify
Usage: asciify('foo', {font:'3-d'}, function(err, result){console.log(result)})
Usage:
var asciify = require('asciify');
asciify('Whoa', {font:'3-d'}, function(err, result){console.log(result)});
*/
var path = require('path');
var fs = require('fs');
module.exports = function (text, opts, callback) {
// Ensure text is a string
text = text + '';
if (typeof opts === 'function') {

@@ -21,5 +28,4 @@ callback = opts;

if (!opts) {
opts = { font: 'graffiti' };
}
// Fix up the opts. Default font is graffiti.
opts = opts || {};

@@ -30,3 +36,9 @@ if (typeof opts === 'string') {

asciify(text, opts.font, function(err, result){
opts.font = opts.font || 'graffiti';
if (typeof opts.font !== 'string') {
callback('opts.font should be a font name string')
}
asciify(text, opts.font, function (err, result) {
callback(err, result);

@@ -36,5 +48,5 @@ });

// Current implementation depends on figlet-js.
function asciify(text, font, callback){
function asciify (text, font, callback) {
var figlet = require('./lib/figlet-js/figlet-node');
figlet.Figlet.write(text, opts.font, function(err, asciifiedText){
figlet.Figlet.write(text, font, function (err, asciifiedText) {
callback(err, asciifiedText);

@@ -44,1 +56,21 @@ });

};
/*
* Provide the callback with array of font names, sans file extension.
*/
module.exports.getFonts = function (callback) {
var fontsDir = path.resolve(__dirname, 'lib', 'figlet-js', 'fonts');
// No caching, just reading. Caller should cache if they need to.
fs.readdir(fontsDir, function (err, files) {
if (err) { return callback(err); }
var fonts = files.map(function (file) {
return file.slice(0, file.length - 4); // chop off the '.flf' extension
});
callback(err, fonts);
});
};
{
"name": "asciify",
"version": "1.2.0",
"version": "1.3.0",
"description": "Plain text awesomizer. A hybrid npm module and CLI for turning plain text into ascii art.",
"main": "index.js",
"dependencies": {
"optimist": "~0.3.5",
"optimist": "~0.5.2",
"pad": "0.0.4"

@@ -34,3 +34,3 @@ },

"author": "olizilla",
"license" : "BSD"
"license": "BSD"
}

@@ -12,2 +12,3 @@ ASCIIFY

[![Build Status](https://travis-ci.org/olizilla/asciify.png)](https://travis-ci.org/olizilla/asciify)
[![Dependency Status](https://david-dm.org/olizilla/asciify.png)](https://david-dm.org/olizilla/asciify)

@@ -63,2 +64,6 @@

**Bonus method**
asciify.getFonts(function (err, fonts) { fonts.forEach( console.log ) )
## Thanks to

@@ -76,3 +81,4 @@

* 1.3.0 - Adds input validation and a getFonts method
* 1.2.0 - Asciify now a good node citizen, callback takes an error as first arg.
* 1.0.1 - IT BEGINS. ASCII BANNERS NOW MANDTORY.

@@ -6,4 +6,9 @@ var test = require('tap').test;

t.plan(3);
t.plan(4);
// Did any fonts go missing?
asciify.getFonts(function (err, fonts){
t.equal(fonts.length, 147, 'We should have 147 fonts');
});
// A simple line-noise style comparison of asciified result with raw string

@@ -38,3 +43,87 @@ asciify('A', function(err, res){

// The font option is optional (obviously) and should default sensibly if a falsy value is passed
test("Check asciify defaults font option correctly", function (t) {
var expected = multilinehack(function(){/*
_____
\__ \
/ __ \_
(____ /
\/
*/});
var fonts = [null, undefined, '', false, 0, NaN];
t.plan(fonts.length * 2);
fonts.forEach(function(font) {
asciify('a', {font: font}, function(err, res){
t.notOk(err);
t.equal(res, expected, '"a" should have been rendered in the graffiti figlet font');
});
});
});
test("Check asciify ensures text is a string", function (t) {
t.plan(3);
asciify(138, 'pyramid', function(err, res){
t.equal(
res,
multilinehack(function(){/*
^ ^ ^
/1\ /3\ /8\
<___><___><___>
*/}),
'138 should have been rendered in the pyramid figlet font'
);
});
asciify(false, 'pyramid', function(err, res){
t.equal(
res,
multilinehack(function(){/*
^ ^ ^ ^ ^
/f\ /a\ /l\ /s\ /e\
<___><___><___><___><___>
*/}),
'false should have been rendered in the pyramid figlet font'
);
});
asciify(undefined, 'pyramid', function(err, res){
t.equal(
res,
multilinehack(function(){/*
^ ^ ^ ^ ^ ^ ^ ^ ^
/u\ /n\ /d\ /e\ /f\ /i\ /n\ /e\ /d\
<___><___><___><___><___><___><___><___><___>
*/}),
'undefined should have been rendered in the pyramid figlet font'
);
});
});
test("Check asciify errors if font name is not a string", function (t) {
t.plan(2);
asciify('OMG', {font: 10}, function(err, res){
t.assert(err, 'Passing in 10 as the font name should cause an error');
});
asciify('OMG', 10, function(err, res){
t.assert(err, 'Passing in 10 as the options object should cause an error');
});
});
// Helper to make the tests more "readable"
function multilinehack(mess){

@@ -41,0 +130,0 @@ // Crazyballs multiline hack courtesy of: https://github.com/isaacs/node-tap/blob/69d721718acc56b5c8ae5875cf8d9bf53f7d5016/bin/tap.js#L58

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc