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

Commit

Permalink
feat(outputtype): add output type for mappers
Browse files Browse the repository at this point in the history
  • Loading branch information
Per Kristian Kummermo committed Nov 26, 2018
1 parent 24b2c3e commit ea9f219
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/DataMapperChain.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { DataMapperChain } from "./DataMapperChain";
import { Mappers } from "./Mappers";
import { IDataValue, IMapper, IMapperConfig } from "./Typings";
import { IDataValue, IMapper, IMapperConfig, IOutputType } from "./Typings";

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

class MapperMock implements IMapper {
initParams: any = {};
outputType: IOutputType = IOutputType.number;

constructor(params = {}) {
this.initParams = params;
Expand Down
6 changes: 6 additions & 0 deletions src/Typings.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
export type IDataValue = string | number;
export enum IOutputType {
"string",
"number",
"array",
}

export interface IMapperConfig {
id: string;
params: any;
}

export interface IMapper {
outputType: IOutputType;
transform(data: IDataValue): IDataValue;
config(): IMapperConfig;
}
Expand Down
3 changes: 2 additions & 1 deletion src/mappers/Base64.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Base64Action } from "../Config";
import { IDataValue, IMapper, IMapperConfig } from "./../Typings";
import { IDataValue, IMapper, IMapperConfig, IOutputType } from "./../Typings";

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

name: string = "Base64";
outputType: IOutputType = IOutputType.string;

action: Base64Action = Base64Action.DECODE;

Expand Down
5 changes: 4 additions & 1 deletion src/mappers/Chunk.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IDataValue, IMapper, IMapperConfig } from "./../Typings";
import { IDataValue, IMapper, IMapperConfig, IOutputType } from "./../Typings";

export interface IChunkConfig {
// Start-index of chunk
Expand All @@ -10,7 +10,10 @@ export interface IChunkConfig {
export class Chunk implements IMapper {
static id: string = "CHUNK";
static description: string = "Chunk";

name: string = "Chunk";
outputType: IOutputType = IOutputType.string;

start: number = 0;
size: number = 4;

Expand Down
4 changes: 3 additions & 1 deletion src/mappers/FromJSON.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IDataValue, IMapper, IMapperConfig } from "./../Typings";
import { IDataValue, IMapper, IMapperConfig, IOutputType } from "./../Typings";

export interface IFromJSONConfig {
propertyString?: string;
Expand All @@ -7,7 +7,9 @@ export interface IFromJSONConfig {
export class FromJSON implements IMapper {
static id: string = "FROMJSON";
static description: string = "JSON";

name: string = "JSON";
outputType: IOutputType = IOutputType.string;

propertyString: string = "";

Expand Down
4 changes: 3 additions & 1 deletion src/mappers/HexToFloat.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Endianness } from "../Config";
import { IDataValue, IMapper, IMapperConfig } from "./../Typings";
import { IDataValue, IMapper, IMapperConfig, IOutputType } from "./../Typings";

export interface IHexToFloatConfig {
endianness?: Endianness;
Expand All @@ -8,7 +8,9 @@ export interface IHexToFloatConfig {
export class HexToFloat implements IMapper {
static id: string = "HEXTOFLOAT";
static description: string = "Hex to float";

name: string = "Hex to float";
outputType: IOutputType = IOutputType.number;

endianness: Endianness = Endianness.BIG_ENDIAN;
hexRegExp: RegExp = new RegExp(/^[a-fxA-F0-9_]+$/);
Expand Down
4 changes: 3 additions & 1 deletion src/mappers/HexToInt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Endianness } from "../Config";
import { IDataValue, IMapper, IMapperConfig } from "./../Typings";
import { IDataValue, IMapper, IMapperConfig, IOutputType } from "./../Typings";

export interface IHexToIntConfig {
endianness?: Endianness;
Expand All @@ -9,7 +9,9 @@ export interface IHexToIntConfig {
export class HexToInt implements IMapper {
static id: string = "HEXTOINT";
static description: string = "Hex to int";

name: string = "Hex to int";
outputType: IOutputType = IOutputType.number;

endianness: Endianness = Endianness.BIG_ENDIAN;
signed: boolean = false;
Expand Down
5 changes: 4 additions & 1 deletion src/mappers/Offset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IDataValue, IMapper, IMapperConfig } from "./../Typings";
import { IDataValue, IMapper, IMapperConfig, IOutputType } from "./../Typings";

export interface IOffsetConfig {
offset?: number | string;
Expand All @@ -7,7 +7,10 @@ export interface IOffsetConfig {
export class Offset implements IMapper {
static id: string = "OFFSET";
static description: string = "Offset number";

name: string = "Offset";
outputType: IOutputType = IOutputType.number;

offset: number = 0;

constructor({
Expand Down

0 comments on commit ea9f219

Please sign in to comment.