Git Product home page Git Product logo

Comments (11)

invernizzi avatar invernizzi commented on May 23, 2024 2

Thanks for the quick check! Agreed on both points. 0.2.12 accepts Uint8Array and drops Buffer for non-Node magika.

from magika.

elhadjaoui avatar elhadjaoui commented on May 23, 2024

facing the same issue :
Could not find a declaration file for module 'magika'. '/node_modules/magika/magika.js' implicitly has an 'any' type.

from magika.

reyammer avatar reyammer commented on May 23, 2024

Thanks for reporting, looking into it.

from magika.

reyammer avatar reyammer commented on May 23, 2024

See #129, not sure if it's related.

from magika.

glassonion1 avatar glassonion1 commented on May 23, 2024

I tried adding types to DefinitelyTyped to use Magika with TypeScript. However, I encountered the following error, and the tests did not pass. Does Magika not support CommonJS?

A require call resolved to an ESM JavaScript file, which is an error in Node and some bundlers.
CommonJS consumers will need to use a dynamic import.

DefinitelyTyped's pull request is below:
DefinitelyTyped/DefinitelyTyped#68765

from magika.

glassonion1 avatar glassonion1 commented on May 23, 2024

@reyammer
It appears that Magica doesn't seem to support CommonJS, as shown in #129. This suggests that we should be able to add types to DefinitelyTyped.

module.exports = { Magika };

from magika.

glassonion1 avatar glassonion1 commented on May 23, 2024

@chris-si
I have added type definitions for Magika to DefinitelyTyped. With this, you can now run it in TypeScript without any errors.

npm: https://www.npmjs.com/package/@types/magika

Please execute the following command.

npm install --save-dev @types/magika

or

pnpm add -D @types/magika

Additional information:
Magika did not support CommonJS and didn't pass the tests at DefinitelyTyped, the DefinitelyTyped team has been modified to allow the tests to pass even if the library does not support CommonJS.

from magika.

invernizzi avatar invernizzi commented on May 23, 2024

We've published a version with commonJS support, and the library has been rewritten in Typescript as of yesterday.
Our types should be bundled with the package. Please take a look and let me know if they are as expected.

from magika.

chris-si avatar chris-si commented on May 23, 2024

That's great to hear! I'll give it a try in the coming days.

from magika.

glassonion1 avatar glassonion1 commented on May 23, 2024

That's great. I tried 0.2.10 out right away.

I'm using Magika as a client application. While doing so, I encountered an issue concerning the argument types of the identifyBytesFull and identifyBytes methods.
The type of fileBytes being Uint16Array | Buffer required the following configuration in webpack.

// webpack.config.js
module.exports = {
  //...
  resolve: {
    fallback: {
      fs: false
    }
  },
};

Buffer is a type specific to Node.js and is not suitable for use in the browser. Additionally, for files used in the browser, the type Uint8Array is more commonly used instead of Uint16Array.
I would like the type of fileBytes to be changed to Uint8Array for comfortable use in a browser environment.

from magika.

chris-si avatar chris-si commented on May 23, 2024

I tried it out and it works like expected! Thanks for improving the js/ts lib!

from magika.

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.