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"] +}