From 23aad516996708d2b4fe2431fe0241da005facf9 Mon Sep 17 00:00:00 2001 From: Mathis Date: Wed, 15 May 2024 11:44:11 +0200 Subject: [PATCH] feat: Add converters utility file This commit introduces a new utility file for various data conversions. This new file, converters.util.ts, includes functions to convert case for strings and convert between boolean values and buffers. --- src/utils/converters.util.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/utils/converters.util.ts diff --git a/src/utils/converters.util.ts b/src/utils/converters.util.ts new file mode 100644 index 0000000..dc96289 --- /dev/null +++ b/src/utils/converters.util.ts @@ -0,0 +1,12 @@ +const ConvertersUtils = { + toUpperCase: (str: string) => String(str).toUpperCase(), + toLowerCase: (str: string) => String(str).toLowerCase(), + bufferToBool: (buf: ArrayBuffer) => { + return new Uint8Array(buf)[0] !== 0; + }, + boolToBuffer: (bol: boolean) => { + return new Uint8Array([bol ? 1 : 0]).buffer; + } +} + +export default ConvertersUtils; \ No newline at end of file