{"id":34570642,"url":"https://github.com/dmcneil/typedsv","last_synced_at":"2026-04-19T20:33:29.127Z","repository":{"id":57383529,"uuid":"247693665","full_name":"dmcneil/typedsv","owner":"dmcneil","description":null,"archived":false,"fork":false,"pushed_at":"2020-04-07T16:33:46.000Z","size":285,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-27T12:05:26.886Z","etag":null,"topics":["csv","csv-parser","csv-reader","dsv","dsv-parser","dsv-reader","javascript","parser","typescript"],"latest_commit_sha":null,"homepage":null,"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/dmcneil.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":"2020-03-16T12:14:07.000Z","updated_at":"2020-04-07T16:55:07.000Z","dependencies_parsed_at":"2022-09-18T12:03:22.812Z","dependency_job_id":null,"html_url":"https://github.com/dmcneil/typedsv","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/dmcneil/typedsv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmcneil%2Ftypedsv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmcneil%2Ftypedsv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmcneil%2Ftypedsv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmcneil%2Ftypedsv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dmcneil","download_url":"https://codeload.github.com/dmcneil/typedsv/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmcneil%2Ftypedsv/sbom","scorecard":{"id":347709,"data":{"date":"2025-08-11","repo":{"name":"github.com/dmcneil/typedsv","commit":"91baf81b590ff3cdfc94b95d5f3fa673ffcb69e4"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.7,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Code-Review","score":0,"reason":"Found 0/2 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":0,"reason":"31 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c","Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-896r-f27r-55mw","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7","Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q","Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh","Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-18T07:32:01.227Z","repository_id":57383529,"created_at":"2025-08-18T07:32:01.227Z","updated_at":"2025-08-18T07:32:01.227Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32022111,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T20:23:30.271Z","status":"online","status_checked_at":"2026-04-19T02:00:07.110Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["csv","csv-parser","csv-reader","dsv","dsv-parser","dsv-reader","javascript","parser","typescript"],"created_at":"2025-12-24T09:34:38.748Z","updated_at":"2026-04-19T20:33:29.121Z","avatar_url":"https://github.com/dmcneil.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\" style=\"margin-top: 0.5em\"\u003e\n\t\u003cimg src=\"logo.png\" alt=\"typedsv\"\u003e\n  \u003cdiv\u003e\u003ci\u003eParse and map delimiter-separated values to your classes!\u003c/i\u003e\u003c/div\u003e\n\u003c/div\u003e\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Getting Started](#getting-started)\n- [Mapping Properties with @Parsed](#mapping-properties-with-parsed)\n  - [A Note on Property Types](#a-note-on-property-types)\n  - [Options](#options)\n- [Parser](#parser)\n  - [Input](#input)\n  - [Options](#options-1)\n\n## Installation\n\n\u003e **NOTE** TypeScript **3.2+** is required.\n\nInstall the package:\n\n```\nnpm install typedsv --save\n```\n\nYou may also need to install the `reflect-metadata` library and import it at high level (typically your application entrypoint):\n\n```\nnpm install reflect-metadata --save\n```\n\n```typescript\nimport 'reflect-metadata'\n```\n\nEnable decorator and metadata support in `tsconfig.json`:\n\n```\n{\n    \"compilerOptions\": {\n        \"lib\": [\n          \"es6\",\n          ...\n        ],\n        \"target\": \"es5\",\n        \"experimentalDecorators\": true,\n        \"emitDecoratorMetadata\": true,\n        ...\n    }\n}\n```\n\n## Getting Started\n\nGiven delimiter-separated data (`csv`, `tsv`, etc.):\n\n```\n# example.csv\n\n\"Foo\",\"123\",\"foo\"\n\"Bar\",\"321\",\"bar\"\n\"Baz\",\"456\",\"baz\"\n```\n\nAnd a class such as:\n\n```typescript\n// Example.ts\n\nimport { Parsed } from 'typedsv'\n\nexport default class Example {\n  @Parsed(0)\n  one: string\n\n  @Parsed(1)\n  two: number\n\n  @Parsed(2)\n  three: string\n}\n```\n\nCreate a `Parser` for the type and pass the file to the `parse` method:\n\n```typescript\n// main.ts\n\nimport { createReadStream } from 'fs'\nimport { Parser } from 'typedsv'\nimport Example from './Example'\n\nconst parser = new Parser(Example)\n\nparser.parse(createReadStream('./example.csv')).then((examples: Example[]) =\u003e console.log(examples))\n```\n\nOutput:\n\n```\nExample[\n  Example{one: 'Foo', two: 123, three: 'foo'},\n  Example{one: 'Bar', two: 321, three: 'bar'},\n  Example{one: 'Baz', two: 456, three: 'baz'}\n]\n```\n\n## Mapping Properties with @Parsed\n\nThe `@Parsed` decorator dictates how the `Parser` should maps values to properties within a class.\n\n#### Index\n\nPass a `number` or `{ index: number }` to specify which column to map based on its index:\n\n```\n\"foo\",\"bar\"\n```\n\n```typescript\nclass ExampleWithIndex {\n  @Parsed(0)\n  first: string\n\n  @Parsed({ index: 1 })\n  second: string\n}\n\nconst parser = new Parser(ExampleWithIndex)\nparser.parse(...)\n```\n\n```\nExampleWithIndex[\n  ExampleWithIndex{first: 'foo', second: 'bar'}\n]\n```\n\n#### Headers\n\nUse a `string` or `{ header: string }` to specify which column to map based on its header:\n\n\u003e **NOTE** It is required that the [headers](#headers) option is set when calling `Parser#parse`.\n\n```\n\"A\",\"B\"\n\"foo\",\"bar\"\n```\n\n```typescript\nclass ExampleWithHeader {\n  @Parsed('A')\n  first: string\n\n  @Parsed({ header: 'B' })\n  second: string\n}\n\nconst parser = new Parser(ExampleWithHeader)\nparser.parse(input { header: true })\n```\n\n```\nExampleWithHeader[\n  ExampleWithHeader{first: 'foo', second: 'bar'}\n]\n```\n\nBoth the `{ index: number }` and `{ header: string }` options can be used together. TypeDSV will first try to map a property using the declared header then fallback to the index.\n\n```\n\"A\",\"B\",\"C\"\n\"foo\",\"bar\",\"baz\"\n```\n\n```typescript\nclass ExampleWithHeaderAndIndex {\n  @Parsed('A')\n  first: string\n\n  @Parsed({ header: 'B', index: 1 })\n  second: string\n\n  @Parsed(2)\n  third: string\n}\n\nconst parser = new Parser(ExampleWithHeaderAndIndex)\nparser.parse(input, { header: true })\n```\n\n```\nExampleWithHeaderAndIndex[\n  ExampleWithHeaderAndIndex{first: 'foo', second: 'bar', third: 'baz'}\n]\n```\n\n### A Note on Property Types\n\nWhile values are first parsed as a `string`, the target property's type is honored so long as the conversion is straightforward. To map something beyond a few primitive types, see the [`map`](#map) option:\n\n#### `number`\n\n```\n\"123\",\"3.14\",\"ABC\"\n```\n\n```typescript\n@Parsed(0)\na: number // OK: 123\n\n@Parsed(1)\nb: number // OK: 3.14\n\n@Parsed(2)\nc: number // ERROR Cannot set c: String is not assignable to Number\n```\n\n#### `boolean`\n\n**Valid Values** (case insensitive)\n\n- `TRUE`, `Y`, `YES`, `T`, `1`\n- `FALSE`, `N`, `NO`, `F`, `0`\n\n```\n\"true\",\"0\",\"y\",\"F\",\"NONE\"\n```\n\n```typescript\n@Parsed(0)\na: boolean // OK: true\n\n@Parsed(1)\nb: boolean // OK: false\n\n@Parsed(2)\nc: boolean // OK: true\n\n@Parsed(3)\nd: boolean // OK: false\n\n@Parsed(4)\ne: boolean // ERROR Cannot set e: String is not assignable to Boolean\n```\n\n### Options\n\n\u003e **NOTE** The below options require that the `{ index: number | header: string }` argument form detailed above is used.\n\n#### `map`\n\nType: `(input: string) =\u003e any`\n\nModify the input value before it is mapped to the property:\n\n```\n\"foo\",\"F,O,O\",1\n\"bar\",\"B,A,R\",2\n\"baz\",\"B,A,Z\",3\n```\n\n```typescript\nclass ExampleWithMap {\n  @Parsed({\n    index: 0,\n    map: (input: string) =\u003e input.toUpperCase()\n  })\n  first: string\n\n  @Parsed({\n    index: 1,\n    map: (input: string) =\u003e input.split(',')\n  })\n  second: string[]\n\n  @Parsed({\n    index: 2,\n    map: (input: string) =\u003e {\n      const n = parseInt(input)\n      return n * n\n    }\n  })\n  third: number\n}\n\nconst parser = new Parser(ExampleWithMap)\nparser.parse(...)\n```\n\n```\nExampleWithMap[\n  ExampleWithMap{first: 'FOO', second: ['F', 'O', 'O'], third: 1},\n  ExampleWithMap{first: 'BAR', second: ['B', 'A', 'R'], third: 4},\n  ExampleWithMap{first: 'BAZ', second: ['B', 'A', 'Z'], third: 9}\n]\n```\n\nWhile the function return type is `any`, an error will be thrown if the type is not the same - or cannot be parsed - as the property type as detailed in [A Note on Property Types](#a-note-on-property-types):\n\n```\n\"foo\",\"B,A,R\"\n```\n\n```typescript\nclass ExampleWithBadMap {\n  @Parsed({\n    index: 0,\n    map: (input: string) =\u003e `${input.length}`\n  })\n  first: number\n\n  @Parsed({\n    index: 1,\n    map: (input: string) =\u003e input.split(',')\n  })\n  second: string\n}\n```\n\n```\nERROR Cannot set ExampleWithBadMap.second: Array is not assignable to String\n```\n\n#### `validate`\n\nType: `(input: any) =\u003e boolean | { function: (input: any) =\u003e boolean; message?: string } | [...]`\n\nValidation to be performed before the property is set.\n\nThe option accepts a few different value types but the main idea is that the function(s) take the form `(input: any) =\u003e bool` where a return value of `true` means the value is valid.\n\n\u003e **NOTE** The `validate` functions are called _after_ the optional `map` function.\n\n```\n0,\"John\",\"Doe\"\n```\n\n```typescript\nclass ExampleWithValidation {\n  @Parsed({\n    index: 0,\n    validate: (id: number) =\u003e id \u003e 0\n  })\n  id: number\n}\n```\n\n```\nERROR Validation failed for property id: ['validate.0']\n```\n\nThe default error message just takes the form of `validate.${index}` where `index` is the position of the validation function that failed. To provide a custom message use the `object` form with the `message` option:\n\n```\n0,\"John\",\"Doe\"\n```\n\n```typescript\nclass ExampleWithValidationMessage {\n  @Parsed({\n    index: 0,\n    validate: {\n      message: 'id must be \u003e 0',\n      function: (id: number) =\u003e id \u003e 0\n    }\n  })\n  id: number\n}\n```\n\n```\nERROR Validation failed for property id: ['id must be \u003e 0']\n```\n\nMultiple objects/functions can also be passed as in an array. They are executed in order until either all pass or there is an error:\n\n```\n1,\"John\",\"Doe\"\n```\n\n```typescript\nclass ExampleWithMultipleValidations {\n  @Parsed({\n    index: 0,\n    validate: [\n      (id: number) =\u003e id \u003e 0,\n      (id: number) =\u003e id \u003e 50,\n      { message: 'id cannot be 1', function: (id: number) =\u003e id !== 1 } // will not run\n    ]\n  })\n  id: number\n}\n```\n\n```\nERROR Validation failed for property id: ['validate.1']\n```\n\nIn case you want to collect all validation errors, use the `object` form with the `aggregate` and `functions` options:\n\n```\n1,\"John\",\"Doe\"\n```\n\n```typescript\nclass ExampleWithAggregatedValidationErrors {\n  @Parsed({\n    index: 0,\n    validate: {\n      aggregate: true,\n      functions: [\n        (id: number) =\u003e id \u003e 50,\n        { message: 'id must be \u003e 100', function: (id: number) =\u003e id \u003e 100 },\n        (id: number) =\u003e id !== 0 // will still run even though the validation has failed\n      ]\n    }\n  })\n  id: number\n}\n```\n\n```\nERROR Validation failed for property id: ['validate.0', 'id must be \u003e 100']\n```\n\n## Parser\n\nThe `Parser` constructor expects a type/class that has at least one property with decorated with `@Parsed`:\n\n```typescript\nexport default class Example {\n  @Parsed(0)\n  one: string\n}\n\nconst parser = new Parser(Example)\n```\n\n\u003e **NOTE** An error will be thrown when attempting to create a `Parser` with a type that does not have any decorated properties.\n\nOnce a `Parser` is created, simply call the `parse` function with an input and [options](#options-1) using any of the following methods:\n\n#### Promise\n\n```typescript\nparser.parse(input, { ... })\n  .then((examples: Example[]) =\u003e ...)\n```\n\n#### `async`/`await`\n\nWait for all rows to be parsed...\n\n```typescript\n(async () =\u003e {\n  const examples: Example[] = await parser.parse(input, { ... })\n})()\n```\n\n#### `onObject`\n\nCall a function each time a row is parsed using the [onObject](#onobject) option:\n\n```typescript\nparser.parse(input, {\n  onObject: (row: Example, line: number) =\u003e ...)\n})\n```\n\n### Input\n\nThe input is assumed to be formatted where each line is considered a single record. A line is then separated by a delimiter to represent a column/field value. Most of the examples in this document make use of the common CSV (comma-separated value) format:\n\n```\n\"1\",\"John\",\"Doe\"\n\"2\",\"Jane\",\"Doe\"\n\"3\",\"Matt\",\"Smith\"\n...\n```\n\nLines that begin with the comment character (default: `#`) are skipped:\n\n```\n\"ID\",\"FirstName\",\"LastName\"\n\"1\",\"John\",\"Doe\"\n# this comment will be skipped\n\"2\",\"Jane\",\"Doe\"\n\"3\",\"Matt\",\"Smith\"\n```\n\nIf a line ends with an inline comment, the line is parsed up until the comment:\n\n```\n\"ID\",\"FirstName\",\"LastName\"\n\"1\",\"John\",\"Doe\"\n\"2\",\"Jane\",\"Doe\" # this line is parsed up to this comment\n\"3\",\"Matt\",\"Smith\"\n```\n\n#### Reading the Input\n\nThe input can be passed as the first argument to `parse` in a few different forms:\n\n#### `string`\n\nA complete, delimited input.\n\n```typescript\nconst input = `\n\"1\",\"John\",\"Doe\"\n\"2\",\"Jane\",\"Doe\"\n\"3\",\"Matt\",\"Smith\"\n`\n```\n\n#### `Readable`\n\nThe most common method is reading a file using `createReadStream`:\n\n```typescript\nimport { createReadStream } from 'fs'\n\nconst input = createReadStream('/tmp/data.csv')\n```\n\n### Options\n\nWhile TypeDSV implements [RFC4180](https://tools.ietf.org/html/rfc4180), `Parser#parse` accepts a variety of options to accomodate data that may not follow that of a typical CSV.\n\n#### `delimiter`\n\nType: `string`  \nDefault: `,` (comma)\n\nThe character that separates values in a row.\n\n```\n# default\n\"1\",\"John\",\"Doe\"\n\n# delimiter: |\n\"1\"|\"John\"|\"Doe\"\n\n# delimiter: \\t\n\"1\" \"John\"  \"Doe\"\n```\n\n#### `quote`\n\nType: `string`  \nDefault: `\"` (double quote)\n\n```\n# default\n\"1\",\"John\",\"Doe\"\n\n# quote: ~\n~1~,~John~,~Doe~\n```\n\nValues do not have to be wrapped in quote characters although there are some exceptions as listed below:\n\n```\n\"1\",\"John\",\"Doe\"          # OK\n2,Jane,Doe                # OK\n3,\"Matt\",Smith            # OK\n```\n\nValues that contain a carriage return (default: `\\r`), new line (default: `\\n`), the delimiter (default: `,`), or comment (default: `#`) must be wrapped in the quote character:\n\n```\n# OK\n1,John,\"Do\\re\"\n2,Jane,\"Do\\ne\"\n3,Matt,\"Smi,th\"\n4,Megan,\"Smi#th\"\n\n# NOT OK\n1,John,Do\\re\n2,Jane,Do\\ne\n3,Matt,Smi,th\n4,Megan,Smi#th\n```\n\nIf a quoted value contains the quote character (default: `\"`) then it must be escaped by a preceeding quote character:\n\n```\n1,John,\"said \"\"Hi!\"\"\"     # OK\n2,Jane,\"said \"Hi!\"\"       # NOT OK\n```\n\nNon-quoted values can contain the quote character without the escaping:\n\n```\n1,John,said \"Hi!\"         # OK\n```\n\n#### `headers`\n\nType: `boolean | string[]`  \nDefault: `false`\n\nThis option enables the ability to map properties by the headers instead of by index as described in [Mapping Properties with @Parsed](#mapping-properties-with-parsed).\n\nIf the first line of the input declares the headers:\n\n```\n\"ID\",\"FirstName\",\"LastName\"\n\"1\",\"John\",\"Doe\"\n```\n\nThen they will be parsed and used for mapping if this option is set to `true`.\n\nAlternatively, a `string[]` can be used to define headers before parsing the input. In this case, the first line of the input _does not_ need to be header declarations. Of course, the supplied headers will be honored when property mapping:\n\n\u003e **NOTE** If the input _does_ contain header declarations on the first line, it is recommended to use the [range](#range) option to skip the first line.\n\n```\n\"1\",\"John\",\"Doe\"\n\"2\",\"Jane\",\"Doe\"\n\"3\",\"Matt\",\"Smith\"\n\"4\",\"Megan\",\"Smith\"\n```\n\n```typescript\nclass Person {\n  @Parsed('id')\n  id: number\n\n  @Parsed('firstName')\n  firstName: string\n\n  @Parsed('lastName')\n  lastName: string\n}\n\nconst parser = new Parser(Person)\n... = parser.parse(input, { headers: ['id', 'firstName', 'lastName'] })\n```\n\n#### `mapHeaders`\n\nType: `(headers: string[]) =\u003e string[]`\n\nGiven an input with headers on the first line:\n\n```\n\"iD\",\"fIrSTnAMe\",\"LAsTNAme\"\n\"1\",\"John\",\"Doe\"\n```\n\nAnd a class to map using the headers formatted differently:\n\n```typescript\nclass Person {\n  @Parsed('id')\n  id: number\n\n  @Parsed('firstname')\n  firstName: string\n\n  @Parsed('lastname')\n  lastName: string\n}\n```\n\nThen this option can be used to reformat the headers so the values will map correctly:\n\n```typescript\nparser.parse(input, {\n  mapHeaders: (headers: string[]) =\u003e {\n    return headers.map((header: string) =\u003e header.toLowerCase())\n  }\n})\n```\n\n#### `range`\n\nType: `[number?, number?] | { start?: number, end?: number }`  \nDefault: `{ start: 1 }`\n\nGiven the following input:\n\n```\n1,\"John\",\"Doe\"\n2,\"Jane\",\"Doe\"\n3,\"Matt\",\"Smith\"\n4,\"Megan\",\"Smith\"\n```\n\nSetting the start line:\n\n```typescript\nparser.parse(input, { range: [2] }) // array form\nparser.parse(input, { range: { start: 2 } }) // object form\n```\n\n```\n[\n  ['2', 'Jane', 'Doe'],\n  ['3', 'Matt', 'Smith'],\n  ['4', 'Megan', 'Smith']\n]\n```\n\nSetting the ending line:\n\n\u003e **NOTE** The ending line argument is _exclusive_.\n\n```typescript\nparser.parse(input, { range: [, 3] }) // array form, remember to include the comma!\nparser.parse(input, { range: { end: 3 } }) // object form\n```\n\n```\n[\n  ['1', 'John', 'Doe'],\n  ['2', 'Jane', 'Doe']\n]\n```\n\nParse a range of lines:\n\n```typescript\nparser.parse(input, { range: [2, 4] }) // array form\nparser.parse(input, { range: { start: 2, end: 4 } }) // object form\n```\n\n```\n[\n  ['2', 'Jane', 'Doe'],\n  ['3', 'Matt', 'Smith']\n]\n```\n\n#### `onObject`\n\nType: `(o: T, line: number) =\u003e void`\n\nThe provided function will be called each time a row has been parsed and mapped:\n\n```typescript\nparser.parse(input, {\n  onObject: (row: Example, line: number) =\u003e { ... }\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmcneil%2Ftypedsv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdmcneil%2Ftypedsv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmcneil%2Ftypedsv/lists"}