Skip to content
This repository was archived by the owner on Jul 20, 2021. It is now read-only.

Commit ea9f219

Browse files
author
Per Kristian Kummermo
committed
feat(outputtype): add output type for mappers
1 parent 24b2c3e commit ea9f219

File tree

8 files changed

+27
-7
lines changed

8 files changed

+27
-7
lines changed

src/DataMapperChain.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { DataMapperChain } from "./DataMapperChain";
22
import { Mappers } from "./Mappers";
3-
import { IDataValue, IMapper, IMapperConfig } from "./Typings";
3+
import { IDataValue, IMapper, IMapperConfig, IOutputType } from "./Typings";
44

55
const { Base64, Chunk, FromJSON, HexToFloat, HexToInt, Offset } = Mappers;
66

77
class MapperMock implements IMapper {
88
initParams: any = {};
9+
outputType: IOutputType = IOutputType.number;
910

1011
constructor(params = {}) {
1112
this.initParams = params;

src/Typings.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
export type IDataValue = string | number;
2+
export enum IOutputType {
3+
"string",
4+
"number",
5+
"array",
6+
}
27

38
export interface IMapperConfig {
49
id: string;
510
params: any;
611
}
712

813
export interface IMapper {
14+
outputType: IOutputType;
915
transform(data: IDataValue): IDataValue;
1016
config(): IMapperConfig;
1117
}

src/mappers/Base64.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Base64Action } from "../Config";
2-
import { IDataValue, IMapper, IMapperConfig } from "./../Typings";
2+
import { IDataValue, IMapper, IMapperConfig, IOutputType } from "./../Typings";
33

44
export interface IBase64Config {
55
action?: Base64Action;
@@ -10,6 +10,7 @@ export class Base64 implements IMapper {
1010
static description: string = "Base64";
1111

1212
name: string = "Base64";
13+
outputType: IOutputType = IOutputType.string;
1314

1415
action: Base64Action = Base64Action.DECODE;
1516

src/mappers/Chunk.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IDataValue, IMapper, IMapperConfig } from "./../Typings";
1+
import { IDataValue, IMapper, IMapperConfig, IOutputType } from "./../Typings";
22

33
export interface IChunkConfig {
44
// Start-index of chunk
@@ -10,7 +10,10 @@ export interface IChunkConfig {
1010
export class Chunk implements IMapper {
1111
static id: string = "CHUNK";
1212
static description: string = "Chunk";
13+
1314
name: string = "Chunk";
15+
outputType: IOutputType = IOutputType.string;
16+
1417
start: number = 0;
1518
size: number = 4;
1619

src/mappers/FromJSON.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IDataValue, IMapper, IMapperConfig } from "./../Typings";
1+
import { IDataValue, IMapper, IMapperConfig, IOutputType } from "./../Typings";
22

33
export interface IFromJSONConfig {
44
propertyString?: string;
@@ -7,7 +7,9 @@ export interface IFromJSONConfig {
77
export class FromJSON implements IMapper {
88
static id: string = "FROMJSON";
99
static description: string = "JSON";
10+
1011
name: string = "JSON";
12+
outputType: IOutputType = IOutputType.string;
1113

1214
propertyString: string = "";
1315

src/mappers/HexToFloat.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Endianness } from "../Config";
2-
import { IDataValue, IMapper, IMapperConfig } from "./../Typings";
2+
import { IDataValue, IMapper, IMapperConfig, IOutputType } from "./../Typings";
33

44
export interface IHexToFloatConfig {
55
endianness?: Endianness;
@@ -8,7 +8,9 @@ export interface IHexToFloatConfig {
88
export class HexToFloat implements IMapper {
99
static id: string = "HEXTOFLOAT";
1010
static description: string = "Hex to float";
11+
1112
name: string = "Hex to float";
13+
outputType: IOutputType = IOutputType.number;
1214

1315
endianness: Endianness = Endianness.BIG_ENDIAN;
1416
hexRegExp: RegExp = new RegExp(/^[a-fxA-F0-9_]+$/);

src/mappers/HexToInt.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Endianness } from "../Config";
2-
import { IDataValue, IMapper, IMapperConfig } from "./../Typings";
2+
import { IDataValue, IMapper, IMapperConfig, IOutputType } from "./../Typings";
33

44
export interface IHexToIntConfig {
55
endianness?: Endianness;
@@ -9,7 +9,9 @@ export interface IHexToIntConfig {
99
export class HexToInt implements IMapper {
1010
static id: string = "HEXTOINT";
1111
static description: string = "Hex to int";
12+
1213
name: string = "Hex to int";
14+
outputType: IOutputType = IOutputType.number;
1315

1416
endianness: Endianness = Endianness.BIG_ENDIAN;
1517
signed: boolean = false;

src/mappers/Offset.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IDataValue, IMapper, IMapperConfig } from "./../Typings";
1+
import { IDataValue, IMapper, IMapperConfig, IOutputType } from "./../Typings";
22

33
export interface IOffsetConfig {
44
offset?: number | string;
@@ -7,7 +7,10 @@ export interface IOffsetConfig {
77
export class Offset implements IMapper {
88
static id: string = "OFFSET";
99
static description: string = "Offset number";
10+
1011
name: string = "Offset";
12+
outputType: IOutputType = IOutputType.number;
13+
1114
offset: number = 0;
1215

1316
constructor({

0 commit comments

Comments
 (0)