Introduce some functional programming techniques

This commit is contained in:
Dolan
2018-11-02 02:51:57 +00:00
parent 9cfd835171
commit 7980f14efb
108 changed files with 749 additions and 659 deletions

View File

@ -1,20 +1,20 @@
export interface IMediaDataDimensions {
pixels: {
x: number;
y: number;
readonly pixels: {
readonly x: number;
readonly y: number;
};
emus: {
x: number;
y: number;
readonly emus: {
readonly x: number;
readonly y: number;
};
}
export interface IMediaData {
referenceId: number;
stream: Buffer | Uint8Array | ArrayBuffer;
path?: string;
fileName: string;
dimensions: IMediaDataDimensions;
readonly referenceId: number;
readonly stream: Buffer | Uint8Array | ArrayBuffer;
readonly path?: string;
readonly fileName: string;
readonly dimensions: IMediaDataDimensions;
}
// Needed because of: https://github.com/s-panferov/awesome-typescript-loader/issues/432

View File

@ -5,6 +5,7 @@ import { IMediaData } from "./data";
import { Image } from "./image";
interface IHackedFile {
// tslint:disable-next-line:readonly-keyword
currentRelationshipId: number;
}
@ -78,17 +79,15 @@ export class Media {
private createMedia(
key: string,
relationshipsCount: number,
dimensions: { width: number; height: number },
dimensions: { readonly width: number; readonly height: number },
data: Buffer | string | Uint8Array | ArrayBuffer,
filePath?: string,
): IMediaData {
if (typeof data === "string") {
data = this.convertDataURIToBinary(data);
}
const newData = typeof data === "string" ? this.convertDataURIToBinary(data) : data;
const imageData = {
const imageData: IMediaData = {
referenceId: relationshipsCount,
stream: data,
stream: newData,
path: filePath,
fileName: key,
dimensions: {