0
0
mirror of https://github.com/sp-tarkov/server.git synced 2025-02-13 09:50:43 -05:00
server/project/src/utils/EncodingUtil.ts
Refringe 5740774a46
Apply Biome Formatting
This is the result of running `npm run format` which applies the Biome formatting rules. Rejoice!
2024-07-23 11:12:53 -04:00

37 lines
891 B
TypeScript

import { injectable } from "tsyringe";
@injectable()
export class EncodingUtil {
public encode(value: string, encode: EncodeType): string {
return Buffer.from(value).toString(encode);
}
public decode(value: string, encode: EncodeType): string {
return Buffer.from(value, encode).toString(EncodeType.UTF8);
}
public fromBase64(value: string): string {
return this.decode(value, EncodeType.BASE64);
}
public toBase64(value: string): string {
return this.encode(value, EncodeType.BASE64);
}
public fromHex(value: string): string {
return this.decode(value, EncodeType.HEX);
}
public toHex(value: string): string {
return this.encode(value, EncodeType.HEX);
}
}
export enum EncodeType {
BASE64 = "base64",
HEX = "hex",
ASCII = "ascii",
BINARY = "binary",
UTF8 = "utf8",
}