From 2eaa150c0d9ebcb002bf8824df7823be53f19b44 Mon Sep 17 00:00:00 2001 From: Per Kristian Kummermo Date: Tue, 8 May 2018 13:50:59 +0200 Subject: [PATCH] feat(mappers): type constructors. Fixes #2 --- src/mappers/Base64.ts | 6 +++++- src/mappers/FromJSON.ts | 6 +++++- src/mappers/HexToFloat.ts | 7 +++++-- src/mappers/HexToInt.ts | 7 ++++++- src/mappers/Offset.ts | 6 +++++- 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/mappers/Base64.ts b/src/mappers/Base64.ts index 526260a..c5a56ce 100644 --- a/src/mappers/Base64.ts +++ b/src/mappers/Base64.ts @@ -5,6 +5,10 @@ export enum Base64Actions { DECODE = "decode", } +export interface IBase64Config { + action?: Base64Actions; +} + export class Base64 implements IMapper { static ident: string = "BASE64"; static description: string = "Base64"; @@ -14,7 +18,7 @@ export class Base64 implements IMapper { constructor({ action = Base64Actions.DECODE, - } = {}) { + }: IBase64Config = {}) { this.action = action; } diff --git a/src/mappers/FromJSON.ts b/src/mappers/FromJSON.ts index 59035cb..985e11c 100644 --- a/src/mappers/FromJSON.ts +++ b/src/mappers/FromJSON.ts @@ -1,5 +1,9 @@ import { IDataValue, IMapper, IMapperConfig } from "./../Models"; +export interface IFromJSONConfig { + propertyString?: string; +} + export class FromJSON implements IMapper { static ident: string = "FROMJSON"; static description: string = "JSON"; @@ -9,7 +13,7 @@ export class FromJSON implements IMapper { constructor({ propertyString = "", - } = {}) { + }: IFromJSONConfig = {}) { this.propertyString = propertyString; } diff --git a/src/mappers/HexToFloat.ts b/src/mappers/HexToFloat.ts index d821c1a..2374cc5 100644 --- a/src/mappers/HexToFloat.ts +++ b/src/mappers/HexToFloat.ts @@ -1,7 +1,10 @@ - import { Endianness } from "../Config"; import { IDataValue, IMapper, IMapperConfig } from "./../Models"; +export interface IHexToFloatConfig { + endianness?: Endianness; +} + export class HexToFloat implements IMapper { static ident: string = "HEXTOFLOAT"; static description: string = "Hex to float"; @@ -11,7 +14,7 @@ export class HexToFloat implements IMapper { constructor({ endianness = Endianness.BIG_ENDIAN, - } = {}) { + }: IHexToFloatConfig = {}) { this.endianness = endianness; } diff --git a/src/mappers/HexToInt.ts b/src/mappers/HexToInt.ts index 040281f..93e5104 100644 --- a/src/mappers/HexToInt.ts +++ b/src/mappers/HexToInt.ts @@ -1,6 +1,11 @@ import { Endianness } from "../Config"; import { IDataValue, IMapper, IMapperConfig } from "./../Models"; +export interface IHexToIntConfig { + endianness?: Endianness; + signed?: boolean; +} + export class HexToInt implements IMapper { static ident: string = "HEXTOINT"; static description: string = "Hex to int"; @@ -13,7 +18,7 @@ export class HexToInt implements IMapper { constructor({ endianness = Endianness.BIG_ENDIAN, signed = false, - } = {}) { + }: IHexToIntConfig = {}) { this.endianness = endianness; this.signed = signed; } diff --git a/src/mappers/Offset.ts b/src/mappers/Offset.ts index ef74faf..4b1b3ef 100644 --- a/src/mappers/Offset.ts +++ b/src/mappers/Offset.ts @@ -1,5 +1,9 @@ import { IDataValue, IMapper, IMapperConfig } from "./../Models"; +export interface IOffsetConfig { + offset?: number | string; +} + export class Offset implements IMapper { static ident: string = "OFFSET"; static description: string = "Offset number"; @@ -8,7 +12,7 @@ export class Offset implements IMapper { constructor({ offset = "0", - } = {}) { + }: IOffsetConfig = {}) { this.offset = parseInt(offset.toString(), 10); }