-
-
Notifications
You must be signed in to change notification settings - Fork 35
Closed
Labels
acceptedIt is accepted to doIt is accepted to dogood first issueGood for newcomersGood for newcomers
Description
Actual
The jsonMapper
described in #40 and implemented in #43 has fallback mechanism that return null
if parsing json failed.
Expected
Default response should be customisable by calling jsonMapper.default<TDefaultResult>(defaultResult: TDefaultResult)
which produce mapper with return type TJsonResult | TDefaultResult
.
Example usage:
const statusMapper = jsonMapper.default<Stats>({views: 0, unique: 0, stars: 0})
// returns default = {views: 0, unique:0, starts:0} for invalide
const stats = statusMapper<Stats>('invalid');
// returns parsed = {views: 1234, unique:10, starts:40}
const stats2 = statusMapper<Stats>('{"views": 123, "unique":10, "starts":40}');
// in a config: (column definition for vertical list)
// {key:"stats", index:5, mapper: jsonMapper.default<Stats>({views: 0, unique: 0, stars: 0})}
TODO:
- Introduce factory similar like in splitMapper:
- define JsonMapper type
- wrap mapper into factory function
- implement setting
default
- produce and export default
jsonMapper
created by the factory
- prove that it works by covering new changes by unit tests
- describe jsonMapper api in a Readme.md
Metadata
Metadata
Assignees
Labels
acceptedIt is accepted to doIt is accepted to dogood first issueGood for newcomersGood for newcomers
Projects
Status
To Release