Git Product home page Git Product logo

Comments (9)

extending avatar extending commented on June 17, 2024 4

resolve the problem , thanks

from figlet.js.

reezpatel avatar reezpatel commented on June 17, 2024 1

Hi @patorjk , How about adding an index.d.ts in the package, would you like a PR?

from figlet.js.

guicara avatar guicara commented on June 17, 2024 1

Hello,

Until the TypeScript definition on DefinitelyTyped is updated, you can use something like that in your project (inspired from DefinitelyTyped/DefinitelyTyped#38318 and https://github.com/aplr/DefinitelyTyped/commit/099f9bea0641922116078c2421e234e72e3a2cb6):

// src/types/figlet.d.ts

// Extended type definitions for figlet 1.2
// Project: https://github.com/patorjk/figlet.js
// Definitions by: Junyoung Clare Jang <https://github.com/Ailrun>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

import * as figlet from 'figlet';

declare global {
    export namespace figlet {
        /*
         * Parses data from a FIGlet font file and places it into the figFonts object.
         */
        function parseFont(fontName: string, data: string): FontOptions;

        declare module 'figlet/importable-fonts/*' {
            const value: string;
            export default value;
        }
    }
}

// Important to have this line (even if empty...)
declare module 'figlet' {}

Of course, you'll need to update your TypeScript project configuration to load custom types. For example:

// tsconfig.json

{
  "compilerOptions": {
    (...)
    "typeRoots": [
      "src/types",
      "node_modules/@types"
    ]
  },
}

from figlet.js.

patorjk avatar patorjk commented on June 17, 2024

Hi @Nightbr, as you mentioned, DefinitelyTyped/DefinitelyTyped#38318 has been opened over on DefinitelyTyped for this. However, I don't think it'll be worked unless someone submits a PR.

I'm not really familar with TypeScript, but this is what I think the new file should look like:

https://github.com/patorjk/DefinitelyTyped/blob/figlet_fix/types/figlet/index.d.ts

However, I'm not on a computer where I can run the DefinitelyTyped code. If you want to put in PR for this fix definitely do so. Otherwise if I get some time tonight I'll try and put in a PR with the above branch (all I did for that was put in the line I think is missing).

from figlet.js.

Yingrjimsch avatar Yingrjimsch commented on June 17, 2024

Hi there. I got a similar error. I'm building a npm package, which should contain figlet. If I test it I get following error:
http://localhost:4200/fonts/Standard.flf 404 (Not Found) somehow the npm package does not find the correct font.

index.js file

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

Does someone has an idea what I'm doing wrong?

Edit: If I import both figlet and a font like following it works. Is there a method I don't have to import the font seperately? Is it possible to expose all fonts per default?

import figlet from 'figlet';
import standard from 'figlet/importable-fonts/Standard.js'

figlet.parseFont('Standard', standard);

figlet.text('test', {
    font: 'Standard',
}, function(err, data) {
    console.log(data);
});

from figlet.js.

patorjk avatar patorjk commented on June 17, 2024

I would accept a PR.

from figlet.js.

elgs avatar elgs commented on June 17, 2024

It's 2021, why do we still want to support webpack. Why not just support native ES code and everybody can use it without webpack?

from figlet.js.

Nightbr avatar Nightbr commented on June 17, 2024

@elgs sure thing, make a PR to refactor this lib into a native ES module and it could be bundle with any ES bundler 👌

from figlet.js.

wujibear avatar wujibear commented on June 17, 2024

Does this have es support now then?

from figlet.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.