{"id":27362607,"url":"https://github.com/vcfvct/fixed-width-ts-decorator","last_synced_at":"2025-04-13T03:25:38.357Z","repository":{"id":45468536,"uuid":"382059896","full_name":"vcfvct/fixed-width-ts-decorator","owner":"vcfvct","description":"Fixed width file handler parser with TypeScript Decorator","archived":false,"fork":false,"pushed_at":"2021-12-12T22:50:22.000Z","size":186,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-09T13:02:54.045Z","etag":null,"topics":["decorator","file-processing","fixed-width","javascript","reflection","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vcfvct.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-01T14:27:34.000Z","updated_at":"2024-05-30T14:49:41.000Z","dependencies_parsed_at":"2022-09-13T00:02:38.308Z","dependency_job_id":null,"html_url":"https://github.com/vcfvct/fixed-width-ts-decorator","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vcfvct%2Ffixed-width-ts-decorator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vcfvct%2Ffixed-width-ts-decorator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vcfvct%2Ffixed-width-ts-decorator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vcfvct%2Ffixed-width-ts-decorator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vcfvct","download_url":"https://codeload.github.com/vcfvct/fixed-width-ts-decorator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248550634,"owners_count":21122933,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["decorator","file-processing","fixed-width","javascript","reflection","typescript"],"created_at":"2025-04-13T03:25:37.631Z","updated_at":"2025-04-13T03:25:38.350Z","avatar_url":"https://github.com/vcfvct.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fixed width file processing/parsing with TS Decorators\nThis lib provide decorator for fixed width file so that the domain class and spec can stay together. No separate schema creation is needed so that it is more readable, maintainable and extensible.\n\n## Usage\n`npm i fixed-width-ts-decorator`\n\n## Example\nThis lib uses [reflect-metadata](https://github.com/rbuckton/reflect-metadata) for Meta programming.\n\nInheritance is supported that fields decorated in parent classes will also be included/processed.\n\n### Model definition\n\n```typescript\n// class inheritance is Optional here.\nexport class Transaction extends FixedWidthConvertible {\n  @FixedWidth({ start: 0, width: 5 })\n  clientId: string;\n\n  @FixedWidth({ start: 5, width: 40 })\n  parentName: string;\n\n  @FixedWidth({ start: 45, width: 40, format: { type: DataType.Float } })\n  taxAmount: number;\n\n  @FixedWidth({\n    start: 85,\n    width: 40,\n    format: {\n      type: DataType.Float,\n      precision: 3,\n    },\n  })\n  paymentAmount: number;\n\n  @FixedWidth({\n    start: 125,\n    width: 20,\n    format: { type: DataType.Integer },\n  })\n  paymentTimeStamp: number;\n\n  @FixedWidth({ start: 145, width: 40 })\n  userId: string;\n\n  @FixedWidth({ start: 225, width: 40 })\n  paymentId: string;\n  // other non-decorated fields\n  otherField: string;\n}\n\n```\n\n### Parse the file to Objects\n\n```typescript\n(() =\u003e {\n\t// Or you can read file line by line\n  const file = fs.readFileSync('data/sample.txt', { encoding: 'utf8' });\n  const lines = file.split('\\n').filter(l =\u003e l);\n  const rs: Array\u003cTransaction\u003e = lines.map(line =\u003e {\n    const trans = new Transaction();\n\t\t/**\n\t   * Option 1: if your domain class extends the abstract `FixedWidthConvertible` class,\n\t\t * then you can use the instance.convertFixedWidth method.\n\t\t */\n    trans.convertFixedWidth(line);\n\t\t/**\n\t\t * Option 2: if your domain class already extends some other classes\n\t\t * then use the static function on the `FixedWidthConvertible` class and pass in the instance as argument like below.\n     */\n\t\t// FixedWidthConvertible.convertFixedWidth(line, trans);\n    return trans;\n  });\n\n  console.log(rs);\n})()\n```\n## Format Options\n* support parse to Integer or Float(with precision) other than the default String type.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvcfvct%2Ffixed-width-ts-decorator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvcfvct%2Ffixed-width-ts-decorator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvcfvct%2Ffixed-width-ts-decorator/lists"}