This repository has been archived by the owner on Jul 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(DataMapperChain): add typings and tutorial
- Loading branch information
Per Kristian Kummermo
committed
May 14, 2018
1 parent
37f1b28
commit b839f89
Showing
2 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
``` |