From 72bce2ce4769ff8f4690edda50ccb33d19878796 Mon Sep 17 00:00:00 2001 From: Taisuke Fujita Date: Fri, 1 Mar 2024 08:56:53 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#68765=20feat:=20ad?= =?UTF-8?q?d=20magika=20types=20by=20@glassonion1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/magika/.npmignore | 5 +++++ types/magika/index.d.ts | 16 ++++++++++++++++ types/magika/magika-tests.ts | 37 ++++++++++++++++++++++++++++++++++++ types/magika/package.json | 18 ++++++++++++++++++ types/magika/tsconfig.json | 14 ++++++++++++++ 5 files changed, 90 insertions(+) create mode 100644 types/magika/.npmignore create mode 100644 types/magika/index.d.ts create mode 100644 types/magika/magika-tests.ts create mode 100644 types/magika/package.json create mode 100644 types/magika/tsconfig.json diff --git a/types/magika/.npmignore b/types/magika/.npmignore new file mode 100644 index 00000000000000..680c524577719f --- /dev/null +++ b/types/magika/.npmignore @@ -0,0 +1,5 @@ +* +!**/*.d.ts +!**/*.d.cts +!**/*.d.mts +!**/*.d.*.ts \ No newline at end of file diff --git a/types/magika/index.d.ts b/types/magika/index.d.ts new file mode 100644 index 00000000000000..8aa508c8980517 --- /dev/null +++ b/types/magika/index.d.ts @@ -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; + identifyBytes(fileBytes: ArrayBuffer): Promise; + identifyBytesFull(fileBytes: ArrayBuffer): Promise; +} diff --git a/types/magika/magika-tests.ts b/types/magika/magika-tests.ts new file mode 100644 index 00000000000000..e01db7ecb1fa91 --- /dev/null +++ b/types/magika/magika-tests.ts @@ -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); +}); diff --git a/types/magika/package.json b/types/magika/package.json new file mode 100644 index 00000000000000..74a1687a7379e6 --- /dev/null +++ b/types/magika/package.json @@ -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" + } + ] +} diff --git a/types/magika/tsconfig.json b/types/magika/tsconfig.json new file mode 100644 index 00000000000000..54e3807e907523 --- /dev/null +++ b/types/magika/tsconfig.json @@ -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"] +}