- /**
- * Convert websocket error code to human readable string message
- *
- * @param code - websocket error code
- * @returns human readable string message
- */
- public static getWebSocketCloseEventStatusString(code: number): string {
- if (code >= 0 && code <= 999) {
- return '(Unused)';
- } else if (code >= 1016) {
- if (code <= 1999) {
- return '(For WebSocket standard)';
- } else if (code <= 2999) {
- return '(For WebSocket extensions)';
- } else if (code <= 3999) {
- return '(For libraries and frameworks)';
- } else if (code <= 4999) {
- return '(For applications)';
+export const JSONStringify = <
+ T extends
+ | JsonType
+ | Array<Record<string, unknown>>
+ | Set<Record<string, unknown>>
+ | Map<string, Record<string, unknown>>
+>(
+ object: T,
+ space?: string | number,
+ mapFormat?: MapStringifyFormat
+ ): string => {
+ return JSON.stringify(
+ object,
+ (_, value: Record<string, unknown>) => {
+ if (is(Map, value)) {
+ switch (mapFormat) {
+ case MapStringifyFormat.object:
+ return { ...Object.fromEntries<Map<string, Record<string, unknown>>>(value.entries()) }
+ case MapStringifyFormat.array:
+ default:
+ return [...value]
+ }
+ } else if (is(Set, value)) {
+ return [...value] as JsonType[]