-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
馃 Merge PR #68765 feat: add magika types by @glassonion1
- Loading branch information
1 parent
1995658
commit 72bce2c
Showing
5 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
* | ||
!**/*.d.ts | ||
!**/*.d.cts | ||
!**/*.d.mts | ||
!**/*.d.*.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |