switch from deprecated types

This commit is contained in:
Moon Man 2024-01-28 18:40:22 -05:00
parent f2baff2816
commit 996fea2eeb
3 changed files with 37 additions and 32 deletions

40
dist/bert.d.ts vendored
View File

@ -1,26 +1,26 @@
/// <reference types="node" /> /// <reference types="node" />
export declare const Types: { export declare const Types: {
BERT_START: number; readonly BERT_START: 131;
SMALL_ATOM: number; readonly SMALL_ATOM: 119;
ATOM: number; readonly ATOM: 118;
BINARY: number; readonly BINARY: 109;
SMALL_INTEGER: number; readonly SMALL_INTEGER: 97;
INTEGER: number; readonly INTEGER: 98;
SMALL_BIG: number; readonly SMALL_BIG: 110;
LARGE_BIG: number; readonly LARGE_BIG: 111;
FLOAT: number; readonly FLOAT: 99;
STRING: number; readonly STRING: 107;
LIST: number; readonly LIST: 108;
SMALL_TUPLE: number; readonly SMALL_TUPLE: 104;
LARGE_TUPLE: number; readonly LARGE_TUPLE: 105;
MAP: number; readonly MAP: 116;
NIL: number; readonly NIL: 106;
NEW_FLOAT: number; readonly NEW_FLOAT: 70;
ZERO: number; readonly ZERO: 0;
}; };
export declare const Lang: { export declare const Lang: {
ELIXIR: number; readonly ELIXIR: 0;
ERLANG: number; readonly ERLANG: 1;
}; };
export declare class Bert { export declare class Bert {
#private; #private;
@ -29,7 +29,7 @@ export declare class Bert {
private decodeUndefinedValues; private decodeUndefinedValues;
private convention; private convention;
private outputBuffer; private outputBuffer;
constructor(allBinariesAsString?: boolean, mapKeyAsAtom?: boolean, decodeUndefinedValues?: boolean, convention?: number); constructor(allBinariesAsString?: boolean, mapKeyAsAtom?: boolean, decodeUndefinedValues?: boolean, convention?: 0 | 1);
toAtom: (str: string) => { toAtom: (str: string) => {
type: string; type: string;
value: string; value: string;

4
dist/bert.js vendored
View File

@ -1,7 +1,7 @@
export const Types = { export const Types = {
BERT_START: 131, BERT_START: 131,
SMALL_ATOM: 115, SMALL_ATOM: 119,
ATOM: 100, ATOM: 118,
BINARY: 109, BINARY: 109,
SMALL_INTEGER: 97, SMALL_INTEGER: 97,
INTEGER: 98, INTEGER: 98,

View File

@ -1,7 +1,7 @@
export const Types = { export const Types = {
BERT_START: 131, BERT_START: 131,
SMALL_ATOM: 115, SMALL_ATOM: 119,
ATOM: 100, ATOM: 118,
BINARY: 109, BINARY: 109,
SMALL_INTEGER: 97, SMALL_INTEGER: 97,
INTEGER: 98, INTEGER: 98,
@ -16,12 +16,12 @@ export const Types = {
NIL: 106, NIL: 106,
NEW_FLOAT: 70, NEW_FLOAT: 70,
ZERO: 0, ZERO: 0,
}; } as const;
export const Lang = { export const Lang = {
ELIXIR: 0, ELIXIR: 0,
ERLANG: 1, ERLANG: 1,
}; } as const;
export class Bert { export class Bert {
private allBinariesAsString; private allBinariesAsString;
@ -34,7 +34,7 @@ export class Bert {
allBinariesAsString = false, allBinariesAsString = false,
mapKeyAsAtom = true, mapKeyAsAtom = true,
decodeUndefinedValues = true, decodeUndefinedValues = true,
convention = Lang.ELIXIR, convention: 0 | 1 = Lang.ELIXIR,
) { ) {
this.allBinariesAsString = allBinariesAsString; this.allBinariesAsString = allBinariesAsString;
this.mapKeyAsAtom = mapKeyAsAtom; this.mapKeyAsAtom = mapKeyAsAtom;
@ -303,23 +303,28 @@ export class Bert {
let value: any = buffer.toString("utf8", 0, size); let value: any = buffer.toString("utf8", 0, size);
if (value === "true") { if (value === "true") {
value = true; value = true;
} else if (value === "false") { }
else if (value === "false") {
value = false; value = false;
} else if ( }
else if (
this.decodeUndefinedValues && this.decodeUndefinedValues &&
this.convention === Lang.ELIXIR && this.convention === Lang.ELIXIR &&
value === "nil" value === "nil"
) { ) {
value = null; value = null;
} else if ( }
else if (
this.decodeUndefinedValues && this.decodeUndefinedValues &&
this.convention === Lang.ERLANG && this.convention === Lang.ERLANG &&
value === "undefined" value === "undefined"
) { ) {
value = null; value = null;
} else { }
else {
value = this.toAtom(value); value = this.toAtom(value);
} }
return { return {
value, value,
rest: buffer.subarray(size), rest: buffer.subarray(size),
@ -391,7 +396,7 @@ export class Bert {
}; };
decode_string = (buffer: Buffer) => { 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); const size = this.bytesToInt(buffer, sizeLen, true);
buffer = buffer.subarray(sizeLen); buffer = buffer.subarray(sizeLen);