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

Commit

Permalink
feat(DataMapperChain): add typings and tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
Per Kristian Kummermo committed May 14, 2018
1 parent 37f1b28 commit b839f89
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/DataMapperChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class DataMapperChain {

/**
* Create a new instance of a DataMapperChain.
* @param param0 DataMapperChain configuration object @see IDataMapperChainConfig
* @param __namedParameters DataMapperChain configuration object
*/
constructor({
mappers = [],
Expand Down
53 changes: 53 additions & 0 deletions tutorials/data-mapper-tutorial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
### Initialization and configuration
```ts

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
```ts
import { DataMapperChain } from "@exploratoryengineering/data-mapper-chain";

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

```


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

const deviceData: string = `47eee3803e3a8c713f8daf7242fc6666423c28c04111d84000024b00a3030c261b010b91d3`;
// Create data object (coincidentally the value is CO2 ppm)
const data: IDataValue = {
name: "CO2 ppm",
value: deviceData,
};

// Run mapper
dataMapperChain.mapData(data); // prints { name: 'CO2 ppm', value: 587 }
```

0 comments on commit b839f89

Please sign in to comment.