patorjk / figlet.js

A FIG Driver written in JavaScript which aims to fully implement the FIGfont spec.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unexpected token u

seriousManual opened this issue · comments

I made little script to get a overview over all fonts that are possible:

var fs = require('fs');

var figlet = require('figlet');

fs.readdirSync('./node_modules/figlet/fonts').forEach(function(font) {
    if (font.indexOf('.flf') == -1) return;

    figlet.text('abc ABC ...', {
        font: font.split('.')[0]
    }, function(err, data) {
        if (err) return console.log('Something went wrong...');

        console.log(font);
        console.log(data);
    });
});

when running figlet breaks on several of the included fonts with the following error:

undefined:1
undefined
^
SyntaxError: Unexpected token u
    at Object.parse (native)
    at D:\programming\strichliste\node_modules\figlet\lib\figlet.js:716:31
    at D:\programming\strichliste\node_modules\figlet\lib\node-figlet.js:24:13
    at Function.me.parseFont (D:\programming\strichliste\node_modules\figlet\lib\figlet.js:899:21)
    at D:\programming\strichliste\node_modules\figlet\lib\node-figlet.js:23:16
    at fs.js:266:14
    at Object.oncomplete (fs.js:107:15)

Thank you for the report!

It looks like there are 6 problem fonts:

var fs = require('fs');
var async = require('async');

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

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


    async.eachSeries(fonts, function(font, next) {
        console.log('each font='+font);

        if (font === 'Banner' || font === 'Big' || font === 'Ivrit' || font === "Patorjk's Cheese" ||
            font === "Patorjk-HeX" || font === 'Wow') {
            next();
            return;
        }

        figlet.text('abc ABC ...', {
            font: font
        }, function(err, data) {
            console.log('font='+font);
            if (err) {
                return console.log('Something went wrong...');
            }

            //console.log(font);
            //console.log(data);
            console.log('about to call next');
            next();
        });
    }, function(err) {
        console.log('complete!');
    });
});

I'll take a look at this tonight and see about getting it fixed.

Should be fixed now. The problem fonts either had unicode characters with a negative value (these were defined at the end of the file) or were lacking the minimum number of figlet characters. On my last update I put in some code to be more strict about file format and this just slipped by. I added a test to the test file to cover this issue to prevent it from occurring again. Thanks again for letting me know!

looks great, thanks!