Skip to content

Commit

Permalink
add int/float type support (#5)
Browse files Browse the repository at this point in the history
* add int/float type support

* readme
  • Loading branch information
vcfvct authored Jul 28, 2021
1 parent b067d27 commit cfe0415
Show file tree
Hide file tree
Showing 8 changed files with 7,105 additions and 41 deletions.
29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,32 @@ This lib uses [reflect-metadata](https://github.com/rbuckton/reflect-metadata) f

```typescript
// class inheritance is Optional here.
export class Transaction extends FixedWidthConvertible{
export class Transaction extends FixedWidthConvertible {
@FixedWidth({ start: 0, width: 5 })
clientId: string;

@FixedWidth({ start: 5, width: 40 })
parentName: string;

@FixedWidth({ start: 45, width: 40, format: { type: DataType.Float } })
taxAmount: number;

@FixedWidth({ start: 45, width: 40 })
receiverId: string;
@FixedWidth({
start: 85,
width: 40,
format: {
type: DataType.Float,
precision: 3,
},
})
paymentAmount: number;

@FixedWidth({ start: 85, width: 40 })
paymentStatus: string;

@FixedWidth({ start: 125, width: 20 })
paymentTimeStamp: string;
@FixedWidth({
start: 125,
width: 20,
format: { type: DataType.Integer },
})
paymentTimeStamp: number;

@FixedWidth({ start: 145, width: 40 })
userId: string;
Expand Down Expand Up @@ -63,3 +74,5 @@ export class Transaction extends FixedWidthConvertible{
console.log(rs);
})()
```
## Format Options
* support parse to Integer or Float(with precision) other than the default String type.
8 changes: 4 additions & 4 deletions data/sample.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
200005a1ac103-ff56-40f2-a025-d127819f9a1d vcfvct SUCCESS 1623943217450 user_8227fa28-0758-4cbc-b239-b5d8ecdc2f8 pymt_5f29520a-6b03-424f-a934-7e07fada7b5
200005a1ac103-ff56-40f2-a025-d127819f9a1d vcfvct SUCCESS 1623943172405 user_f8189a6b-b41b-42ef-8c05-65b8e2b9816 pymt_5b6cbbf7-1863-438f-ac95-2c2fb86ca37
200005a1ac103-ff56-40f2-a025-d127819f9a1d vcfvct SUCCESS 1623943073771 user_8227fa28-0758-4cbc-b239-b5d8ecdc2f8 pymt_8be3eea4-1be5-41c5-82be-1bf008a1292
200005a1ac103-ff56-40f2-a025-d127819f9a1d vcfvct SUCCESS 1623943251009 user_f8189a6b-b41b-42ef-8c05-65b8e2b9816 pymt_ab5258f5-1650-44db-aa9e-5924621b625
200005a1ac103-ff56-40f2-a025-d127819f9a1d 1234.5 1234.56 1623943217450 user_8227fa28-0758-4cbc-b239-b5d8ecdc2f8 pymt_5f29520a-6b03-424f-a934-7e07fada7b5
200005a1ac103-ff56-40f2-a025-d127819f9a1d 123.45 123.456 1623943172405 user_f8189a6b-b41b-42ef-8c05-65b8e2b9816 pymt_5b6cbbf7-1863-438f-ac95-2c2fb86ca37
200005a1ac103-ff56-40f2-a025-d127819f9a1d 12.345 12.3456 1623943073771 user_8227fa28-0758-4cbc-b239-b5d8ecdc2f8 pymt_8be3eea4-1be5-41c5-82be-1bf008a1292
200005a1ac103-ff56-40f2-a025-d127819f9a1d 1.2345 1.23456 1623943251009 user_f8189a6b-b41b-42ef-8c05-65b8e2b9816 pymt_ab5258f5-1650-44db-aa9e-5924621b625
Loading

0 comments on commit cfe0415

Please sign in to comment.