Skip to content

Commit

Permalink
馃 Merge PR #68765 feat: add magika types by @glassonion1
Browse files Browse the repository at this point in the history
  • Loading branch information
glassonion1 committed Feb 29, 2024
1 parent 1995658 commit 72bce2c
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 0 deletions.
5 changes: 5 additions & 0 deletions types/magika/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*
!**/*.d.ts
!**/*.d.cts
!**/*.d.mts
!**/*.d.*.ts
16 changes: 16 additions & 0 deletions types/magika/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export interface Prediction {
label: string;
score: number;
labels: { [name: string]: number };
}
export interface Option {
modelURL?: string;
configURL?: string;
}

export class Magika {
constructor();
load(config: Option): Promise<void>;
identifyBytes(fileBytes: ArrayBuffer): Promise<Prediction>;
identifyBytesFull(fileBytes: ArrayBuffer): Promise<Prediction>;
}
37 changes: 37 additions & 0 deletions types/magika/magika-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Magika } from "magika";

const func1 = async () => {
const fileBytes = new Uint8Array(new ArrayBuffer(8));
const m = new Magika();
await m.load({});
return await m.identifyBytes(fileBytes);
};

func1().then((prediction) => {
console.log(prediction);
});

const func2 = async () => {
const fileBytes = new Uint8Array(new ArrayBuffer(8));
const m = new Magika();
await m.load({});
return await m.identifyBytesFull(fileBytes);
};

func2().then((prediction) => {
console.log(prediction);
});

const func3 = async () => {
const fileBytes = new Uint8Array(new ArrayBuffer(8));
const m = new Magika();
await m.load({
modelURL: "https://google.github.io/magika/model/model.json",
configURL: "https://google.github.io/magika/model/config.json",
});
return await m.identifyBytes(fileBytes);
};

func3().then((prediction) => {
console.log(prediction);
});
18 changes: 18 additions & 0 deletions types/magika/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"private": true,
"type": "module",
"name": "@types/magika",
"version": "0.2.9999",
"projects": [
"https://github.com/google/magika/tree/main/js"
],
"devDependencies": {
"@types/magika": "workspace:."
},
"owners": [
{
"name": "Taisuke Fujita",
"githubUsername": "glassonion1"
}
]
}
14 changes: 14 additions & 0 deletions types/magika/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"module": "node16",
"lib": ["es6", "dom"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": ["index.d.ts", "magika-tests.ts"]
}

0 comments on commit 72bce2c

Please sign in to comment.