From 996fea2eeb2bd4174987be3736bb9af62bf39784 Mon Sep 17 00:00:00 2001 From: Moon Man Date: Sun, 28 Jan 2024 18:40:22 -0500 Subject: [PATCH] switch from deprecated types --- dist/bert.d.ts | 40 ++++++++++++++++++++-------------------- dist/bert.js | 4 ++-- src/bert.ts | 25 +++++++++++++++---------- 3 files changed, 37 insertions(+), 32 deletions(-) diff --git a/dist/bert.d.ts b/dist/bert.d.ts index 607939a..b15d7cc 100644 --- a/dist/bert.d.ts +++ b/dist/bert.d.ts @@ -1,26 +1,26 @@ /// export declare const Types: { - BERT_START: number; - SMALL_ATOM: number; - ATOM: number; - BINARY: number; - SMALL_INTEGER: number; - INTEGER: number; - SMALL_BIG: number; - LARGE_BIG: number; - FLOAT: number; - STRING: number; - LIST: number; - SMALL_TUPLE: number; - LARGE_TUPLE: number; - MAP: number; - NIL: number; - NEW_FLOAT: number; - ZERO: number; + readonly BERT_START: 131; + readonly SMALL_ATOM: 119; + readonly ATOM: 118; + readonly BINARY: 109; + readonly SMALL_INTEGER: 97; + readonly INTEGER: 98; + readonly SMALL_BIG: 110; + readonly LARGE_BIG: 111; + readonly FLOAT: 99; + readonly STRING: 107; + readonly LIST: 108; + readonly SMALL_TUPLE: 104; + readonly LARGE_TUPLE: 105; + readonly MAP: 116; + readonly NIL: 106; + readonly NEW_FLOAT: 70; + readonly ZERO: 0; }; export declare const Lang: { - ELIXIR: number; - ERLANG: number; + readonly ELIXIR: 0; + readonly ERLANG: 1; }; export declare class Bert { #private; @@ -29,7 +29,7 @@ export declare class Bert { private decodeUndefinedValues; private convention; private outputBuffer; - constructor(allBinariesAsString?: boolean, mapKeyAsAtom?: boolean, decodeUndefinedValues?: boolean, convention?: number); + constructor(allBinariesAsString?: boolean, mapKeyAsAtom?: boolean, decodeUndefinedValues?: boolean, convention?: 0 | 1); toAtom: (str: string) => { type: string; value: string; diff --git a/dist/bert.js b/dist/bert.js index 9d3ba64..82a7105 100644 --- a/dist/bert.js +++ b/dist/bert.js @@ -1,7 +1,7 @@ export const Types = { BERT_START: 131, - SMALL_ATOM: 115, - ATOM: 100, + SMALL_ATOM: 119, + ATOM: 118, BINARY: 109, SMALL_INTEGER: 97, INTEGER: 98, diff --git a/src/bert.ts b/src/bert.ts index c249cdb..0f0adba 100644 --- a/src/bert.ts +++ b/src/bert.ts @@ -1,7 +1,7 @@ export const Types = { BERT_START: 131, - SMALL_ATOM: 115, - ATOM: 100, + SMALL_ATOM: 119, + ATOM: 118, BINARY: 109, SMALL_INTEGER: 97, INTEGER: 98, @@ -16,12 +16,12 @@ export const Types = { NIL: 106, NEW_FLOAT: 70, ZERO: 0, -}; +} as const; export const Lang = { ELIXIR: 0, ERLANG: 1, -}; +} as const; export class Bert { private allBinariesAsString; @@ -34,7 +34,7 @@ export class Bert { allBinariesAsString = false, mapKeyAsAtom = true, decodeUndefinedValues = true, - convention = Lang.ELIXIR, + convention: 0 | 1 = Lang.ELIXIR, ) { this.allBinariesAsString = allBinariesAsString; this.mapKeyAsAtom = mapKeyAsAtom; @@ -303,23 +303,28 @@ export class Bert { let value: any = buffer.toString("utf8", 0, size); if (value === "true") { value = true; - } else if (value === "false") { + } + else if (value === "false") { value = false; - } else if ( + } + else if ( this.decodeUndefinedValues && this.convention === Lang.ELIXIR && value === "nil" ) { value = null; - } else if ( + } + else if ( this.decodeUndefinedValues && this.convention === Lang.ERLANG && value === "undefined" ) { value = null; - } else { + } + else { value = this.toAtom(value); } + return { value, rest: buffer.subarray(size), @@ -391,7 +396,7 @@ export class Bert { }; decode_string = (buffer: Buffer) => { - const sizeLen = this.convention === Lang.ELIXIR ? 4 : 2; + const sizeLen = this.convention === Lang.ELIXIR ? 4 : 2; const size = this.bytesToInt(buffer, sizeLen, true); buffer = buffer.subarray(sizeLen);