Skip to content

Commit

Permalink
support typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
wuriyanto48 committed Jan 10, 2023
1 parent 9d6c4d4 commit f3d2da5
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 2 deletions.
2 changes: 2 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const _exports: typeof import("./lib/validator");
export = _exports;
32 changes: 32 additions & 0 deletions dist/lib/signature.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export const AVIF: any;
export const BMP: any;
export const DIB_0: any;
export const DIB_1: any;
export const GIF: any;
export const TIFF: any;
export const MP3: any;
export const MPG_0: any;
export const MPG_1: any;
export const FLV: any;
export const APK: any;
export const MS_OFFICE: any;
export const JAR: any;
export const SWF_0: any;
export const SWF_1: any;
export const PNG: any;
export const JPEG: any;
export const MP4_0: any;
export const MP4_1: any;
export const MP4_2: any;
export const THREE_GP_0: any;
export const THREE_GP_1: any;
export const THREE_GP_2: any;
export const MKV: any;
export const PDF: any;
export const RAR: any;
export const GZIP: any;
export const ZIP_0: any;
export const ZIP_1: any;
export const ZIP_2: any;
export const WEBP: any;
export const SVG: any;
30 changes: 30 additions & 0 deletions dist/lib/validator.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Check if buffer is one of the predefined file types function
* @param buffer {Buffer}
* @param fns {Array<function>}
* @returns {boolean|Error}
*/
export function oneOf(buffer: Buffer, ...fns: Array<Function>): boolean | Error;
export function isPng(buffer: any): boolean | Error;
export function isAvif(buffer: any): boolean | Error;
export function isBmp(buffer: any): boolean | Error;
export function isDib(buffer: any): boolean;
export function isGif(buffer: any): boolean | Error;
export function isTiff(buffer: any): boolean | Error;
export function isMp3(buffer: any): boolean | Error;
export function isMpg(buffer: any): boolean;
export function isFlv(buffer: any): boolean | Error;
export function isApk(buffer: any): boolean | Error;
export function isMsOffice(buffer: any): boolean | Error;
export function isJar(buffer: any): boolean | Error;
export function isSwf(buffer: any): boolean;
export function isJpeg(buffer: any): boolean | Error;
export function isMp4(buffer: any): boolean;
export function is3gp(buffer: any): boolean;
export function isMkv(buffer: any): boolean | Error;
export function isPdf(buffer: any): boolean | Error;
export function isRar(buffer: any): boolean | Error;
export function isGzip(buffer: any): boolean | Error;
export function isZip(buffer: any): boolean;
export function isWebp(buffer: any): boolean | Error;
export function isSvg(buffer: any): boolean | Error;
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"name": "filesig",
"version": "1.0.2",
"version": "1.0.3",
"description": "small library to validate Files by reading each magic number from a file",
"main": "index.js",
"types": "dist/index.d.ts",
"scripts": {
"build:types": "npx tsc",
"test": "./node_modules/.bin/nyc ./node_modules/.bin/mocha",
"test:cover": "./node_modules/.bin/nyc --reporter=cobertura --reporter=text-summary ./node_modules/.bin/mocha"
},
Expand All @@ -22,6 +24,7 @@
],
"devDependencies": {
"mocha": "^9.2.1",
"nyc": "^15.1.0"
"nyc": "^15.1.0",
"typescript": "^4.9.4"
}
}
19 changes: 19 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
// Change this to match your project
"include": ["lib/**/*", "index.js"],

"compilerOptions": {
// Tells TypeScript to read JS files, as
// normally they are ignored as source files
"allowJs": true,
// Generate d.ts files
"declaration": true,
// This compiler run should
// only output d.ts files
"emitDeclarationOnly": true,
// Types should go into this directory.
// Removing this would place the .d.ts files
// next to the .js files
"outDir": "dist",
},
}

0 comments on commit f3d2da5

Please sign in to comment.