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

figlet

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

figlet - npm Package Compare versions

Comparing version 1.6.0-beta.1 to 1.6.0

.idea/prettier.xml

12

bin/index.js
#!/usr/bin/env node
const figlet = require('../lib/node-figlet');
const figlet = require("../lib/node-figlet");

@@ -7,10 +7,10 @@ const [text] = process.argv.slice(2);

if (!text) {
throw new Error('You need to provide some text.');
throw new Error("You need to provide some text.");
}
figlet(text, function (err, formattedText) {
if (err) {
throw err;
}
console.log(formattedText);
if (err) {
throw err;
}
console.log(formattedText);
});

@@ -5,3 +5,3 @@ /*

var figlet = require('../../lib/node-figlet.js');
var figlet = require("../../lib/node-figlet.js");

@@ -17,7 +17,16 @@ /*

figlet('Hello World!', 'Standard', function(err, data) {
figlet("Hello World!", "Standard", function (err, data) {
if (err) {
console.log("Something went wrong...");
console.dir(err);
return;
}
console.log(data);
figlet.text("Again, Hello World!", "Graffiti", function (err, data) {
if (err) {
console.log('Something went wrong...');
console.dir(err);
return;
console.log("Something went wrong...");
console.dir(err);
return;
}

@@ -27,26 +36,19 @@

figlet.text('Again, Hello World!', 'Graffiti', function(err, data) {
figlet.text(
"Last time...",
{
font: "Standard",
horizontalLayout: "full",
verticalLayout: "full",
},
function (err, data) {
if (err) {
console.log('Something went wrong...');
console.dir(err);
return;
console.log("Something went wrong...");
console.dir(err);
return;
}
console.log(data);
figlet.text('Last time...', {
font: 'Standard',
horizontalLayout: 'full',
verticalLayout: 'full'
}, function(err, data) {
if (err) {
console.log('Something went wrong...');
console.dir(err);
return;
}
console.log(data);
});
});
}
);
});
});

@@ -5,3 +5,3 @@ /*

var figlet = require('../../lib/node-figlet.js');
var figlet = require("../../lib/node-figlet.js");

@@ -17,8 +17,10 @@ /*

console.log(figlet.textSync('Hello World!', 'Standard'));
console.log(figlet.textSync('Again, Hello World!', 'Graffiti'));
console.log(figlet.textSync('Last time...', {
font: 'Standard',
horizontalLayout: 'full',
verticalLayout: 'full'
}));
console.log(figlet.textSync("Hello World!", "Standard"));
console.log(figlet.textSync("Again, Hello World!", "Graffiti"));
console.log(
figlet.textSync("Last time...", {
font: "Standard",
horizontalLayout: "full",
verticalLayout: "full",
})
);

@@ -1,42 +0,35 @@

'use strict';
"use strict";
module.exports = function(grunt) {
module.exports = function (grunt) {
// Project configuration.
grunt.initConfig({
jshint: {
all: ["Gruntfile.js", "lib/*.js", "<%= nodeunit.tests %>"],
options: {
jshintrc: ".jshintrc",
},
},
// Project configuration.
grunt.initConfig({
jshint: {
all: [
'Gruntfile.js',
'lib/*.js',
'<%= nodeunit.tests %>',
],
options: {
jshintrc: '.jshintrc',
},
},
// Before generating any new files, remove any previously-created files.
clean: {
tests: ["tmp"],
},
// Before generating any new files, remove any previously-created files.
clean: {
tests: ['tmp'],
},
// Unit tests.
nodeunit: {
tests: ["test/*_test.js"],
},
});
// Unit tests.
nodeunit: {
tests: ['test/*_test.js'],
},
});
// These plugins provide necessary tasks.
grunt.loadNpmTasks("grunt-contrib-jshint");
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-nodeunit");
// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-nodeunit');
// Whenever the "test" task is run, first clean the "tmp" dir, then run this
// plugin's task(s), then test the result.
grunt.registerTask('test', ['clean', 'nodeunit']);
// Whenever the "test" task is run, first clean the "tmp" dir, then run this
// plugin's task(s), then test the result.
grunt.registerTask("test", ["clean", "nodeunit"]);
// By default, lint and run all tests.
grunt.registerTask('default', ['jshint', 'test']);
};
// By default, lint and run all tests.
grunt.registerTask("default", ["jshint", "test"]);
};
/*
FIGlet.js (a FIGDriver for FIGlet fonts)
By Patrick Gillespie (patorjk@gmail.com)
Written by https://github.com/patorjk/figlet.js/graphs/contributors
Originally Written For: http://patorjk.com/software/taag/

@@ -17,86 +17,125 @@ License: MIT (with this header staying intact)

var figlet = figlet || (function() {
const figlet = (() => {
// ---------------------------------------------------------------------
// Private static variables
// ---------------------------------------------------------------------
// Private static variables
const FULL_WIDTH = 0,
FITTING = 1,
SMUSHING = 2,
CONTROLLED_SMUSHING = 3;
var FULL_WIDTH = 0,
FITTING = 1,
SMUSHING = 2,
CONTROLLED_SMUSHING = 3;
// ---------------------------------------------------------------------
// Variable that will hold information about the fonts
// ---------------------------------------------------------------------
// Variable that will hold information about the fonts
const figFonts = {}; // What stores all of the FIGlet font data
const figDefaults = {
font: "Standard",
fontPath: "./fonts",
};
var figFonts = {}; // What stores all of the FIGlet font data
var figDefaults = {
font: 'Standard',
fontPath: './fonts'
};
// ---------------------------------------------------------------------
// Private static methods
// ---------------------------------------------------------------------
// Private static methods
/*
/*
This method takes in the oldLayout and newLayout data from the FIGfont header file and returns
the layout information.
*/
function getSmushingRules(oldLayout, newLayout) {
var rules = {};
var val, index, len, code;
var codes = [[16384,"vLayout",SMUSHING], [8192,"vLayout",FITTING], [4096, "vRule5", true], [2048, "vRule4", true],
[1024, "vRule3", true], [512, "vRule2", true], [256, "vRule1", true], [128, "hLayout", SMUSHING],
[64, "hLayout", FITTING], [32, "hRule6", true], [16, "hRule5", true], [8, "hRule4", true], [4, "hRule3", true],
[2, "hRule2", true], [1, "hRule1", true]];
function getSmushingRules(oldLayout, newLayout) {
let rules = {};
let val, index, len, code;
let codes = [
[16384, "vLayout", SMUSHING],
[8192, "vLayout", FITTING],
[4096, "vRule5", true],
[2048, "vRule4", true],
[1024, "vRule3", true],
[512, "vRule2", true],
[256, "vRule1", true],
[128, "hLayout", SMUSHING],
[64, "hLayout", FITTING],
[32, "hRule6", true],
[16, "hRule5", true],
[8, "hRule4", true],
[4, "hRule3", true],
[2, "hRule2", true],
[1, "hRule1", true],
];
val = (newLayout !== null) ? newLayout : oldLayout;
index = 0;
len = codes.length;
while ( index < len ) {
code = codes[index];
if (val >= code[0]) {
val = val - code[0];
rules[code[1]] = (typeof rules[code[1]] === "undefined") ? code[2] : rules[code[1]];
} else if (code[1] !== "vLayout" && code[1] !== "hLayout") {
rules[code[1]] = false;
}
index++;
}
val = newLayout !== null ? newLayout : oldLayout;
index = 0;
len = codes.length;
while (index < len) {
code = codes[index];
if (val >= code[0]) {
val = val - code[0];
rules[code[1]] =
typeof rules[code[1]] === "undefined" ? code[2] : rules[code[1]];
} else if (code[1] !== "vLayout" && code[1] !== "hLayout") {
rules[code[1]] = false;
}
index++;
}
if (typeof rules["hLayout"] === "undefined") {
if (oldLayout === 0) {
rules["hLayout"] = FITTING;
} else if (oldLayout === -1) {
rules["hLayout"] = FULL_WIDTH;
} else {
if (rules["hRule1"] || rules["hRule2"] || rules["hRule3"] || rules["hRule4"] ||rules["hRule5"] || rules["hRule6"] ) {
rules["hLayout"] = CONTROLLED_SMUSHING;
} else {
rules["hLayout"] = SMUSHING;
}
}
} else if (rules["hLayout"] === SMUSHING) {
if (rules["hRule1"] || rules["hRule2"] || rules["hRule3"] || rules["hRule4"] ||rules["hRule5"] || rules["hRule6"] ) {
rules["hLayout"] = CONTROLLED_SMUSHING;
}
if (typeof rules["hLayout"] === "undefined") {
if (oldLayout === 0) {
rules["hLayout"] = FITTING;
} else if (oldLayout === -1) {
rules["hLayout"] = FULL_WIDTH;
} else {
if (
rules["hRule1"] ||
rules["hRule2"] ||
rules["hRule3"] ||
rules["hRule4"] ||
rules["hRule5"] ||
rules["hRule6"]
) {
rules["hLayout"] = CONTROLLED_SMUSHING;
} else {
rules["hLayout"] = SMUSHING;
}
}
} else if (rules["hLayout"] === SMUSHING) {
if (
rules["hRule1"] ||
rules["hRule2"] ||
rules["hRule3"] ||
rules["hRule4"] ||
rules["hRule5"] ||
rules["hRule6"]
) {
rules["hLayout"] = CONTROLLED_SMUSHING;
}
}
if (typeof rules["vLayout"] === "undefined") {
if (rules["vRule1"] || rules["vRule2"] || rules["vRule3"] || rules["vRule4"] ||rules["vRule5"] ) {
rules["vLayout"] = CONTROLLED_SMUSHING;
} else {
rules["vLayout"] = FULL_WIDTH;
}
} else if (rules["vLayout"] === SMUSHING) {
if (rules["vRule1"] || rules["vRule2"] || rules["vRule3"] || rules["vRule4"] ||rules["vRule5"] ) {
rules["vLayout"] = CONTROLLED_SMUSHING;
}
}
return rules;
if (typeof rules["vLayout"] === "undefined") {
if (
rules["vRule1"] ||
rules["vRule2"] ||
rules["vRule3"] ||
rules["vRule4"] ||
rules["vRule5"]
) {
rules["vLayout"] = CONTROLLED_SMUSHING;
} else {
rules["vLayout"] = FULL_WIDTH;
}
} else if (rules["vLayout"] === SMUSHING) {
if (
rules["vRule1"] ||
rules["vRule2"] ||
rules["vRule3"] ||
rules["vRule4"] ||
rules["vRule5"]
) {
rules["vLayout"] = CONTROLLED_SMUSHING;
}
}
/* The [vh]Rule[1-6]_Smush functions return the smushed character OR false if the two characters can't be smushed */
return rules;
}
/*
/* The [vh]Rule[1-6]_Smush functions return the smushed character OR false if the two characters can't be smushed */
/*
Rule 1: EQUAL CHARACTER SMUSHING (code value 1)

@@ -108,8 +147,10 @@

*/
function hRule1_Smush(ch1, ch2, hardBlank) {
if (ch1 === ch2 && ch1 !== hardBlank) {return ch1;}
return false;
function hRule1_Smush(ch1, ch2, hardBlank) {
if (ch1 === ch2 && ch1 !== hardBlank) {
return ch1;
}
return false;
}
/*
/*
Rule 2: UNDERSCORE SMUSHING (code value 2)

@@ -120,13 +161,17 @@

*/
function hRule2_Smush(ch1, ch2) {
var rule2Str = "|/\\[]{}()<>";
if (ch1 === "_") {
if (rule2Str.indexOf(ch2) !== -1) {return ch2;}
} else if (ch2 === "_") {
if (rule2Str.indexOf(ch1) !== -1) {return ch1;}
}
return false;
function hRule2_Smush(ch1, ch2) {
let rule2Str = "|/\\[]{}()<>";
if (ch1 === "_") {
if (rule2Str.indexOf(ch2) !== -1) {
return ch2;
}
} else if (ch2 === "_") {
if (rule2Str.indexOf(ch1) !== -1) {
return ch1;
}
}
return false;
}
/*
/*
Rule 3: HIERARCHY SMUSHING (code value 4)

@@ -139,15 +184,17 @@

*/
function hRule3_Smush(ch1, ch2) {
var rule3Classes = "| /\\ [] {} () <>";
var r3_pos1 = rule3Classes.indexOf(ch1);
var r3_pos2 = rule3Classes.indexOf(ch2);
if (r3_pos1 !== -1 && r3_pos2 !== -1) {
if (r3_pos1 !== r3_pos2 && Math.abs(r3_pos1-r3_pos2) !== 1) {
return rule3Classes.substr(Math.max(r3_pos1,r3_pos2), 1);
}
}
return false;
function hRule3_Smush(ch1, ch2) {
let rule3Classes = "| /\\ [] {} () <>";
let r3_pos1 = rule3Classes.indexOf(ch1);
let r3_pos2 = rule3Classes.indexOf(ch2);
if (r3_pos1 !== -1 && r3_pos2 !== -1) {
if (r3_pos1 !== r3_pos2 && Math.abs(r3_pos1 - r3_pos2) !== 1) {
const startPos = Math.max(r3_pos1, r3_pos2);
const endPos = startPos + 1;
return rule3Classes.substring(startPos, endPos);
}
}
return false;
}
/*
/*
Rule 4: OPPOSITE PAIR SMUSHING (code value 8)

@@ -159,15 +206,15 @@

*/
function hRule4_Smush(ch1, ch2) {
var rule4Str = "[] {} ()";
var r4_pos1 = rule4Str.indexOf(ch1);
var r4_pos2 = rule4Str.indexOf(ch2);
if (r4_pos1 !== -1 && r4_pos2 !== -1) {
if (Math.abs(r4_pos1-r4_pos2) <= 1) {
return "|";
}
}
return false;
function hRule4_Smush(ch1, ch2) {
let rule4Str = "[] {} ()";
let r4_pos1 = rule4Str.indexOf(ch1);
let r4_pos2 = rule4Str.indexOf(ch2);
if (r4_pos1 !== -1 && r4_pos2 !== -1) {
if (Math.abs(r4_pos1 - r4_pos2) <= 1) {
return "|";
}
}
return false;
}
/*
/*
Rule 5: BIG X SMUSHING (code value 16)

@@ -180,16 +227,16 @@

*/
function hRule5_Smush(ch1, ch2) {
var rule5Str = "/\\ \\/ ><";
var rule5Hash = {"0": "|", "3": "Y", "6": "X"};
var r5_pos1 = rule5Str.indexOf(ch1);
var r5_pos2 = rule5Str.indexOf(ch2);
if (r5_pos1 !== -1 && r5_pos2 !== -1) {
if ((r5_pos2-r5_pos1) === 1) {
return rule5Hash[r5_pos1];
}
}
return false;
function hRule5_Smush(ch1, ch2) {
let rule5Str = "/\\ \\/ ><";
let rule5Hash = { 0: "|", 3: "Y", 6: "X" };
let r5_pos1 = rule5Str.indexOf(ch1);
let r5_pos2 = rule5Str.indexOf(ch2);
if (r5_pos1 !== -1 && r5_pos2 !== -1) {
if (r5_pos2 - r5_pos1 === 1) {
return rule5Hash[r5_pos1];
}
}
return false;
}
/*
/*
Rule 6: HARDBLANK SMUSHING (code value 32)

@@ -200,10 +247,10 @@

*/
function hRule6_Smush(ch1, ch2, hardBlank) {
if (ch1 === hardBlank && ch2 === hardBlank) {
return hardBlank;
}
return false;
function hRule6_Smush(ch1, ch2, hardBlank) {
if (ch1 === hardBlank && ch2 === hardBlank) {
return hardBlank;
}
return false;
}
/*
/*
Rule 1: EQUAL CHARACTER SMUSHING (code value 256)

@@ -213,8 +260,10 @@

*/
function vRule1_Smush(ch1, ch2) {
if (ch1 === ch2) {return ch1;}
return false;
function vRule1_Smush(ch1, ch2) {
if (ch1 === ch2) {
return ch1;
}
return false;
}
/*
/*
Rule 2: UNDERSCORE SMUSHING (code value 512)

@@ -224,13 +273,17 @@

*/
function vRule2_Smush(ch1, ch2) {
var rule2Str = "|/\\[]{}()<>";
if (ch1 === "_") {
if (rule2Str.indexOf(ch2) !== -1) {return ch2;}
} else if (ch2 === "_") {
if (rule2Str.indexOf(ch1) !== -1) {return ch1;}
}
return false;
function vRule2_Smush(ch1, ch2) {
let rule2Str = "|/\\[]{}()<>";
if (ch1 === "_") {
if (rule2Str.indexOf(ch2) !== -1) {
return ch2;
}
} else if (ch2 === "_") {
if (rule2Str.indexOf(ch1) !== -1) {
return ch1;
}
}
return false;
}
/*
/*
Rule 3: HIERARCHY SMUSHING (code value 1024)

@@ -240,15 +293,17 @@

*/
function vRule3_Smush(ch1, ch2) {
var rule3Classes = "| /\\ [] {} () <>";
var r3_pos1 = rule3Classes.indexOf(ch1);
var r3_pos2 = rule3Classes.indexOf(ch2);
if (r3_pos1 !== -1 && r3_pos2 !== -1) {
if (r3_pos1 !== r3_pos2 && Math.abs(r3_pos1-r3_pos2) !== 1) {
return rule3Classes.substr(Math.max(r3_pos1,r3_pos2), 1);
}
}
return false;
function vRule3_Smush(ch1, ch2) {
let rule3Classes = "| /\\ [] {} () <>";
let r3_pos1 = rule3Classes.indexOf(ch1);
let r3_pos2 = rule3Classes.indexOf(ch2);
if (r3_pos1 !== -1 && r3_pos2 !== -1) {
if (r3_pos1 !== r3_pos2 && Math.abs(r3_pos1 - r3_pos2) !== 1) {
const startPos = Math.max(r3_pos1, r3_pos2);
const endPos = startPos + 1;
return rule3Classes.substring(startPos, endPos);
}
}
return false;
}
/*
/*
Rule 4: HORIZONTAL LINE SMUSHING (code value 2048)

@@ -263,10 +318,10 @@

*/
function vRule4_Smush(ch1, ch2) {
if ( (ch1 === "-" && ch2 === "_") || (ch1 === "_" && ch2 === "-") ) {
return "=";
}
return false;
function vRule4_Smush(ch1, ch2) {
if ((ch1 === "-" && ch2 === "_") || (ch1 === "_" && ch2 === "-")) {
return "=";
}
return false;
}
/*
/*
Rule 5: VERTICAL LINE SUPERSMUSHING (code value 4096)

@@ -285,10 +340,10 @@

*/
function vRule5_Smush(ch1, ch2) {
if ( ch1 === "|" && ch2 === "|" ) {
return "|";
}
return false;
function vRule5_Smush(ch1, ch2) {
if (ch1 === "|" && ch2 === "|") {
return "|";
}
return false;
}
/*
/*
Universal smushing simply overrides the sub-character from the

@@ -300,16 +355,16 @@ earlier FIGcharacter with the sub-character from the later

*/
function uni_Smush(ch1, ch2, hardBlank) {
if (ch2 === " " || ch2 === "") {
return ch1;
} else if (ch2 === hardBlank && ch1 !== " ") {
return ch1;
} else {
return ch2;
}
function uni_Smush(ch1, ch2, hardBlank) {
if (ch2 === " " || ch2 === "") {
return ch1;
} else if (ch2 === hardBlank && ch1 !== " ") {
return ch1;
} else {
return ch2;
}
}
// --------------------------------------------------------------------------
// main vertical smush routines (excluding rules)
// --------------------------------------------------------------------------
// main vertical smush routines (excluding rules)
/*
/*
txt1 - A line of text

@@ -324,263 +379,373 @@ txt2 - A line of text

*/
function canVerticalSmush(txt1, txt2, opts) {
if (opts.fittingRules.vLayout === FULL_WIDTH) {return "invalid";}
var ii, len = Math.min(txt1.length, txt2.length);
var ch1, ch2, endSmush = false, validSmush;
if (len===0) {return "invalid";}
function canVerticalSmush(txt1, txt2, opts) {
if (opts.fittingRules.vLayout === FULL_WIDTH) {
return "invalid";
}
let ii,
len = Math.min(txt1.length, txt2.length),
ch1,
ch2,
endSmush = false,
validSmush;
if (len === 0) {
return "invalid";
}
for (ii = 0; ii < len; ii++) {
ch1 = txt1.substr(ii,1);
ch2 = txt2.substr(ii,1);
if (ch1 !== " " && ch2 !== " ") {
if (opts.fittingRules.vLayout === FITTING) {
return "invalid";
} else if (opts.fittingRules.vLayout === SMUSHING) {
return "end";
} else {
if (vRule5_Smush(ch1,ch2)) {endSmush = endSmush || false; continue;} // rule 5 allow for "super" smushing, but only if we're not already ending this smush
validSmush = false;
validSmush = (opts.fittingRules.vRule1) ? vRule1_Smush(ch1,ch2) : validSmush;
validSmush = (!validSmush && opts.fittingRules.vRule2) ? vRule2_Smush(ch1,ch2) : validSmush;
validSmush = (!validSmush && opts.fittingRules.vRule3) ? vRule3_Smush(ch1,ch2) : validSmush;
validSmush = (!validSmush && opts.fittingRules.vRule4) ? vRule4_Smush(ch1,ch2) : validSmush;
endSmush = true;
if (!validSmush) {return "invalid";}
}
}
}
if (endSmush) {
return "end";
for (ii = 0; ii < len; ii++) {
ch1 = txt1.substring(ii, ii + 1);
ch2 = txt2.substring(ii, ii + 1);
if (ch1 !== " " && ch2 !== " ") {
if (opts.fittingRules.vLayout === FITTING) {
return "invalid";
} else if (opts.fittingRules.vLayout === SMUSHING) {
return "end";
} else {
return "valid";
if (vRule5_Smush(ch1, ch2)) {
endSmush = endSmush || false;
continue;
} // rule 5 allow for "super" smushing, but only if we're not already ending this smush
validSmush = false;
validSmush = opts.fittingRules.vRule1
? vRule1_Smush(ch1, ch2)
: validSmush;
validSmush =
!validSmush && opts.fittingRules.vRule2
? vRule2_Smush(ch1, ch2)
: validSmush;
validSmush =
!validSmush && opts.fittingRules.vRule3
? vRule3_Smush(ch1, ch2)
: validSmush;
validSmush =
!validSmush && opts.fittingRules.vRule4
? vRule4_Smush(ch1, ch2)
: validSmush;
endSmush = true;
if (!validSmush) {
return "invalid";
}
}
}
}
if (endSmush) {
return "end";
} else {
return "valid";
}
}
function getVerticalSmushDist(lines1, lines2, opts) {
var maxDist = lines1.length;
var len1 = lines1.length;
var len2 = lines2.length;
var subLines1, subLines2, slen;
var curDist = 1;
var ii, ret, result;
while (curDist <= maxDist) {
function getVerticalSmushDist(lines1, lines2, opts) {
let maxDist = lines1.length;
let len1 = lines1.length;
let len2 = lines2.length;
let subLines1, subLines2, slen;
let curDist = 1;
let ii, ret, result;
while (curDist <= maxDist) {
subLines1 = lines1.slice(Math.max(0, len1 - curDist), len1);
subLines2 = lines2.slice(0, Math.min(maxDist, curDist));
subLines1 = lines1.slice(Math.max(0,len1-curDist), len1);
subLines2 = lines2.slice(0, Math.min(maxDist, curDist));
slen = subLines2.length;//TODO:check this
result = "";
for (ii = 0; ii < slen; ii++) {
ret = canVerticalSmush(subLines1[ii], subLines2[ii], opts);
if (ret === "end") {
result = ret;
} else if (ret === "invalid") {
result = ret;
break;
} else {
if (result === "") {
result = "valid";
}
}
}
if (result === "invalid") {curDist--;break;}
if (result === "end") {break;}
if (result === "valid") {curDist++;}
slen = subLines2.length; //TODO:check this
result = "";
for (ii = 0; ii < slen; ii++) {
ret = canVerticalSmush(subLines1[ii], subLines2[ii], opts);
if (ret === "end") {
result = ret;
} else if (ret === "invalid") {
result = ret;
break;
} else {
if (result === "") {
result = "valid";
}
}
}
return Math.min(maxDist,curDist);
if (result === "invalid") {
curDist--;
break;
}
if (result === "end") {
break;
}
if (result === "valid") {
curDist++;
}
}
function verticallySmushLines(line1, line2, opts) {
var ii, len = Math.min(line1.length, line2.length);
var ch1, ch2, result = "", validSmush;
return Math.min(maxDist, curDist);
}
for (ii = 0; ii < len; ii++) {
ch1 = line1.substr(ii,1);
ch2 = line2.substr(ii,1);
if (ch1 !== " " && ch2 !== " ") {
if (opts.fittingRules.vLayout === FITTING) {
result += uni_Smush(ch1,ch2);
} else if (opts.fittingRules.vLayout === SMUSHING) {
result += uni_Smush(ch1,ch2);
} else {
validSmush = false;
validSmush = (opts.fittingRules.vRule5) ? vRule5_Smush(ch1,ch2) : validSmush;
validSmush = (!validSmush && opts.fittingRules.vRule1) ? vRule1_Smush(ch1,ch2) : validSmush;
validSmush = (!validSmush && opts.fittingRules.vRule2) ? vRule2_Smush(ch1,ch2) : validSmush;
validSmush = (!validSmush && opts.fittingRules.vRule3) ? vRule3_Smush(ch1,ch2) : validSmush;
validSmush = (!validSmush && opts.fittingRules.vRule4) ? vRule4_Smush(ch1,ch2) : validSmush;
result += validSmush;
}
} else {
result += uni_Smush(ch1,ch2);
}
function verticallySmushLines(line1, line2, opts) {
let ii,
len = Math.min(line1.length, line2.length);
let ch1,
ch2,
result = "",
validSmush;
for (ii = 0; ii < len; ii++) {
ch1 = line1.substring(ii, ii + 1);
ch2 = line2.substring(ii, ii + 1);
if (ch1 !== " " && ch2 !== " ") {
if (opts.fittingRules.vLayout === FITTING) {
result += uni_Smush(ch1, ch2);
} else if (opts.fittingRules.vLayout === SMUSHING) {
result += uni_Smush(ch1, ch2);
} else {
validSmush = false;
validSmush = opts.fittingRules.vRule5
? vRule5_Smush(ch1, ch2)
: validSmush;
validSmush =
!validSmush && opts.fittingRules.vRule1
? vRule1_Smush(ch1, ch2)
: validSmush;
validSmush =
!validSmush && opts.fittingRules.vRule2
? vRule2_Smush(ch1, ch2)
: validSmush;
validSmush =
!validSmush && opts.fittingRules.vRule3
? vRule3_Smush(ch1, ch2)
: validSmush;
validSmush =
!validSmush && opts.fittingRules.vRule4
? vRule4_Smush(ch1, ch2)
: validSmush;
result += validSmush;
}
return result;
} else {
result += uni_Smush(ch1, ch2);
}
}
return result;
}
function verticalSmush(lines1, lines2, overlap, opts) {
var len1 = lines1.length;
var len2 = lines2.length;
var piece1 = lines1.slice(0, Math.max(0,len1-overlap));
var piece2_1 = lines1.slice(Math.max(0,len1-overlap), len1);
var piece2_2 = lines2.slice(0, Math.min(overlap, len2));
var ii, len, line, piece2 = [], piece3, result = [];
function verticalSmush(lines1, lines2, overlap, opts) {
let len1 = lines1.length;
let len2 = lines2.length;
let piece1 = lines1.slice(0, Math.max(0, len1 - overlap));
let piece2_1 = lines1.slice(Math.max(0, len1 - overlap), len1);
let piece2_2 = lines2.slice(0, Math.min(overlap, len2));
let ii,
len,
line,
piece2 = [],
piece3,
result = [];
len = piece2_1.length;
for (ii = 0; ii < len; ii++) {
if (ii >= len2) {
line = piece2_1[ii];
} else {
line = verticallySmushLines(piece2_1[ii], piece2_2[ii], opts);
}
piece2.push(line);
}
len = piece2_1.length;
for (ii = 0; ii < len; ii++) {
if (ii >= len2) {
line = piece2_1[ii];
} else {
line = verticallySmushLines(piece2_1[ii], piece2_2[ii], opts);
}
piece2.push(line);
}
piece3 = lines2.slice(Math.min(overlap,len2), len2);
piece3 = lines2.slice(Math.min(overlap, len2), len2);
return result.concat(piece1,piece2,piece3);
}
return result.concat(piece1, piece2, piece3);
}
function padLines(lines, numSpaces) {
var ii, len = lines.length, padding = "";
for (ii = 0; ii < numSpaces; ii++) {
padding += " ";
}
for (ii = 0; ii < len; ii++) {
lines[ii] += padding;
}
function padLines(lines, numSpaces) {
let ii,
len = lines.length,
padding = "";
for (ii = 0; ii < numSpaces; ii++) {
padding += " ";
}
for (ii = 0; ii < len; ii++) {
lines[ii] += padding;
}
}
function smushVerticalFigLines(output, lines, opts) {
var len1 = output[0].length;
var len2 = lines[0].length;
var overlap;
if (len1 > len2) {
padLines(lines, len1-len2);
} else if (len2 > len1) {
padLines(output, len2-len1);
}
overlap = getVerticalSmushDist(output, lines, opts);
return verticalSmush(output, lines, overlap,opts);
function smushVerticalFigLines(output, lines, opts) {
let len1 = output[0].length;
let len2 = lines[0].length;
let overlap;
if (len1 > len2) {
padLines(lines, len1 - len2);
} else if (len2 > len1) {
padLines(output, len2 - len1);
}
overlap = getVerticalSmushDist(output, lines, opts);
return verticalSmush(output, lines, overlap, opts);
}
// -------------------------------------------------------------------------
// Main horizontal smush routines (excluding rules)
// -------------------------------------------------------------------------
// Main horizontal smush routines (excluding rules)
function getHorizontalSmushLength(txt1, txt2, opts) {
if (opts.fittingRules.hLayout === FULL_WIDTH) {return 0;}
var ii, len1 = txt1.length, len2 = txt2.length;
var maxDist = len1;
var curDist = 1;
var breakAfter = false;
var validSmush = false;
var seg1, seg2, ch1, ch2;
if (len1 === 0) {return 0;}
function getHorizontalSmushLength(txt1, txt2, opts) {
if (opts.fittingRules.hLayout === FULL_WIDTH) {
return 0;
}
let ii,
len1 = txt1.length,
len2 = txt2.length;
let maxDist = len1;
let curDist = 1;
let breakAfter = false;
let validSmush = false;
let seg1, seg2, ch1, ch2;
if (len1 === 0) {
return 0;
}
distCal: while (curDist <= maxDist) {
seg1 = txt1.substr(len1-curDist,curDist);
seg2 = txt2.substr(0,Math.min(curDist,len2));
for (ii = 0; ii < Math.min(curDist,len2); ii++) {
ch1 = seg1.substr(ii,1);
ch2 = seg2.substr(ii,1);
if (ch1 !== " " && ch2 !== " " ) {
if (opts.fittingRules.hLayout === FITTING) {
curDist = curDist - 1;
break distCal;
} else if (opts.fittingRules.hLayout === SMUSHING) {
if (ch1 === opts.hardBlank || ch2 === opts.hardBlank) {
curDist = curDist - 1; // universal smushing does not smush hardblanks
}
break distCal;
} else {
breakAfter = true; // we know we need to break, but we need to check if our smushing rules will allow us to smush the overlapped characters
validSmush = false; // the below checks will let us know if we can smush these characters
distCal: while (curDist <= maxDist) {
const seg1StartPos = len1 - curDist;
seg1 = txt1.substring(seg1StartPos, seg1StartPos + curDist);
seg2 = txt2.substring(0, Math.min(curDist, len2));
for (ii = 0; ii < Math.min(curDist, len2); ii++) {
ch1 = seg1.substring(ii, ii + 1);
ch2 = seg2.substring(ii, ii + 1);
if (ch1 !== " " && ch2 !== " ") {
if (opts.fittingRules.hLayout === FITTING) {
curDist = curDist - 1;
break distCal;
} else if (opts.fittingRules.hLayout === SMUSHING) {
if (ch1 === opts.hardBlank || ch2 === opts.hardBlank) {
curDist = curDist - 1; // universal smushing does not smush hardblanks
}
break distCal;
} else {
breakAfter = true; // we know we need to break, but we need to check if our smushing rules will allow us to smush the overlapped characters
validSmush = false; // the below checks will let us know if we can smush these characters
validSmush = (opts.fittingRules.hRule1) ? hRule1_Smush(ch1,ch2,opts.hardBlank) : validSmush;
validSmush = (!validSmush && opts.fittingRules.hRule2) ? hRule2_Smush(ch1,ch2,opts.hardBlank) : validSmush;
validSmush = (!validSmush && opts.fittingRules.hRule3) ? hRule3_Smush(ch1,ch2,opts.hardBlank) : validSmush;
validSmush = (!validSmush && opts.fittingRules.hRule4) ? hRule4_Smush(ch1,ch2,opts.hardBlank) : validSmush;
validSmush = (!validSmush && opts.fittingRules.hRule5) ? hRule5_Smush(ch1,ch2,opts.hardBlank) : validSmush;
validSmush = (!validSmush && opts.fittingRules.hRule6) ? hRule6_Smush(ch1,ch2,opts.hardBlank) : validSmush;
validSmush = opts.fittingRules.hRule1
? hRule1_Smush(ch1, ch2, opts.hardBlank)
: validSmush;
validSmush =
!validSmush && opts.fittingRules.hRule2
? hRule2_Smush(ch1, ch2, opts.hardBlank)
: validSmush;
validSmush =
!validSmush && opts.fittingRules.hRule3
? hRule3_Smush(ch1, ch2, opts.hardBlank)
: validSmush;
validSmush =
!validSmush && opts.fittingRules.hRule4
? hRule4_Smush(ch1, ch2, opts.hardBlank)
: validSmush;
validSmush =
!validSmush && opts.fittingRules.hRule5
? hRule5_Smush(ch1, ch2, opts.hardBlank)
: validSmush;
validSmush =
!validSmush && opts.fittingRules.hRule6
? hRule6_Smush(ch1, ch2, opts.hardBlank)
: validSmush;
if (!validSmush) {
curDist = curDist - 1;
break distCal;
}
}
}
if (!validSmush) {
curDist = curDist - 1;
break distCal;
}
if (breakAfter) {break;}
curDist++;
}
}
return Math.min(maxDist,curDist);
}
if (breakAfter) {
break;
}
curDist++;
}
return Math.min(maxDist, curDist);
}
function horizontalSmush(textBlock1, textBlock2, overlap, opts) {
var ii, jj, ch, outputFig = [],
overlapStart,piece1,piece2,piece3,len1,len2,txt1,txt2;
function horizontalSmush(textBlock1, textBlock2, overlap, opts) {
let ii,
jj,
outputFig = [],
overlapStart,
piece1,
piece2,
piece3,
len1,
len2,
txt1,
txt2;
for (ii = 0; ii < opts.height; ii++) {
txt1 = textBlock1[ii];
txt2 = textBlock2[ii];
len1 = txt1.length;
len2 = txt2.length;
overlapStart = len1-overlap;
piece1 = txt1.substr(0,Math.max(0,overlapStart));
piece2 = "";
for (ii = 0; ii < opts.height; ii++) {
txt1 = textBlock1[ii];
txt2 = textBlock2[ii];
len1 = txt1.length;
len2 = txt2.length;
overlapStart = len1 - overlap;
piece1 = txt1.substr(0, Math.max(0, overlapStart));
piece2 = "";
// determine overlap piece
var seg1 = txt1.substr(Math.max(0,len1-overlap),overlap);
var seg2 = txt2.substr(0,Math.min(overlap,len2));
// determine overlap piece
const seg1StartPos = Math.max(0, len1 - overlap);
var seg1 = txt1.substring(seg1StartPos, seg1StartPos + overlap);
var seg2 = txt2.substring(0, Math.min(overlap, len2));
for (jj = 0; jj < overlap; jj++) {
var ch1 = (jj < len1) ? seg1.substr(jj,1) : " ";
var ch2 = (jj < len2) ? seg2.substr(jj,1) : " ";
for (jj = 0; jj < overlap; jj++) {
var ch1 = jj < len1 ? seg1.substring(jj, jj + 1) : " ";
var ch2 = jj < len2 ? seg2.substring(jj, jj + 1) : " ";
if (ch1 !== " " && ch2 !== " ") {
if (opts.fittingRules.hLayout === FITTING) {
piece2 += uni_Smush(ch1, ch2, opts.hardBlank);
} else if (opts.fittingRules.hLayout === SMUSHING) {
piece2 += uni_Smush(ch1, ch2, opts.hardBlank);
} else {
// Controlled Smushing
var nextCh = "";
nextCh = (!nextCh && opts.fittingRules.hRule1) ? hRule1_Smush(ch1,ch2,opts.hardBlank) : nextCh;
nextCh = (!nextCh && opts.fittingRules.hRule2) ? hRule2_Smush(ch1,ch2,opts.hardBlank) : nextCh;
nextCh = (!nextCh && opts.fittingRules.hRule3) ? hRule3_Smush(ch1,ch2,opts.hardBlank) : nextCh;
nextCh = (!nextCh && opts.fittingRules.hRule4) ? hRule4_Smush(ch1,ch2,opts.hardBlank) : nextCh;
nextCh = (!nextCh && opts.fittingRules.hRule5) ? hRule5_Smush(ch1,ch2,opts.hardBlank) : nextCh;
nextCh = (!nextCh && opts.fittingRules.hRule6) ? hRule6_Smush(ch1,ch2,opts.hardBlank) : nextCh;
nextCh = nextCh || uni_Smush(ch1, ch2, opts.hardBlank);
piece2 += nextCh;
}
} else {
piece2 += uni_Smush(ch1, ch2, opts.hardBlank);
}
}
if (ch1 !== " " && ch2 !== " ") {
if (opts.fittingRules.hLayout === FITTING) {
piece2 += uni_Smush(ch1, ch2, opts.hardBlank);
} else if (opts.fittingRules.hLayout === SMUSHING) {
piece2 += uni_Smush(ch1, ch2, opts.hardBlank);
} else {
// Controlled Smushing
var nextCh = "";
nextCh =
!nextCh && opts.fittingRules.hRule1
? hRule1_Smush(ch1, ch2, opts.hardBlank)
: nextCh;
nextCh =
!nextCh && opts.fittingRules.hRule2
? hRule2_Smush(ch1, ch2, opts.hardBlank)
: nextCh;
nextCh =
!nextCh && opts.fittingRules.hRule3
? hRule3_Smush(ch1, ch2, opts.hardBlank)
: nextCh;
nextCh =
!nextCh && opts.fittingRules.hRule4
? hRule4_Smush(ch1, ch2, opts.hardBlank)
: nextCh;
nextCh =
!nextCh && opts.fittingRules.hRule5
? hRule5_Smush(ch1, ch2, opts.hardBlank)
: nextCh;
nextCh =
!nextCh && opts.fittingRules.hRule6
? hRule6_Smush(ch1, ch2, opts.hardBlank)
: nextCh;
nextCh = nextCh || uni_Smush(ch1, ch2, opts.hardBlank);
piece2 += nextCh;
}
} else {
piece2 += uni_Smush(ch1, ch2, opts.hardBlank);
}
}
if (overlap >= len2) {
piece3 = "";
} else {
piece3 = txt2.substr(overlap,Math.max(0,len2-overlap));
}
outputFig[ii] = piece1 + piece2 + piece3;
}
return outputFig;
if (overlap >= len2) {
piece3 = "";
} else {
piece3 = txt2.substring(overlap, overlap + Math.max(0, len2 - overlap));
}
outputFig[ii] = piece1 + piece2 + piece3;
}
return outputFig;
}
/*
/*
Creates new empty ASCII placeholder of give len
- len - number
*/
function newFigChar(len) {
var outputFigText = [], row;
for (row = 0; row < len; row++) {
outputFigText[row] = "";
}
return outputFigText;
function newFigChar(len) {
let outputFigText = [],
row;
for (row = 0; row < len; row++) {
outputFigText[row] = "";
}
return outputFigText;
}
/*
/*
Return max line of the ASCII Art

@@ -590,9 +755,12 @@ - text is array of lines for text

*/
var figLinesWidth = function(textLines) {
return Math.max.apply(Math, textLines.map(function(line, i) {
return line.length;
}));
};
const figLinesWidth = function (textLines) {
return Math.max.apply(
Math,
textLines.map(function (line, i) {
return line.length;
})
);
};
/*
/*
join words or single characaters into single Fig line

@@ -603,9 +771,9 @@ - array - array of ASCII words or single characters: {fig: array, overlap: number}

*/
function joinFigArray(array, len, opts) {
return array.reduce(function(acc, data) {
return horizontalSmush(acc, data.fig, data.overlap, opts);
}, newFigChar(len));
}
function joinFigArray(array, len, opts) {
return array.reduce(function (acc, data) {
return horizontalSmush(acc, data.fig, data.overlap, opts);
}, newFigChar(len));
}
/*
/*
break long word return leftover characters and line before the break

@@ -616,187 +784,297 @@ - figChars - list of single ASCII characters in form {fig, overlap}

*/
function breakWord(figChars, len, opts) {
var result = {};
for (var i = figChars.length; --i;) {
var w = joinFigArray(figChars.slice(0, i), len, opts);
if (figLinesWidth(w) <= opts.width) {
result.outputFigText = w;
if (i < figChars.length) {
result.chars = figChars.slice(i);
} else {
result.chars = [];
}
break;
}
function breakWord(figChars, len, opts) {
const result = {};
for (let i = figChars.length; --i; ) {
let w = joinFigArray(figChars.slice(0, i), len, opts);
if (figLinesWidth(w) <= opts.width) {
result.outputFigText = w;
if (i < figChars.length) {
result.chars = figChars.slice(i);
} else {
result.chars = [];
}
return result;
break;
}
}
return result;
}
function generateFigTextLines(txt, figChars, opts) {
var charIndex, figChar, spaceIndex, overlap = 0, row, outputFigText, len, height=opts.height, outputFigLines = [], maxWidth, prevWidth, nextFigChars, figWords = [], char, isSpace, textFigWord, textFigLine, tmpBreak;
function generateFigTextLines(txt, figChars, opts) {
let charIndex,
figChar,
overlap = 0,
row,
outputFigText,
len,
height = opts.height,
outputFigLines = [],
maxWidth,
nextFigChars,
figWords = [],
char,
isSpace,
textFigWord,
textFigLine,
tmpBreak;
outputFigText = newFigChar(height);
outputFigText = newFigChar(height);
if (opts.width > 0 && opts.whitespaceBreak) {
// list of characters is used to break in the middle of the word when word is logner
// chars is array of characters with {fig, overlap} and overlap is for whole word
nextFigChars = {
chars: [],
overlap: overlap,
};
}
if (opts.printDirection === 1) {
txt = txt.split("").reverse().join("");
}
len = txt.length;
for (charIndex = 0; charIndex < len; charIndex++) {
char = txt.substring(charIndex, charIndex + 1);
isSpace = char.match(/\s/);
figChar = figChars[char.charCodeAt(0)];
textFigLine = null;
if (figChar) {
if (opts.fittingRules.hLayout !== FULL_WIDTH) {
overlap = 10000; // a value too high to be the overlap
for (row = 0; row < opts.height; row++) {
overlap = Math.min(
overlap,
getHorizontalSmushLength(outputFigText[row], figChar[row], opts)
);
}
overlap = overlap === 10000 ? 0 : overlap;
}
if (opts.width > 0) {
if (opts.whitespaceBreak) {
// next character in last word (figChars have same data as words)
textFigWord = joinFigArray(
nextFigChars.chars.concat([
{
fig: figChar,
overlap: overlap,
},
]),
height,
opts
);
textFigLine = joinFigArray(
figWords.concat([
{
fig: textFigWord,
overlap: nextFigChars.overlap,
},
]),
height,
opts
);
maxWidth = figLinesWidth(textFigLine);
} else {
textFigLine = horizontalSmush(
outputFigText,
figChar,
overlap,
opts
);
maxWidth = figLinesWidth(textFigLine);
}
if (maxWidth >= opts.width && charIndex > 0) {
if (opts.whitespaceBreak) {
outputFigText = joinFigArray(figWords.slice(0, -1), height, opts);
if (figWords.length > 1) {
outputFigLines.push(outputFigText);
outputFigText = newFigChar(height);
}
figWords = [];
} else {
outputFigLines.push(outputFigText);
outputFigText = newFigChar(height);
}
}
}
if (opts.width > 0 && opts.whitespaceBreak) {
// list of characters is used to break in the middle of the word when word is logner
// chars is array of characters with {fig, overlap} and overlap is for whole word
if (!isSpace || charIndex === len - 1) {
nextFigChars.chars.push({ fig: figChar, overlap: overlap });
}
if (isSpace || charIndex === len - 1) {
// break long words
tmpBreak = null;
while (true) {
textFigLine = joinFigArray(nextFigChars.chars, height, opts);
maxWidth = figLinesWidth(textFigLine);
if (maxWidth >= opts.width) {
tmpBreak = breakWord(nextFigChars.chars, height, opts);
nextFigChars = { chars: tmpBreak.chars };
outputFigLines.push(tmpBreak.outputFigText);
} else {
break;
}
}
// any leftovers
if (maxWidth > 0) {
if (tmpBreak) {
figWords.push({ fig: textFigLine, overlap: 1 });
} else {
figWords.push({
fig: textFigLine,
overlap: nextFigChars.overlap,
});
}
}
// save space character and current overlap for smush in joinFigWords
if (isSpace) {
figWords.push({ fig: figChar, overlap: overlap });
outputFigText = newFigChar(height);
}
if (charIndex === len - 1) {
// last line
outputFigText = joinFigArray(figWords, height, opts);
}
nextFigChars = {
chars: [],
overlap: overlap
chars: [],
overlap: overlap,
};
continue;
}
}
if (opts.printDirection === 1) {
txt = txt.split('').reverse().join('');
outputFigText = horizontalSmush(outputFigText, figChar, overlap, opts);
}
}
// special case when last line would be empty
// this may happen if text fit exactly opt.width
if (figLinesWidth(outputFigText) > 0) {
outputFigLines.push(outputFigText);
}
// remove hardblanks
if (opts.showHardBlanks !== true) {
outputFigLines.forEach(function (outputFigText) {
len = outputFigText.length;
for (row = 0; row < len; row++) {
outputFigText[row] = outputFigText[row].replace(
new RegExp("\\" + opts.hardBlank, "g"),
" "
);
}
len = txt.length;
for (charIndex = 0; charIndex < len; charIndex++) {
char = txt.substr(charIndex, 1);
isSpace = char.match(/\s/);
figChar = figChars[char.charCodeAt(0)];
textFigLine = null;
if (figChar) {
if (opts.fittingRules.hLayout !== FULL_WIDTH) {
overlap = 10000;// a value too high to be the overlap
for (row = 0; row < opts.height; row++) {
overlap = Math.min(overlap, getHorizontalSmushLength(outputFigText[row], figChar[row], opts));
}
overlap = (overlap === 10000) ? 0 : overlap;
}
if (opts.width > 0) {
if (opts.whitespaceBreak) {
// next character in last word (figChars have same data as words)
textFigWord = joinFigArray(nextFigChars.chars.concat([{
fig: figChar, overlap: overlap
}]), height, opts);
textFigLine = joinFigArray(figWords.concat([{
fig: textFigWord, overlap: nextFigChars.overlap
}]), height, opts);
maxWidth = figLinesWidth(textFigLine);
} else {
textFigLine = horizontalSmush(outputFigText, figChar, overlap, opts);
maxWidth = figLinesWidth(textFigLine);
}
if (maxWidth >= opts.width && charIndex > 0) {
if (opts.whitespaceBreak) {
outputFigText = joinFigArray(figWords.slice(0, -1), height, opts);
if (figWords.length > 1) {
outputFigLines.push(outputFigText);
outputFigText = newFigChar(height);
}
figWords = [];
} else {
outputFigLines.push(outputFigText);
outputFigText = newFigChar(height);
}
}
}
if (opts.width > 0 && opts.whitespaceBreak) {
if (!isSpace || charIndex === len - 1) {
nextFigChars.chars.push({fig: figChar, overlap: overlap});
}
if (isSpace || charIndex === len - 1) {
// break long words
tmpBreak = null;
while (true) {
textFigLine = joinFigArray(nextFigChars.chars, height, opts);
maxWidth = figLinesWidth(textFigLine);
if (maxWidth >= opts.width) {
tmpBreak = breakWord(nextFigChars.chars, height, opts);
nextFigChars = { chars: tmpBreak.chars };
outputFigLines.push(tmpBreak.outputFigText);
} else {
break;
}
}
// any leftovers
if (maxWidth > 0) {
if (tmpBreak) {
figWords.push({fig: textFigLine, overlap: 1});
} else {
figWords.push({
fig: textFigLine,
overlap: nextFigChars.overlap
});
}
}
// save space character and current overlap for smush in joinFigWords
if (isSpace) {
figWords.push({fig: figChar, overlap: overlap});
outputFigText = newFigChar(height);
}
if (charIndex === len - 1) {
// last line
outputFigText = joinFigArray(figWords, height, opts);
}
nextFigChars = {
chars: [],
overlap: overlap
};
continue;
}
}
outputFigText = horizontalSmush(outputFigText, figChar, overlap, opts);
}
}
// special case when last line would be empty
// this may happen if text fit exactly opt.width
if (figLinesWidth(outputFigText) > 0) {
outputFigLines.push(outputFigText);
}
// remove hardblanks
if (opts.showHardBlanks !== true) {
outputFigLines.forEach(function(outputFigText) {
len = outputFigText.length;
for (row = 0; row < len; row++) {
outputFigText[row] = outputFigText[row].replace(new RegExp("\\"+opts.hardBlank,"g")," ");
}
});
}
return outputFigLines;
});
}
return outputFigLines;
}
// -------------------------------------------------------------------------
// Parsing and Generation methods
// -------------------------------------------------------------------------
// Parsing and Generation methods
var getHorizontalFittingRules = function(layout, options) {
var props = ["hLayout", "hRule1","hRule2","hRule3","hRule4","hRule5","hRule6"],
params = {}, prop, ii;
if (layout === "default") {
for (ii = 0; ii < props.length; ii++) {
params[props[ii]] = options.fittingRules[props[ii]];
}
} else if (layout === "full") {
params = {"hLayout": FULL_WIDTH,"hRule1":false,"hRule2":false,"hRule3":false,"hRule4":false,"hRule5":false,"hRule6":false};
} else if (layout === "fitted") {
params = {"hLayout": FITTING,"hRule1":false,"hRule2":false,"hRule3":false,"hRule4":false,"hRule5":false,"hRule6":false};
} else if (layout === "controlled smushing") {
params = {"hLayout": CONTROLLED_SMUSHING,"hRule1":true,"hRule2":true,"hRule3":true,"hRule4":true,"hRule5":true,"hRule6":true};
} else if (layout === "universal smushing") {
params = {"hLayout": SMUSHING,"hRule1":false,"hRule2":false,"hRule3":false,"hRule4":false,"hRule5":false,"hRule6":false};
} else {
return;
}
return params;
};
const getHorizontalFittingRules = function (layout, options) {
let props = [
"hLayout",
"hRule1",
"hRule2",
"hRule3",
"hRule4",
"hRule5",
"hRule6",
],
params = {},
ii;
if (layout === "default") {
for (ii = 0; ii < props.length; ii++) {
params[props[ii]] = options.fittingRules[props[ii]];
}
} else if (layout === "full") {
params = {
hLayout: FULL_WIDTH,
hRule1: false,
hRule2: false,
hRule3: false,
hRule4: false,
hRule5: false,
hRule6: false,
};
} else if (layout === "fitted") {
params = {
hLayout: FITTING,
hRule1: false,
hRule2: false,
hRule3: false,
hRule4: false,
hRule5: false,
hRule6: false,
};
} else if (layout === "controlled smushing") {
params = {
hLayout: CONTROLLED_SMUSHING,
hRule1: true,
hRule2: true,
hRule3: true,
hRule4: true,
hRule5: true,
hRule6: true,
};
} else if (layout === "universal smushing") {
params = {
hLayout: SMUSHING,
hRule1: false,
hRule2: false,
hRule3: false,
hRule4: false,
hRule5: false,
hRule6: false,
};
} else {
return;
}
return params;
};
var getVerticalFittingRules = function(layout, options) {
var props = ["vLayout", "vRule1","vRule2","vRule3","vRule4","vRule5"],
params = {}, prop, ii;
if (layout === "default") {
for (ii = 0; ii < props.length; ii++) {
params[props[ii]] = options.fittingRules[props[ii]];
}
} else if (layout === "full") {
params = {"vLayout": FULL_WIDTH,"vRule1":false,"vRule2":false,"vRule3":false,"vRule4":false,"vRule5":false};
} else if (layout === "fitted") {
params = {"vLayout": FITTING,"vRule1":false,"vRule2":false,"vRule3":false,"vRule4":false,"vRule5":false};
} else if (layout === "controlled smushing") {
params = {"vLayout": CONTROLLED_SMUSHING,"vRule1":true,"vRule2":true,"vRule3":true,"vRule4":true,"vRule5":true};
} else if (layout === "universal smushing") {
params = {"vLayout": SMUSHING,"vRule1":false,"vRule2":false,"vRule3":false,"vRule4":false,"vRule5":false};
} else {
return;
}
return params;
};
const getVerticalFittingRules = function (layout, options) {
let props = ["vLayout", "vRule1", "vRule2", "vRule3", "vRule4", "vRule5"],
params = {},
ii;
if (layout === "default") {
for (ii = 0; ii < props.length; ii++) {
params[props[ii]] = options.fittingRules[props[ii]];
}
} else if (layout === "full") {
params = {
vLayout: FULL_WIDTH,
vRule1: false,
vRule2: false,
vRule3: false,
vRule4: false,
vRule5: false,
};
} else if (layout === "fitted") {
params = {
vLayout: FITTING,
vRule1: false,
vRule2: false,
vRule3: false,
vRule4: false,
vRule5: false,
};
} else if (layout === "controlled smushing") {
params = {
vLayout: CONTROLLED_SMUSHING,
vRule1: true,
vRule2: true,
vRule3: true,
vRule4: true,
vRule5: true,
};
} else if (layout === "universal smushing") {
params = {
vLayout: SMUSHING,
vRule1: false,
vRule2: false,
vRule3: false,
vRule4: false,
vRule5: false,
};
} else {
return;
}
return params;
};
/*
/*
Generates the ASCII Art

@@ -807,60 +1085,65 @@ - fontName: Font to use

*/
var generateText = function(fontName, options, txt) {
txt = txt.replace(/\r\n/g,"\n").replace(/\r/g,"\n");
var lines = txt.split("\n");
var figLines = [];
var ii, len, output;
len = lines.length;
for (ii = 0; ii < len; ii++) {
figLines = figLines.concat( generateFigTextLines(lines[ii], figFonts[fontName], options) );
}
len = figLines.length;
output = figLines[0];
for (ii = 1; ii < len; ii++) {
output = smushVerticalFigLines(output, figLines[ii], options);
}
const generateText = function (fontName, options, txt) {
txt = txt.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
let lines = txt.split("\n");
let figLines = [];
let ii, len, output;
len = lines.length;
for (ii = 0; ii < len; ii++) {
figLines = figLines.concat(
generateFigTextLines(lines[ii], figFonts[fontName], options)
);
}
len = figLines.length;
output = figLines[0];
for (ii = 1; ii < len; ii++) {
output = smushVerticalFigLines(output, figLines[ii], options);
}
return output ? output.join("\n") : '';
};
return output ? output.join("\n") : "";
};
/*
/*
takes assigned options and merges them with the default options from the choosen font
*/
function _reworkFontOpts(fontOpts, options) {
var myOpts = JSON.parse(JSON.stringify(fontOpts)), // make a copy because we may edit this (see below)
params,
prop;
function _reworkFontOpts(fontOpts, options) {
let myOpts = JSON.parse(JSON.stringify(fontOpts)), // make a copy because we may edit this (see below)
params,
prop;
/*
/*
If the user is chosing to use a specific type of layout (e.g., 'full', 'fitted', etc etc)
Then we need to override the default font options.
*/
if (typeof options.horizontalLayout !== 'undefined') {
params = getHorizontalFittingRules(options.horizontalLayout, fontOpts);
for (prop in params) {
if (params.hasOwnProperty(prop)) {
myOpts.fittingRules[prop] = params[prop];
}
}
if (typeof options.horizontalLayout !== "undefined") {
params = getHorizontalFittingRules(options.horizontalLayout, fontOpts);
for (prop in params) {
if (params.hasOwnProperty(prop)) {
myOpts.fittingRules[prop] = params[prop];
}
if (typeof options.verticalLayout !== 'undefined') {
params = getVerticalFittingRules(options.verticalLayout, fontOpts);
for (prop in params) {
if (params.hasOwnProperty(prop)) {
myOpts.fittingRules[prop] = params[prop];
}
}
}
}
if (typeof options.verticalLayout !== "undefined") {
params = getVerticalFittingRules(options.verticalLayout, fontOpts);
for (prop in params) {
if (params.hasOwnProperty(prop)) {
myOpts.fittingRules[prop] = params[prop];
}
myOpts.printDirection = (typeof options.printDirection !== 'undefined') ? options.printDirection : fontOpts.printDirection;
myOpts.showHardBlanks = options.showHardBlanks || false;
myOpts.width = options.width || -1;
myOpts.whitespaceBreak = options.whitespaceBreak || false;
return myOpts;
}
}
myOpts.printDirection =
typeof options.printDirection !== "undefined"
? options.printDirection
: fontOpts.printDirection;
myOpts.showHardBlanks = options.showHardBlanks || false;
myOpts.width = options.width || -1;
myOpts.whitespaceBreak = options.whitespaceBreak || false;
// -------------------------------------------------------------------------
// Public methods
return myOpts;
}
/*
// -------------------------------------------------------------------------
// Public methods
/*
A short-cut for the figlet.text method

@@ -880,26 +1163,26 @@

*/
var me = function(txt, options, next) {
me.text(txt, options, next);
};
me.text = function(txt, options, next) {
var fontName = '';
const me = function (txt, options, next) {
me.text(txt, options, next);
};
me.text = function (txt, options, next) {
let fontName = "";
// Validate inputs
txt = txt + '';
// Validate inputs
txt = txt + "";
if (typeof arguments[1] === 'function') {
next = options;
options = {};
options.font = figDefaults.font; // default font
}
if (typeof arguments[1] === "function") {
next = options;
options = {};
options.font = figDefaults.font; // default font
}
if (typeof options === 'string') {
fontName = options;
options = {};
} else {
options = options || {};
fontName = options.font || figDefaults.font;
}
if (typeof options === "string") {
fontName = options;
options = {};
} else {
options = options || {};
fontName = options.font || figDefaults.font;
}
/*
/*
Load the font. If it loads, it's data will be contained in the figFonts object.

@@ -909,34 +1192,37 @@ The callback will recieve a fontsOpts object, which contains the default

*/
me.loadFont(fontName, function(err, fontOpts) {
if (err) {
return next(err);
}
me.loadFont(fontName, function (err, fontOpts) {
if (err) {
return next(err);
}
next(null, generateText(fontName, _reworkFontOpts(fontOpts, options), txt));
});
};
next(
null,
generateText(fontName, _reworkFontOpts(fontOpts, options), txt)
);
});
};
/*
/*
Synchronous version of figlet.text.
Accepts the same parameters.
*/
me.textSync = function(txt, options) {
var fontName = '';
me.textSync = function (txt, options) {
let fontName = "";
// Validate inputs
txt = txt + '';
// Validate inputs
txt = txt + "";
if (typeof options === 'string') {
fontName = options;
options = {};
} else {
options = options || {};
fontName = options.font || figDefaults.font;
}
if (typeof options === "string") {
fontName = options;
options = {};
} else {
options = options || {};
fontName = options.font || figDefaults.font;
}
var fontOpts = _reworkFontOpts(me.loadFontSync(fontName), options);
return generateText(fontName, fontOpts, txt);
};
var fontOpts = _reworkFontOpts(me.loadFontSync(fontName), options);
return generateText(fontName, fontOpts, txt);
};
/*
/*
Returns metadata about a specfic FIGlet font.

@@ -950,6 +1236,6 @@

*/
me.metadata = function(fontName, next) {
fontName = fontName + '';
me.metadata = function (fontName, next) {
fontName = fontName + "";
/*
/*
Load the font. If it loads, it's data will be contained in the figFonts object.

@@ -959,13 +1245,13 @@ The callback will recieve a fontsOpts object, which contains the default

*/
me.loadFont(fontName, function(err, fontOpts) {
if (err) {
next(err);
return;
}
me.loadFont(fontName, function (err, fontOpts) {
if (err) {
next(err);
return;
}
next(null, fontOpts, figFonts[fontName].comment);
});
};
next(null, fontOpts, figFonts[fontName].comment);
});
};
/*
/*
Allows you to override defaults. See the definition of the figDefaults object up above

@@ -975,171 +1261,192 @@ to see what properties can be overridden.

*/
me.defaults = function(opts) {
if (typeof opts === 'object' && opts !== null) {
for (var prop in opts) {
if (opts.hasOwnProperty(prop)) {
figDefaults[prop] = opts[prop];
}
}
me.defaults = function (opts) {
if (typeof opts === "object" && opts !== null) {
for (var prop in opts) {
if (opts.hasOwnProperty(prop)) {
figDefaults[prop] = opts[prop];
}
return JSON.parse(JSON.stringify(figDefaults));
};
}
}
return JSON.parse(JSON.stringify(figDefaults));
};
/*
/*
Parses data from a FIGlet font file and places it into the figFonts object.
*/
me.parseFont = function(fontName, data) {
data = data.replace(/\r\n/g,"\n").replace(/\r/g,"\n");
figFonts[fontName] = {};
me.parseFont = function (fontName, data) {
data = data.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
figFonts[fontName] = {};
var lines = data.split("\n");
var headerData = lines.splice(0,1)[0].split(" ");
var figFont = figFonts[fontName];
var opts = {};
var lines = data.split("\n");
var headerData = lines.splice(0, 1)[0].split(" ");
var figFont = figFonts[fontName];
var opts = {};
opts.hardBlank = headerData[0].substr(5,1);
opts.height = parseInt(headerData[1], 10);
opts.baseline = parseInt(headerData[2], 10);
opts.maxLength = parseInt(headerData[3], 10);
opts.oldLayout = parseInt(headerData[4], 10);
opts.numCommentLines = parseInt(headerData[5], 10);
opts.printDirection = (headerData.length >= 6) ? parseInt(headerData[6], 10) : 0;
opts.fullLayout = (headerData.length >= 7) ? parseInt(headerData[7], 10) : null;
opts.codeTagCount = (headerData.length >= 8) ? parseInt(headerData[8], 10) : null;
opts.fittingRules = getSmushingRules(opts.oldLayout, opts.fullLayout);
opts.hardBlank = headerData[0].substr(5, 1);
opts.height = parseInt(headerData[1], 10);
opts.baseline = parseInt(headerData[2], 10);
opts.maxLength = parseInt(headerData[3], 10);
opts.oldLayout = parseInt(headerData[4], 10);
opts.numCommentLines = parseInt(headerData[5], 10);
opts.printDirection =
headerData.length >= 6 ? parseInt(headerData[6], 10) : 0;
opts.fullLayout =
headerData.length >= 7 ? parseInt(headerData[7], 10) : null;
opts.codeTagCount =
headerData.length >= 8 ? parseInt(headerData[8], 10) : null;
opts.fittingRules = getSmushingRules(opts.oldLayout, opts.fullLayout);
figFont.options = opts;
figFont.options = opts;
// error check
if (opts.hardBlank.length !== 1 ||
isNaN(opts.height) ||
isNaN(opts.baseline) ||
isNaN(opts.maxLength) ||
isNaN(opts.oldLayout) ||
isNaN(opts.numCommentLines) )
{
throw new Error('FIGlet header contains invalid values.');
}
// error check
if (
opts.hardBlank.length !== 1 ||
isNaN(opts.height) ||
isNaN(opts.baseline) ||
isNaN(opts.maxLength) ||
isNaN(opts.oldLayout) ||
isNaN(opts.numCommentLines)
) {
throw new Error("FIGlet header contains invalid values.");
}
/*
/*
All FIGlet fonts must contain chars 32-126, 196, 214, 220, 228, 246, 252, 223
*/
var charNums = [], ii;
for (ii = 32; ii <= 126; ii++) {
charNums.push(ii);
}
charNums = charNums.concat(196, 214, 220, 228, 246, 252, 223);
let charNums = [],
ii;
for (ii = 32; ii <= 126; ii++) {
charNums.push(ii);
}
charNums = charNums.concat(196, 214, 220, 228, 246, 252, 223);
// error check - validate that there are enough lines in the file
if (lines.length < (opts.numCommentLines + (opts.height * charNums.length)) ) {
throw new Error('FIGlet file is missing data.');
}
// error check - validate that there are enough lines in the file
if (lines.length < opts.numCommentLines + opts.height * charNums.length) {
throw new Error("FIGlet file is missing data.");
}
/*
/*
Parse out the context of the file and put it into our figFont object
*/
var cNum, endCharRegEx, parseError = false;
let cNum,
endCharRegEx,
parseError = false;
figFont.comment = lines.splice(0,opts.numCommentLines).join("\n");
figFont.numChars = 0;
figFont.comment = lines.splice(0, opts.numCommentLines).join("\n");
figFont.numChars = 0;
while (lines.length > 0 && figFont.numChars < charNums.length) {
cNum = charNums[figFont.numChars];
figFont[cNum] = lines.splice(0,opts.height);
// remove end sub-chars
for (ii = 0; ii < opts.height; ii++) {
if (typeof figFont[cNum][ii] === "undefined") {
figFont[cNum][ii] = "";
} else {
endCharRegEx = new RegExp("\\"+figFont[cNum][ii].substr(figFont[cNum][ii].length-1,1)+"+$");
figFont[cNum][ii] = figFont[cNum][ii].replace(endCharRegEx,"");
}
}
figFont.numChars++;
while (lines.length > 0 && figFont.numChars < charNums.length) {
cNum = charNums[figFont.numChars];
figFont[cNum] = lines.splice(0, opts.height);
// remove end sub-chars
for (ii = 0; ii < opts.height; ii++) {
if (typeof figFont[cNum][ii] === "undefined") {
figFont[cNum][ii] = "";
} else {
endCharRegEx = new RegExp(
"\\" +
figFont[cNum][ii].substr(figFont[cNum][ii].length - 1, 1) +
"+$"
);
figFont[cNum][ii] = figFont[cNum][ii].replace(endCharRegEx, "");
}
}
figFont.numChars++;
}
/*
/*
Now we check to see if any additional characters are present
*/
while (lines.length > 0) {
cNum = lines.splice(0,1)[0].split(" ")[0];
if ( /^0[xX][0-9a-fA-F]+$/.test(cNum) ) {
cNum = parseInt(cNum, 16);
} else if ( /^0[0-7]+$/.test(cNum) ) {
cNum = parseInt(cNum, 8);
} else if ( /^[0-9]+$/.test(cNum) ) {
cNum = parseInt(cNum, 10);
} else if ( /^-0[xX][0-9a-fA-F]+$/.test(cNum) ) {
cNum = parseInt(cNum, 16);
} else {
if (cNum === "") {break;}
// something's wrong
console.log("Invalid data:"+cNum);
parseError = true;
break;
}
figFont[cNum] = lines.splice(0,opts.height);
// remove end sub-chars
for (ii = 0; ii < opts.height; ii++) {
if (typeof figFont[cNum][ii] === "undefined") {
figFont[cNum][ii] = "";
} else {
endCharRegEx = new RegExp("\\"+figFont[cNum][ii].substr(figFont[cNum][ii].length-1,1)+"+$");
figFont[cNum][ii] = figFont[cNum][ii].replace(endCharRegEx,"");
}
}
figFont.numChars++;
while (lines.length > 0) {
cNum = lines.splice(0, 1)[0].split(" ")[0];
if (/^0[xX][0-9a-fA-F]+$/.test(cNum)) {
cNum = parseInt(cNum, 16);
} else if (/^0[0-7]+$/.test(cNum)) {
cNum = parseInt(cNum, 8);
} else if (/^[0-9]+$/.test(cNum)) {
cNum = parseInt(cNum, 10);
} else if (/^-0[xX][0-9a-fA-F]+$/.test(cNum)) {
cNum = parseInt(cNum, 16);
} else {
if (cNum === "") {
break;
}
// something's wrong
console.log("Invalid data:" + cNum);
parseError = true;
break;
}
// error check
if (parseError === true) {
throw new Error('Error parsing data.');
figFont[cNum] = lines.splice(0, opts.height);
// remove end sub-chars
for (ii = 0; ii < opts.height; ii++) {
if (typeof figFont[cNum][ii] === "undefined") {
figFont[cNum][ii] = "";
} else {
endCharRegEx = new RegExp(
"\\" +
figFont[cNum][ii].substr(figFont[cNum][ii].length - 1, 1) +
"+$"
);
figFont[cNum][ii] = figFont[cNum][ii].replace(endCharRegEx, "");
}
}
figFont.numChars++;
}
return opts;
};
// error check
if (parseError === true) {
throw new Error("Error parsing data.");
}
/*
return opts;
};
/*
Loads a font.
*/
me.loadFont = function(fontName, next) {
if (figFonts[fontName]) {
next(null, figFonts[fontName].options);
return;
}
me.loadFont = function (fontName, next) {
if (figFonts[fontName]) {
next(null, figFonts[fontName].options);
return;
}
if (typeof fetch !== 'function') {
console.error('figlet.js requires the fetch API or a fetch polyfill such as https://cdnjs.com/libraries/fetch');
throw new Error('fetch is required for figlet.js to work.');
if (typeof fetch !== "function") {
console.error(
"figlet.js requires the fetch API or a fetch polyfill such as https://cdnjs.com/libraries/fetch"
);
throw new Error("fetch is required for figlet.js to work.");
}
fetch(figDefaults.fontPath + "/" + fontName + ".flf")
.then(function (response) {
if (response.ok) {
return response.text();
}
fetch(figDefaults.fontPath + '/' + fontName + '.flf')
.then(function(response) {
if(response.ok) {
return response.text();
}
console.log("Unexpected response", response);
throw new Error("Network response was not ok.");
})
.then(function (text) {
next(null, me.parseFont(fontName, text));
})
.catch(next);
};
console.log('Unexpected response', response);
throw new Error('Network response was not ok.');
})
.then(function(text) {
next(null, me.parseFont(fontName, text));
})
.catch(next);
};
/*
/*
loads a font synchronously, not implemented for the browser
*/
me.loadFontSync = function(name) {
if (figFonts[name]) {
return figFonts[name].options;
}
throw new Error('synchronous font loading is not implemented for the browser');
};
me.loadFontSync = function (name) {
if (figFonts[name]) {
return figFonts[name].options;
}
throw new Error(
"synchronous font loading is not implemented for the browser"
);
};
/*
/*
preloads a list of fonts prior to using textSync

@@ -1149,36 +1456,40 @@ - fonts: an array of font names (i.e. ["Standard","Soft"])

*/
me.preloadFonts = function(fonts, next) {
var fontData = [];
me.preloadFonts = function (fonts, next) {
let fontData = [];
fonts.reduce(function(promise, name){
return promise.then(function() {
return fetch(figDefaults.fontPath + '/' + name + '.flf').then((response) => {
return response.text();
}).then(function(data) {
fontData.push(data);
});
fonts
.reduce(function (promise, name) {
return promise.then(function () {
return fetch(figDefaults.fontPath + "/" + name + ".flf")
.then((response) => {
return response.text();
})
.then(function (data) {
fontData.push(data);
});
}, Promise.resolve()).then(function(res){
for(var i in fonts){
if (fonts.hasOwnProperty(i)) {
me.parseFont(fonts[i], fontData[i]);
}
}
if (next) {
next();
}
});
};
}, Promise.resolve())
.then(function (res) {
for (var i in fonts) {
if (fonts.hasOwnProperty(i)) {
me.parseFont(fonts[i], fontData[i]);
}
}
me.figFonts = figFonts;
if (next) {
next();
}
});
};
return me;
me.figFonts = figFonts;
return me;
})();
// for node.js
if (typeof module !== 'undefined') {
if (typeof module.exports !== 'undefined') {
module.exports = figlet;
}
if (typeof module !== "undefined") {
if (typeof module.exports !== "undefined") {
module.exports = figlet;
}
}

@@ -5,6 +5,6 @@ /*

var figlet = require('./figlet.js'),
fs = require('fs'),
path = require('path'),
fontDir = path.join(__dirname, '/../fonts/');
const figlet = require("./figlet.js"),
fs = require("fs"),
path = require("path"),
fontDir = path.join(__dirname, "/../fonts/");

@@ -18,20 +18,24 @@ /*

*/
figlet.loadFont = function(name, next) {
if (figlet.figFonts[name]) {
next(null, figlet.figFonts[name].options);
return;
}
figlet.loadFont = function (name, next) {
if (figlet.figFonts[name]) {
next(null, figlet.figFonts[name].options);
return;
}
fs.readFile( path.join(fontDir, name + '.flf'), {encoding: 'utf-8'}, function(err, fontData) {
if (err) {
return next(err);
}
fs.readFile(
path.join(fontDir, name + ".flf"),
{ encoding: "utf-8" },
function (err, fontData) {
if (err) {
return next(err);
}
fontData = fontData + '';
try {
next(null, figlet.parseFont(name, fontData));
} catch(error) {
next(error);
}
});
fontData = fontData + "";
try {
next(null, figlet.parseFont(name, fontData));
} catch (error) {
next(error);
}
}
);
};

@@ -45,11 +49,13 @@

*/
figlet.loadFontSync = function(name) {
if (figlet.figFonts[name]) {
return figlet.figFonts[name].options;
}
figlet.loadFontSync = function (name) {
if (figlet.figFonts[name]) {
return figlet.figFonts[name].options;
}
var fontData = fs.readFileSync( path.join(fontDir, name + '.flf'), {encoding: 'utf-8'});
var fontData = fs.readFileSync(path.join(fontDir, name + ".flf"), {
encoding: "utf-8",
});
fontData = fontData + '';
return figlet.parseFont(name, fontData);
fontData = fontData + "";
return figlet.parseFont(name, fontData);
};

@@ -60,31 +66,31 @@

*/
figlet.fonts = function(next) {
var fontList = [];
fs.readdir(fontDir, function (err, files) { // '/' denotes the root folder
if (err) {
return next(err);
}
figlet.fonts = function (next) {
var fontList = [];
fs.readdir(fontDir, function (err, files) {
// '/' denotes the root folder
if (err) {
return next(err);
}
files.forEach( function (file) {
if ( /\.flf$/.test(file) ) {
fontList.push( file.replace(/\.flf$/,'') );
}
});
next(null, fontList);
files.forEach(function (file) {
if (/\.flf$/.test(file)) {
fontList.push(file.replace(/\.flf$/, ""));
}
});
next(null, fontList);
});
};
figlet.fontsSync = function() {
var fontList = [];
fs.readdirSync(fontDir).forEach(function(file) {
if ( /\.flf$/.test(file) ) {
fontList.push( file.replace(/\.flf$/,'') );
}
});
figlet.fontsSync = function () {
var fontList = [];
fs.readdirSync(fontDir).forEach(function (file) {
if (/\.flf$/.test(file)) {
fontList.push(file.replace(/\.flf$/, ""));
}
});
return fontList;
return fontList;
};
module.exports = figlet;
{
"name": "figlet",
"version": "1.6.0-beta.1",
"description": "Creates ASCII Art from text. A full implementation of the FIGfont spec.",
"keywords": [
"figlet",
"ascii",
"art",
"banner",
"ansi"
],
"bin": "./bin/index.js",
"repository": {
"type": "git",
"url": "https://github.com/patorjk/figlet.js.git"
},
"bugs": {
"url": "https://github.com/patorjk/figlet.js/issues"
},
"author": {
"name": "Patrick Gillespie",
"email": "patorjk@gmail.com",
"url": "http://patorjk.com/"
},
"license": "MIT",
"main": "./lib/node-figlet.js",
"browser": "./lib/figlet.js",
"devDependencies": {
"async": "~3.2.4",
"grunt": "^1.6.1",
"grunt-contrib-clean": "~2.0.1",
"grunt-contrib-jshint": "^3.2.0",
"grunt-contrib-nodeunit": "~5.0.0",
"grunt-contrib-uglify": "^5.2.2"
},
"scripts": {
"test": "grunt test"
},
"engines": {
"node": ">= 0.4.0"
}
"name": "figlet",
"version": "1.6.0",
"description": "Creates ASCII Art from text. A full implementation of the FIGfont spec.",
"keywords": [
"figlet",
"ascii",
"art",
"banner",
"ansi"
],
"bin": "./bin/index.js",
"repository": {
"type": "git",
"url": "https://github.com/patorjk/figlet.js.git"
},
"bugs": {
"url": "https://github.com/patorjk/figlet.js/issues"
},
"author": {
"name": "Patrick Gillespie",
"email": "patorjk@gmail.com",
"url": "http://patorjk.com/"
},
"license": "MIT",
"main": "./lib/node-figlet.js",
"browser": "./lib/figlet.js",
"devDependencies": {
"async": "~3.2.4",
"grunt": "^1.6.1",
"grunt-contrib-clean": "~2.0.1",
"grunt-contrib-jshint": "^3.2.0",
"grunt-contrib-nodeunit": "~5.0.0",
"grunt-contrib-uglify": "^5.2.2",
"prettier": "2.8.7"
},
"scripts": {
"test": "grunt test"
},
"engines": {
"node": ">= 0.4.0"
}
}
```
___________.___ ________.__ __ __
___________.___ ________.__ __ __
\_ _____/| |/ _____/| | _____/ |_ |__| ______

@@ -10,2 +10,3 @@ | __) | / \ ___| | _/ __ \ __\ | |/ ___/

```
[![Build Status](https://travis-ci.org/patorjk/figlet.js.svg)](https://travis-ci.org/patorjk/figlet.js)

@@ -16,4 +17,3 @@ [![NPM Downloads](https://img.shields.io/npm/dt/figlet.svg?style=flat)](https://npmcharts.com/compare/figlet?minimal=true)

Quick Start - Node.js
-------------------------
## Quick Start - Node.js

@@ -29,11 +29,11 @@ Install:

```js
var figlet = require('figlet');
var figlet = require("figlet");
figlet('Hello World!!', function(err, data) {
if (err) {
console.log('Something went wrong...');
console.dir(err);
return;
}
console.log(data)
figlet("Hello World!!", function (err, data) {
if (err) {
console.log("Something went wrong...");
console.dir(err);
return;
}
console.log(data);
});

@@ -52,4 +52,3 @@ ```

Basic Usage - Node.js
-------------------------
## Basic Usage - Node.js

@@ -60,5 +59,5 @@ ### text

* Input Text - A string of text to turn into ASCII Art.
* Options - Either a string indicating the font name or an options object (description below).
* Callback - A function to execute with the generated ASCII Art.
- Input Text - A string of text to turn into ASCII Art.
- Options - Either a string indicating the font name or an options object (description below).
- Callback - A function to execute with the generated ASCII Art.

@@ -68,16 +67,20 @@ Example:

```js
figlet.text('Boo!', {
font: 'Ghost',
horizontalLayout: 'default',
verticalLayout: 'default',
figlet.text(
"Boo!",
{
font: "Ghost",
horizontalLayout: "default",
verticalLayout: "default",
width: 80,
whitespaceBreak: true
}, function(err, data) {
whitespaceBreak: true,
},
function (err, data) {
if (err) {
console.log('Something went wrong...');
console.dir(err);
return;
console.log("Something went wrong...");
console.dir(err);
return;
}
console.log(data);
});
}
);
```

@@ -94,4 +97,4 @@

| .-. `. \_) | |\| |\_) | |\| || .'
| | \ | \ | | | | \ | | | |`--'
| '--' / `' '-' ' `' '-' '.--.
| | \ | \ | | | | \ | | | |`--'
| '--' / `' '-' ' `' '-' '.--.
`------' `-----' `-----' '--'

@@ -104,4 +107,4 @@ ```

* Input Text - A string of text to turn into ASCII Art.
* Font Options - Either a string indicating the font name or an options object (description below).
- Input Text - A string of text to turn into ASCII Art.
- Font Options - Either a string indicating the font name or an options object (description below).

@@ -111,9 +114,11 @@ Example:

```js
console.log(figlet.textSync('Boo!', {
font: 'Ghost',
horizontalLayout: 'default',
verticalLayout: 'default',
console.log(
figlet.textSync("Boo!", {
font: "Ghost",
horizontalLayout: "default",
verticalLayout: "default",
width: 80,
whitespaceBreak: true
}));
whitespaceBreak: true,
})
);
```

@@ -140,2 +145,3 @@

#### font
Type: `String`

@@ -147,2 +153,3 @@ Default value: `'Standard'`

#### horizontalLayout
Type: `String`

@@ -154,2 +161,3 @@ Default value: `'default'`

#### verticalLayout
Type: `String`

@@ -161,2 +169,3 @@ Default value: `'default'`

#### width
Type: `Number`

@@ -168,2 +177,3 @@ Default value: `undefined`

#### whitespaceBreak
Type: `Boolean`

@@ -176,6 +186,6 @@ Default value: `false`

The 2 layout options allow you to override a font's default "kerning". Below you can see how this effects the text. The string "Kerning" was printed using the "Standard" font with horizontal layouts of "default", "fitted" and then "full".
The 2 layout options allow you to override a font's default "kerning". Below you can see how this effects the text. The string "Kerning" was printed using the "Standard" font with horizontal layouts of "default", "fitted" and then "full".
```
_ __ _
_ __ _
| |/ /___ _ __ _ __ (_)_ __ __ _

@@ -186,3 +196,3 @@ | ' // _ \ '__| '_ \| | '_ \ / _` |

|___/
_ __ _
_ __ _
| |/ / ___ _ __ _ __ (_) _ __ __ _

@@ -193,3 +203,3 @@ | ' / / _ \| '__|| '_ \ | || '_ \ / _` |

|___/
_ __ _
_ __ _
| |/ / ___ _ __ _ __ (_) _ __ __ _

@@ -209,10 +219,10 @@ | ' / / _ \ | '__| | '_ \ | | | '_ \ / _` |

```js
figlet.metadata('Standard', function(err, options, headerComment) {
if (err) {
console.log('something went wrong...');
console.dir(err);
return;
}
console.dir(options);
console.log(headerComment);
figlet.metadata("Standard", function (err, options, headerComment) {
if (err) {
console.log("something went wrong...");
console.dir(err);
return;
}
console.dir(options);
console.log(headerComment);
});

@@ -226,9 +236,9 @@ ```

```js
figlet.fonts(function(err, fonts) {
if (err) {
console.log('something went wrong...');
console.dir(err);
return;
}
console.dir(fonts);
figlet.fonts(function (err, fonts) {
if (err) {
console.log("something went wrong...");
console.dir(err);
return;
}
console.dir(fonts);
});

@@ -250,12 +260,11 @@ ```

```js
const fs = require('fs');
const path = require('path');
const fs = require("fs");
const path = require("path");
let data = fs.readFileSync(path.join(__dirname, 'myfont.flf'), 'utf8');
figlet.parseFont('myfont', data);
console.log(figlet.textSync('myfont!', 'myfont'));
let data = fs.readFileSync(path.join(__dirname, "myfont.flf"), "utf8");
figlet.parseFont("myfont", data);
console.log(figlet.textSync("myfont!", "myfont"));
```
Getting Started - Webpack / React
-------------------------
## Getting Started - Webpack / React

@@ -265,16 +274,19 @@ Webpack/React usage will be very similar to what's talked about in the "Getting Started - The Browser" section. The main difference is that you import fonts via the importable-fonts folder. Example:

```js
import figlet from 'figlet';
import standard from 'figlet/importable-fonts/Standard.js'
import figlet from "figlet";
import standard from "figlet/importable-fonts/Standard.js";
figlet.parseFont('Standard', standard);
figlet.parseFont("Standard", standard);
figlet.text('test', {
font: 'Standard',
}, function(err, data) {
figlet.text(
"test",
{
font: "Standard",
},
function (err, data) {
console.log(data);
});
}
);
```
Getting Started - The Browser
-------------------------
## Getting Started - The Browser

@@ -286,16 +298,17 @@ The browser API is the same as the Node API with the exception of the "fonts" method not being available. The browser version also requires [fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) (or a [shim](https://github.com/github/fetch)) for its loadFont function.

```html
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/fetch/1.0.0/fetch.min.js"></script>
<script
type="text/javascript"
src="//cdnjs.cloudflare.com/ajax/libs/fetch/1.0.0/fetch.min.js"
></script>
<script type="text/javascript" src="figlet.js"></script>
<script>
figlet(inputText, 'Standard', function(err, text) {
if (err) {
console.log('something went wrong...');
console.dir(err);
return;
}
console.log(text);
});
figlet(inputText, "Standard", function (err, text) {
if (err) {
console.log("something went wrong...");
console.dir(err);
return;
}
console.log(text);
});
</script>

@@ -311,11 +324,10 @@ ```

```js
figlet.defaults({fontPath: "assets/fonts"});
figlet.defaults({ fontPath: "assets/fonts" });
figlet.preloadFonts(["Standard", "Ghost"], ready);
function ready(){
function ready() {
console.log(figlet.textSync("ASCII"));
console.log(figlet.textSync("Art", "Ghost"));
}
```

@@ -332,11 +344,11 @@

('-. _ .-') .-') _
( OO ).-.( \( -O ) ( OO) )
/ . --. / ,------. / '._
('-. _ .-') .-') _
( OO ).-.( \( -O ) ( OO) )
/ . --. / ,------. / '._
| \-. \ | /`. '|'--...__)
.-'-' | | | / | |'--. .--'
\| |_.' | | |_.' | | |
| .-. | | . '.' | |
| | | | | |\ \ | |
`--' `--' `--' '--' `--'
\| |_.' | | |_.' | | |
| .-. | | . '.' | |
| | | | | |\ \ | |
`--' `--' `--' '--' `--'

@@ -347,4 +359,3 @@ ```

Getting Started - Command Line
-------------------------
## Getting Started - Command Line

@@ -366,13 +377,15 @@ To use figlet.js on the command line, install figlet-cli:

## Release History
* 2021.08.11 v1.5.2 Minor bug fixes.
* 2020.07.12 v1.5.1 Fixed with vertical smushing, updated lodash version.
* 2020.07.12 v1.5.0 Added width and whitespaceBreak options.
* 2020.04.26 v1.4.0 Removed jQuery from preloader and examples.
* 2020.02.23 v1.3.0 Added the "ANSI Regular" font and updated the README with info on how to use with Webpack.
* 2018.03.26 v1.2.1 parseFont works in node for adding fonts manually
* 2016.09.27 v1.2.0 jQuery replaced with fetch API / polyfill.
* 2016.04.28 v1.1.2 textSync now works in the browser with font pre-loading.
* 2014.08.15 v1.1.0 Sync functions added.
* 2014.07.31 v1.0.1 Bug fixes.
* 2013.12.28 v1.0.7 README update and minor tweaks.
* 2013.01.02 v1.0.8 Added tests and command line info.
- 2023.04.08 v1.6.0 Added npx support (ex: npx figlet test).
- 2021.08.11 v1.5.2 Minor bug fixes.
- 2020.07.12 v1.5.1 Fixed with vertical smushing, updated lodash version.
- 2020.07.12 v1.5.0 Added width and whitespaceBreak options.
- 2020.04.26 v1.4.0 Removed jQuery from preloader and examples.
- 2020.02.23 v1.3.0 Added the "ANSI Regular" font and updated the README with info on how to use with Webpack.
- 2018.03.26 v1.2.1 parseFont works in node for adding fonts manually
- 2016.09.27 v1.2.0 jQuery replaced with fetch API / polyfill.
- 2016.04.28 v1.1.2 textSync now works in the browser with font pre-loading.
- 2014.08.15 v1.1.0 Sync functions added.
- 2014.07.31 v1.0.1 Bug fixes.
- 2013.12.28 v1.0.7 README update and minor tweaks.
- 2013.01.02 v1.0.8 Added tests and command line info.

@@ -0,11 +1,9 @@

"use strict";
const figlet = require("../lib/node-figlet"),
grunt = require("grunt"),
fs = require("fs"),
path = require("path"),
async = require("async");
'use strict';
var figlet = require('../lib/node-figlet'),
grunt = require('grunt'),
fs = require('fs'),
path = require('path'),
async = require('async');
/*

@@ -32,225 +30,306 @@ ======== A Handy Little Nodeunit Reference ========

exports.figlet = {
setUp: function(done) {
// setup here if necessary
done();
},
standard: function(test) {
test.expect(1);
setUp: function (done) {
// setup here if necessary
done();
},
standard: function (test) {
test.expect(1);
figlet('FIGlet\nFONTS', {
font: 'Standard',
verticalLayout: 'fitted'
}, function(err, actual) {
var expected = grunt.file.read('test/expected/standard');
test.equal(actual, expected, 'Standard font with a vertical layout of "fitted".');
figlet(
"FIGlet\nFONTS",
{
font: "Standard",
verticalLayout: "fitted",
},
function (err, actual) {
var expected = grunt.file.read("test/expected/standard");
test.equal(
actual,
expected,
'Standard font with a vertical layout of "fitted".'
);
test.done();
});
},
standardSync: function(test) {
test.expect(1);
test.done();
}
);
},
standardSync: function (test) {
test.expect(1);
var expected = grunt.file.read('test/expected/standard');
var actual = figlet.textSync('FIGlet\nFONTS', {font: 'Standard', verticalLayout: 'fitted'});
var expected = grunt.file.read("test/expected/standard");
var actual = figlet.textSync("FIGlet\nFONTS", {
font: "Standard",
verticalLayout: "fitted",
});
test.equal(actual, expected, 'Standard font with a vertical layout of "fitted".');
test.equal(
actual,
expected,
'Standard font with a vertical layout of "fitted".'
);
test.done();
},
standardParse: function(test) {
test.expect(1);
test.done();
},
standardParse: function (test) {
test.expect(1);
var expected = grunt.file.read('test/expected/standard');
var data = fs.readFileSync(path.join(__dirname, '../fonts/Standard.flf'), 'utf8');
var font = figlet.parseFont('StandardParseFontName', data);
var actual = figlet.textSync('FIGlet\nFONTS', {font: 'StandardParseFontName', verticalLayout: 'fitted'});
var expected = grunt.file.read("test/expected/standard");
var data = fs.readFileSync(
path.join(__dirname, "../fonts/Standard.flf"),
"utf8"
);
var font = figlet.parseFont("StandardParseFontName", data);
var actual = figlet.textSync("FIGlet\nFONTS", {
font: "StandardParseFontName",
verticalLayout: "fitted",
});
test.equal(actual, expected, 'Standard font with a vertical layout of "fitted" loaded using parseFont().');
test.equal(
actual,
expected,
'Standard font with a vertical layout of "fitted" loaded using parseFont().'
);
test.done();
},
graffiti: function (test) {
test.expect(1);
figlet.text(
"ABC.123",
{
font: "Graffiti",
horizontalLayout: "fitted",
},
function (err, actual) {
var expected = grunt.file.read("test/expected/graffiti");
test.equal(
actual,
expected,
'Graffiti font with a horizontal layout of "fitted".'
);
test.done();
},
graffiti: function(test) {
test.expect(1);
}
);
},
graffitiSync: function (test) {
test.expect(1);
figlet.text('ABC.123', {
font: 'Graffiti',
horizontalLayout: 'fitted'
}, function(err, actual) {
var expected = grunt.file.read('test/expected/graffiti');
test.equal(actual, expected, 'Graffiti font with a horizontal layout of "fitted".');
var expected = grunt.file.read("test/expected/graffiti");
var actual = figlet.textSync("ABC.123", {
font: "Graffiti",
horizontalLayout: "fitted",
});
test.equal(
actual,
expected,
'Graffiti font with a horizontal layout of "fitted".'
);
test.done();
});
},
graffitiSync: function(test) {
test.expect(1);
test.done();
},
wrap: function (test) {
test.expect(4);
var specs = [
{
input: "Hello From The Figlet Library",
expected: grunt.file.read("test/expected/wrapSimple"),
},
{
input: "Hello From The Figlet Library That Wrap Text",
expected: grunt.file.read("test/expected/wrapSimpleThreeLines"),
},
];
(function recur() {
var spec = specs.pop();
if (!spec) {
test.done();
} else {
figlet(
spec.input,
{
font: "Standard",
width: 80,
},
function (err, actual) {
var maxWidth = actual.split("\n").reduce(function (acc, line) {
if (acc < line.length) {
return line.length;
}
return acc;
}, 0);
test.equal(maxWidth <= 80, true);
test.equal(actual, spec.expected, "Standard font with wrap.");
recur();
}
);
}
})();
},
wrapBreakWord: function (test) {
test.expect(10);
var specs = [
{
input: "Hello From The Figlet Library",
expected: grunt.file.read("test/expected/wrapWord"),
width: 80,
},
{
input: "Hello From The Figlet Library That Wrap Text",
expected: grunt.file.read("test/expected/wrapWordThreeLines"),
width: 80,
},
{
input: "Hello From The Figlet Library That Wrap Text",
expected: grunt.file.read("test/expected/wrapWordThreeLines"),
width: 80,
},
{
input: "Hello LongLongLong Word Longerhello",
expected: grunt.file.read("test/expected/wrapWhitespaceBreakWord"),
width: 30,
},
{
input: "xxxxxxxxxxxxxxxxxxxxxxxx",
expected: grunt.file.read("test/expected/wrapWhitespaceLogString"),
width: 30,
},
];
(function recur() {
var spec = specs.pop();
if (!spec) {
test.done();
} else {
var width = spec.width;
figlet(
spec.input,
{
font: "Standard",
width: width,
whitespaceBreak: true,
},
function (err, actual) {
var maxWidth = actual.split("\n").reduce(function (acc, line) {
if (acc < line.length) {
return line.length;
}
return acc;
}, 0);
test.equal(maxWidth <= width, true);
test.equal(actual, spec.expected, "Standard font with word break.");
recur();
}
);
}
})();
},
dancingFont: function (test) {
test.expect(1);
var expected = grunt.file.read('test/expected/graffiti');
var actual = figlet.textSync('ABC.123', {font: 'Graffiti', horizontalLayout: 'fitted'});
test.equal(actual, expected, 'Graffiti font with a horizontal layout of "fitted".');
figlet.text(
"pizzapie",
{
font: "Dancing Font",
horizontalLayout: "full",
},
function (err, actual) {
var expected = grunt.file.read("test/expected/dancingFont");
test.equal(
actual,
expected,
'Dancing Font with a horizontal layout of "full".'
);
test.done();
},
wrap: function(test) {
test.expect(4);
var specs = [
{
input: 'Hello From The Figlet Library',
expected: grunt.file.read('test/expected/wrapSimple')
},
{
input: 'Hello From The Figlet Library That Wrap Text',
expected: grunt.file.read('test/expected/wrapSimpleThreeLines')
}
];
(function recur() {
var spec = specs.pop();
if (!spec) {
test.done();
} else {
figlet(spec.input, {
font: 'Standard',
width: 80
}, function(err, actual) {
var maxWidth = actual.split('\n').reduce(function(acc, line) {
if (acc < line.length) {
return line.length;
}
return acc;
}, 0);
test.equal(maxWidth <= 80, true);
test.equal(actual, spec.expected, 'Standard font with wrap.');
recur();
});
}
})();
},
wrapBreakWord: function(test) {
test.expect(10);
var specs = [
{
input: 'Hello From The Figlet Library',
expected: grunt.file.read('test/expected/wrapWord'),
width: 80
},
{
input: 'Hello From The Figlet Library That Wrap Text',
expected: grunt.file.read('test/expected/wrapWordThreeLines'),
width: 80
},
{
input: 'Hello From The Figlet Library That Wrap Text',
expected: grunt.file.read('test/expected/wrapWordThreeLines'),
width: 80
},
{
input: 'Hello LongLongLong Word Longerhello',
expected: grunt.file.read('test/expected/wrapWhitespaceBreakWord'),
width: 30
},
{
input: 'xxxxxxxxxxxxxxxxxxxxxxxx',
expected: grunt.file.read('test/expected/wrapWhitespaceLogString'),
width: 30
}
];
(function recur() {
var spec = specs.pop();
if (!spec) {
test.done();
} else {
var width = spec.width;
figlet(spec.input, {
font: 'Standard',
width: width,
whitespaceBreak: true
}, function(err, actual) {
var maxWidth = actual.split('\n').reduce(function(acc, line) {
if (acc < line.length) {
return line.length;
}
return acc;
}, 0);
test.equal(maxWidth <= width, true);
test.equal(actual, spec.expected, 'Standard font with word break.');
recur();
});
}
})();
},
dancingFont: function(test) {
test.expect(1);
}
);
},
dancingFontSync: function (test) {
test.expect(1);
figlet.text('pizzapie', {
font: 'Dancing Font',
horizontalLayout: 'full'
}, function(err, actual) {
var expected = grunt.file.read("test/expected/dancingFont");
var actual = figlet.textSync("pizzapie", {
font: "Dancing Font",
horizontalLayout: "full",
});
test.equal(
actual,
expected,
'Dancing Font with a horizontal layout of "full".'
);
var expected = grunt.file.read('test/expected/dancingFont');
test.equal(actual, expected, 'Dancing Font with a horizontal layout of "full".');
test.done();
},
verticalSmushRule2: function (test) {
test.expect(1);
test.done();
});
},
dancingFontSync: function(test) {
test.expect(1);
var expected = grunt.file.read("test/expected/verticalSmushRule2");
var actual = figlet.textSync("Terminal\nChess", { font: "Slant" });
test.equal(actual, expected, "Vertical Smush Rule 2 should be followed.");
var expected = grunt.file.read('test/expected/dancingFont');
var actual = figlet.textSync('pizzapie', {font: 'Dancing Font', horizontalLayout: 'full'});
test.equal(actual, expected, 'Dancing Font with a horizontal layout of "full".');
test.done();
},
printDirection: function (test) {
test.expect(1);
test.done();
},
verticalSmushRule2: function(test) {
test.expect(1);
figlet.text(
"pizzapie",
{
font: "Dancing Font",
horizontalLayout: "full",
printDirection: 1,
},
function (err, actual) {
var expected = grunt.file.read("test/expected/dancingFontReverse");
test.equal(
actual,
expected,
"Dancing Font with a reversed print direction."
);
var expected = grunt.file.read('test/expected/verticalSmushRule2');
var actual = figlet.textSync('Terminal\nChess', {font: 'Slant'});
test.equal(actual, expected, 'Vertical Smush Rule 2 should be followed.');
test.done();
},
printDirection: function(test) {
test.expect(1);
figlet.text('pizzapie', {
font: 'Dancing Font',
horizontalLayout: 'full',
printDirection: 1
}, function(err, actual) {
var expected = grunt.file.read('test/expected/dancingFontReverse');
test.equal(actual, expected, 'Dancing Font with a reversed print direction.');
test.done();
});
},
/*
}
);
},
/*
This test ensures that all fonts will load without error
*/
loadAll: function(test) {
var errCount = 0;
test.expect(1);
loadAll: function (test) {
var errCount = 0;
test.expect(1);
figlet.fonts(function(err, fonts) {
if (err) {
figlet.fonts(function (err, fonts) {
if (err) {
errCount++;
return;
}
async.eachSeries(
fonts,
function (font, next) {
figlet.text(
"abc ABC ...",
{
font: font,
},
function (err, data) {
if (err) {
errCount++;
return;
}
next();
}
async.eachSeries(fonts, function(font, next) {
figlet.text('abc ABC ...', {
font: font
}, function(err, data) {
if (err) {
errCount++;
}
next();
});
}, function(err) {
test.equal(errCount, 0, 'A problem occurred while testing one of the fonts.');
test.done();
});
});
}
);
},
function (err) {
test.equal(
errCount,
0,
"A problem occurred while testing one of the fonts."
);
test.done();
}
);
});
},
};

@@ -1,22 +0,29 @@

var path = require('path');
var fontDir = path.join(__dirname, '/../fonts/');
var exportDir = path.join(__dirname, '../importable-fonts/');
var fs = require('fs')
var path = require("path");
var fontDir = path.join(__dirname, "/../fonts/");
var exportDir = path.join(__dirname, "../importable-fonts/");
var fs = require("fs");
fs.readdir(fontDir, function (err, files) {
if (err) {
console.error(err);
return;
if (err) {
console.error(err);
return;
}
files.forEach(function (name) {
if (/\.flf$/.test(name)) {
console.log(name);
var fontData = fs.readFileSync(path.join(fontDir, name), {
encoding: "utf-8",
});
fontData =
"export default `" +
fontData.replace(/\\/g, "\\\\").replace(/`/g, "\\`") +
"`";
fs.writeFileSync(
path.join(exportDir, name.replace(/flf$/, "js")),
fontData,
{ encoding: "utf-8" }
);
}
files.forEach( function (name) {
if ( /\.flf$/.test(name) ) {
console.log(name);
var fontData = fs.readFileSync( path.join(fontDir, name), {encoding: 'utf-8'});
fontData = 'export default `' + fontData.replace(/\\/g, '\\\\').replace(/`/g, '\\`') + '`';
fs.writeFileSync( path.join(exportDir, name.replace(/flf$/, 'js') ), fontData, {encoding: 'utf-8'});
}
});
});
});
});

Sorry, the diff of this file is not supported yet

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