Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add magika types #68765

Merged
merged 6 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]
}