chore: apply code fixes with biome

This commit is contained in:
PalmDevs
2023-11-28 22:03:41 +07:00
parent c80bd068fa
commit f2d85c32a4
32 changed files with 1384 additions and 1383 deletions

View File

@@ -1,41 +1,41 @@
import { Packet } from '../schemas/Packet.js'
import {
ClientOperation,
Operation,
ServerOperation,
} from '../constants/Operation.js'
/**
* Checks whether a packet is trying to do the given operation
* @param op Operation code to check
* @param packet A packet
* @returns Whether this packet is trying to do the operation given
*/
export function packetMatchesOperation<TOp extends Operation>(
op: TOp,
packet: Packet
): packet is Packet<TOp> {
return packet.op === op
}
/**
* Checks whether this packet is a client packet **(this does NOT validate the data)**
* @param packet A packet
* @returns Whether this packet is a client packet
*/
export function isClientPacket(
packet: Packet
): packet is Packet<ClientOperation> {
return packet.op in ClientOperation
}
/**
* Checks whether this packet is a server packet **(this does NOT validate the data)**
* @param packet A packet
* @returns Whether this packet is a server packet
*/
export function isServerPacket(
packet: Packet
): packet is Packet<ServerOperation> {
return packet.op in ServerOperation
}
import {
ClientOperation,
Operation,
ServerOperation,
} from '../constants/Operation.js'
import { Packet } from '../schemas/Packet.js'
/**
* Checks whether a packet is trying to do the given operation
* @param op Operation code to check
* @param packet A packet
* @returns Whether this packet is trying to do the operation given
*/
export function packetMatchesOperation<TOp extends Operation>(
op: TOp,
packet: Packet,
): packet is Packet<TOp> {
return packet.op === op
}
/**
* Checks whether this packet is a client packet **(this does NOT validate the data)**
* @param packet A packet
* @returns Whether this packet is a client packet
*/
export function isClientPacket(
packet: Packet,
): packet is Packet<ClientOperation> {
return packet.op in ClientOperation
}
/**
* Checks whether this packet is a server packet **(this does NOT validate the data)**
* @param packet A packet
* @returns Whether this packet is a server packet
*/
export function isServerPacket(
packet: Packet,
): packet is Packet<ServerOperation> {
return packet.op in ServerOperation
}

View File

@@ -1,3 +1,3 @@
export * from './guard.js'
export * from './serialization.js'
export * from './string.js'
export * from './guard.js'
export * from './serialization.js'
export * from './string.js'

View File

@@ -1,23 +1,23 @@
import * as BSON from 'bson'
import { Packet, PacketSchema } from '../schemas/index.js'
import { Operation } from '../constants/index.js'
import { parse } from 'valibot'
/**
* Compresses a packet into a buffer
* @param packet The packet to compress
* @returns A buffer of the compressed packet
*/
export function serializePacket<TOp extends Operation>(packet: Packet<TOp>) {
return BSON.serialize(packet)
}
/**
* Decompresses a buffer into a packet
* @param buffer The buffer to decompress
* @returns A packet
*/
export function deserializePacket(buffer: Buffer) {
const data = BSON.deserialize(buffer)
return parse(PacketSchema, data) as Packet
}
import * as BSON from 'bson'
import { parse } from 'valibot'
import { Operation } from '../constants/index.js'
import { Packet, PacketSchema } from '../schemas/index.js'
/**
* Compresses a packet into a buffer
* @param packet The packet to compress
* @returns A buffer of the compressed packet
*/
export function serializePacket<TOp extends Operation>(packet: Packet<TOp>) {
return BSON.serialize(packet)
}
/**
* Decompresses a buffer into a packet
* @param buffer The buffer to decompress
* @returns A packet
*/
export function deserializePacket(buffer: Buffer) {
const data = BSON.deserialize(buffer)
return parse(PacketSchema, data) as Packet
}

View File

@@ -1,8 +1,8 @@
/**
* Uncapitalizes the first letter of a string
* @param str The string to uncapitalize
* @returns The uncapitalized string
*/
export function uncapitalize<T extends string>(str: T): Uncapitalize<T> {
return (str.charAt(0).toLowerCase() + str.slice(1)) as Uncapitalize<T>
}
/**
* Uncapitalizes the first letter of a string
* @param str The string to uncapitalize
* @returns The uncapitalized string
*/
export function uncapitalize<T extends string>(str: T): Uncapitalize<T> {
return (str.charAt(0).toLowerCase() + str.slice(1)) as Uncapitalize<T>
}