Options
All
  • Public
  • Public/Protected
  • All
Menu

DataMapperChain is a simple collection of mappers and allows for serializing and loading configurations of mappers.

Initialization and configuration


import { DataMapperChain } from "@exploratoryengineering/data-mapper-chain";

// Optional config
const myMapper = new DataMapperChain();

// With config
const myMapperWithConfig = new DataMapperChain({
  mappers: [],
  name: "My name for the mapper",
});

Adding mappers

Using short hand

import { DataMapperChain } from "@exploratoryengineering/data-mapper-chain";

// Create mapper and add mappers
const dataMapperChain = new DataMapperChain()
  .chunk({
    start: 50,
    size: 4,
  })
  .hexToInt();

Mapping data

// Create mapper and add mappers
const dataMapperChain = new DataMapperChain()
  .chunk({
    start: 50,
    size: 4,
  })
  .hexToInt();

const deviceData: string = `47eee3803e3a8c713f8daf7242fc6666423c28c04111d84000024b00a3030c261b010b91d3`;
// Run mapper
dataMapperChain.mapData(deviceData); // prints 587

Hierarchy

  • DataMapperChain

Index

Constructors

constructor

  • Create a new instance of a DataMapperChain.

    Parameters

    • Default value __namedParameters: object = {}

      DataMapperChain configuration object

      • mappers: IMapper[]

        The initial mappers for the DataMapperChain

      • meta: object

        The initial meta data for the DataMapperChain

      • name: string

        The initial name for the DataMapperChain

    Returns DataMapperChain

Properties

initialValue

initialValue: IDataValue = ""

mappers

mappers: IMapper[] = []

meta

meta: object

name

name: string = ""

Methods

addMapper

addNewMapperType

  • Make a new mapper type available to the DataMapperChain. If the mapper type already exists it will be overwritten.

    Parameters

    Returns void

base64

chunk

createMapperByConfig

  • Create a IMapper based on the given IMapperConfig. If no mapper type is found the function returns false.

    Parameters

    Returns IMapper | false

findMapperTypeById

  • findMapperTypeById(id: string): undefined | IMapperType

fromJson

hexToFloat

hexToInt

loadConfig

  • Loads a configuration which has been exported earlier by serializeConfig.

    Parameters

    • configString: string

      Configuration string as exported from serializeConfig @see serializeConfig

    Returns DataMapperChain

mapData

  • Uses the configured mappers for the DataMapperChain and maps the given data through the mappers.

    Parameters

    Returns string | number

offset

serializeConfig

  • serializeConfig(): string
  • Serializes the DataMapperChain configuration including the mappers added to the chain. Returns a string representation of the configuration which has been run through JSON.stringify.

    Returns string

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc