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

Commit b839f89

Browse files
author
Per Kristian Kummermo
committed
feat(DataMapperChain): add typings and tutorial
1 parent 37f1b28 commit b839f89

2 files changed

Lines changed: 54 additions & 1 deletion

File tree

src/DataMapperChain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class DataMapperChain {
3838

3939
/**
4040
* Create a new instance of a DataMapperChain.
41-
* @param param0 DataMapperChain configuration object @see IDataMapperChainConfig
41+
* @param __namedParameters DataMapperChain configuration object
4242
*/
4343
constructor({
4444
mappers = [],

tutorials/data-mapper-tutorial.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
### Initialization and configuration
2+
```ts
3+
4+
import { DataMapperChain } from "@exploratoryengineering/data-mapper-chain";
5+
6+
// Optional config
7+
const myMapper = new DataMapperChain();
8+
9+
// With config
10+
const myMapperWithConfig = new DataMapperChain({
11+
mappers: [],
12+
name: "My name for the mapper",
13+
});
14+
15+
```
16+
17+
### Adding mappers
18+
19+
#### Using short hand
20+
```ts
21+
import { DataMapperChain } from "@exploratoryengineering/data-mapper-chain";
22+
23+
// Create mapper and add mappers
24+
const dataMapperChain = new DataMapperChain()
25+
.chunk({
26+
start: 50,
27+
size: 4,
28+
})
29+
.hexToInt();
30+
31+
```
32+
33+
34+
### Mapping data
35+
```ts
36+
// Create mapper and add mappers
37+
const dataMapperChain = new DataMapperChain()
38+
.chunk({
39+
start: 50,
40+
size: 4,
41+
})
42+
.hexToInt();
43+
44+
const deviceData: string = `47eee3803e3a8c713f8daf7242fc6666423c28c04111d84000024b00a3030c261b010b91d3`;
45+
// Create data object (coincidentally the value is CO2 ppm)
46+
const data: IDataValue = {
47+
name: "CO2 ppm",
48+
value: deviceData,
49+
};
50+
51+
// Run mapper
52+
dataMapperChain.mapData(data); // prints { name: 'CO2 ppm', value: 587 }
53+
```

0 commit comments

Comments
 (0)