npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

magika

v0.2.13

Published

A tool to detect content types with deep learning.

Downloads

2,627

Readme

Magika TypeScript/JavaScript library

Use Magika in the browser or in Node!

Installing MagikaJS

npm install magika

Using MagikaJS

Simple usage in Node:

import { readFile } from "fs/promises";
import { MagikaNode as Magika } from "magika";

const data = await readFile("some file");
const magika = new Magika();
await magika.load();
const prediction = await magika.identifyBytes(data);
console.log(prediction);

Simple usage in the browser:

import { Magika } from "magika";

const file = new File(["# Hello I am a markdown file"], "hello.md");
const fileBytes = new Uint8Array(await file.arrayBuffer());
const magika = new Magika();
await magika.load();
const prediction = await magika.identifyBytes(fileBytes);
console.log(prediction);

For more, see our documentation.

Commmand-line tool

Please use the official CLI (with pip install magika) as it can perform batch processing and search for files recursivelyw. Read more about that in the main README. This one is useful to load the TensorflowJS model and see that it works as expected.

Install it with npm install -g magika. You can then run it by executing magika-js <some files>

Magika JS - file type detection with ML. https://google.github.io/magika

Arguments:
  paths                      Paths of the files to detect

Options:
  --json-output              Format output in JSON
  --model-url <model-url>    Model URL (default: "https://google.github.io/magika/model/model.json")
  --config-url <config-url>  Config  URL (default: "https://google.github.io/magika/model/config.json")
  -h, --help                 display help for command

Reporting false positives

Please open an issue on Github.

Citation

If you use this software for your research, please cite it as:

@software{magika,
author = {Fratantonio, Yanick and Bursztein, Elie and Invernizzi, Luca and Zhang, Marina and Metitieri, Giancarlo and Kurt, Thomas and Galilee, Francois and Petit-Bianco, Alexandre and Farah, Loua and Albertini, Ange},
title = {{Magika content-type scanner}},
url = {https://github.com/google/magika}
}

Loading the model and configuration

MagikaJS is designed flexible in how you provide the model and configuration file to it.

Both the Node and browser versions accept URLs to asyncronously load these two assets.

await magika.load({
        modelURL: "https://...",
        configURL: "https://...",
    });

The Node version also allows to load local files.

await magika.load({
        modelPath: './assets/...',
        configPath: './assets/...'
    });

Development

Using the model hosted On Github:

yarn install
yarn run build
yarn run bin -- README.md

Using the local model:

yarn install
yarn run build
(cd ../website; yarn install; yarn run dev) &
yarn run bin --model-url http://localhost:5173/magika/model/model.json --config-url http://localhost:5173/magika/model/config.json ../tests_data/mitra/*

Testing

Execute:

yarn install
yarn run build
yarn run test