Added types to modules without types

This commit is contained in:
Jonathan Barrow
2023-04-27 15:05:22 -04:00
parent 84c2086da2
commit d6d92ca27c
7 changed files with 525 additions and 393 deletions

794
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -61,15 +61,19 @@
"@types/dicer": "^0.2.2",
"@types/express": "^4.17.17",
"@types/fs-extra": "^11.0.1",
"@types/mongoose-unique-validator": "^1.0.7",
"@types/morgan": "^1.9.4",
"@types/ndarray": "^1.0.11",
"@types/node": "^18.14.4",
"@types/node-rsa": "^1.1.1",
"@types/nodemailer": "^6.4.7",
"@types/qs": "^6.9.7",
"@types/validator": "^13.7.14",
"@types/w3c-css-typed-object-model-level-1": "^20180410.0.5",
"@typescript-eslint/eslint-plugin": "^5.54.1",
"@typescript-eslint/parser": "^5.54.1",
"eslint": "^8.35.0",
"ndarray": "^1.0.19",
"prompt": "^1.0.0",
"typescript": "^4.9.5",
"yesno": "^0.4.0"

View File

@@ -176,12 +176,8 @@ PNIDSchema.method('generateMiiImages', async function generateMiiImages(): Promi
instanceCount: 1,
});
const miiStudioNormalFaceImageData: Buffer = await got(miiStudioUrl).buffer();
const pngData: {
width: number;
height: number;
data: Buffer;
} = await imagePixels(miiStudioNormalFaceImageData);
const tga: Buffer = TGA.createTgaBuffer(pngData.width, pngData.height, pngData.data);
const pngData: ImageData = await imagePixels(miiStudioNormalFaceImageData);
const tga: Buffer = TGA.createTgaBuffer(pngData.width, pngData.height, Uint8Array.from(pngData.data), false);
const userMiiKey: string = `mii/${this.get('pid')}`;

View File

@@ -1,3 +1,16 @@
declare module 'express-subdomain';
// * Credit to https://github.com/bmullan91/express-subdomain/pull/61 for the types!
// TODO - Add proper types
declare module 'express-subdomain'{
import type { Request, Response, Router } from 'express';
/**
* @description The subdomain function.
* @param subdomain The subdomain to listen on.
* @param fn The listener function, takes a response and request.
* @returns A function call to the value passed as FN, or void (the next function).
*/
export default function subdomain(
subdomain: string,
fn: Router | ((req: Request, res: Response) => void | any)
): (req: Request, res: Response, next: () => void) => void | typeof fn;
}

View File

@@ -1,3 +1,34 @@
declare module 'image-pixels';
declare module 'image-pixels' {
import { NdArray } from 'ndarray';
// TODO - Add proper types
export interface ImagePixelsOptions {
source: ImageSource;
shape: [number, number];
width: number;
height: number;
type: string;
mime: string;
clip: [number, number, number, number] | {
x?: number;
y?: number;
width?: number;
height?: number;
};
cache: boolean;
}
export type ImageSource = string |
HTMLImageElement | SVGImageElement | HTMLVideoElement | CSSImageValue |
typeof Image | ImageData | ImageBitmap |
File | Blob |
//Canvas | Context2D |
//WebGLContext |
Buffer | ArrayBuffer | Uint8Array | Uint8ClampedArray |
Float32Array | Float64Array | Array<number> | Array<Array<number>> |
NdArray |
ImagePixelsOptions;
export default function pixels(
src: ImageSource | Promise<ImageSource>
): ImageData;
}

View File

@@ -1 +0,0 @@
declare module 'mongoose-unique-validator';

59
src/types/tga.d.ts vendored
View File

@@ -1,3 +1,58 @@
declare module 'tga';
declare module 'tga' {
export interface TGAHeader {
idLength: number;
colorMapType: number;
dataType: number;
colorMapOrigin: number;
colorMapLength: number;
colorMapDepth: number;
xOrigin: number;
yOrigin: number;
width: number;
height: number;
bitsPerPixel: number;
flags: number;
id: string;
}
// TODO - Add proper types
export default class TGA {
constructor(buf: Buffer, opt?: { dontFixAlpha: boolean });
static createTgaBuffer(width: number, height: number, pixels: Uint8Array, dontFlipY: boolean): Buffer;
parseHeader(): void;
parseFooter(): void;
parseExtension(extensionAreaOffset: number): void;
readColor(offset: number, bytesPerPixel: number): Uint8Array;
readColorWithColorMap(offset: number): Uint8Array;
readColorAuto(offset: number, bytesPerPixel: number, isUsingColorMap: boolean): Uint8Array;
parseColorMap(): void;
setPixel(pixels: Uint8Array, idx: number, color: Uint8Array): void;
parsePixels(): void;
parse(): void;
fixForAlpha(): void;
public dontFixAlpha: boolean;
public _buff: Buffer;
public data: Uint8Array;
public currentOffset: number;
public header: TGAHeader;
public width: number;
public height: number;
public isUsingColorMap: boolean;
public isUsingRLE: boolean;
public isGray: boolean;
public hasAlpha: boolean;
public isFlipX: boolean;
public isFlipY: boolean;
public colorMap: Uint8Array;
public pixels: Uint8Array;
}
}