Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszchudyk committed Aug 9, 2022
1 parent 5f3bc84 commit 39355e6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions src/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as utils from './utils';
//
// From X to bytes.
//
export function fromBinary(str: string, little_endian: boolean) {
export function fromBinary(str: string, isLittleEndian: boolean) {
if (!str) {
return undefined;
}
Expand All @@ -17,7 +17,7 @@ export function fromBinary(str: string, little_endian: boolean) {
}
}

if (!little_endian) {
if (!isLittleEndian) {
result = utils.switchEndian(result);
}
return result;
Expand Down Expand Up @@ -50,15 +50,15 @@ function decToBin(str: string) {
return result;
}

export function fromDecimal(str: string, little_endian: boolean) {
export function fromDecimal(str: string, isLittleEndian: boolean) {
if (!str) {
return undefined;
}

return fromBinary(decToBin(str), little_endian);
return fromBinary(decToBin(str), isLittleEndian);
}

export function fromHexadecimal(str: string, little_endian: boolean) {
export function fromHexadecimal(str: string, isLittleEndian: boolean) {
if (!str) {
return undefined;
}
Expand All @@ -69,7 +69,7 @@ export function fromHexadecimal(str: string, little_endian: boolean) {
result[i] = parseInt(str[2 * i], 16) + (2 * i + 1 < str.length ? 16 * parseInt(str[2 * i + 1], 16) : 0);
}

if (!little_endian) {
if (!isLittleEndian) {
result = utils.switchEndian(result);
}
return result;
Expand Down
14 changes: 7 additions & 7 deletions src/input_handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export type MapFormToFunction = {

abstract class InputHandler {
abstract parse(str: string) : string;
abstract convert(str: string, little_endian : boolean) : Uint8Array;
abstract convert(str: string, isLittleEndian : boolean) : Uint8Array;
abstract getFormsMap() : MapFormToFunction;
}

Expand All @@ -58,8 +58,8 @@ class InputHandlerBinary extends InputHandler {
}
}

convert(str: string, little_endian : boolean) {
return converters.fromBinary(str, little_endian);
convert(str: string, isLittleEndian : boolean) {
return converters.fromBinary(str, isLittleEndian);
}

getFormsMap() {
Expand Down Expand Up @@ -91,8 +91,8 @@ class InputHandlerDecimal extends InputHandler {
}
}

convert(str: string, little_endian : boolean) {
return converters.fromDecimal(str, little_endian);
convert(str: string, isLittleEndian : boolean) {
return converters.fromDecimal(str, isLittleEndian);
}

getFormsMap() {
Expand Down Expand Up @@ -125,8 +125,8 @@ class InputHandlerHexadecimal extends InputHandler {
}
}

convert(str: string, little_endian : boolean) {
return converters.fromHexadecimal(str, little_endian);
convert(str: string, isLittleEndian : boolean) {
return converters.fromHexadecimal(str, isLittleEndian);
}

getFormsMap() {
Expand Down

0 comments on commit 39355e6

Please sign in to comment.