{"id":21224279,"url":"https://github.com/sam-parsons/snowpack-plugin-dsv","last_synced_at":"2025-03-15T01:40:54.002Z","repository":{"id":123936178,"uuid":"368035598","full_name":"sam-parsons/snowpack-plugin-dsv","owner":"sam-parsons","description":"converts .csv and .tsv files into javascript modules","archived":false,"fork":false,"pushed_at":"2021-06-09T03:51:09.000Z","size":32,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-21T17:34:48.287Z","etag":null,"topics":["csv","snowpack-plugin","tsv"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/snowpack-plugin-dsv","language":"JavaScript","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/sam-parsons.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-17T02:44:33.000Z","updated_at":"2023-03-09T03:58:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"0bc59331-9db8-4bca-a825-13ff01b1b7e1","html_url":"https://github.com/sam-parsons/snowpack-plugin-dsv","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sam-parsons%2Fsnowpack-plugin-dsv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sam-parsons%2Fsnowpack-plugin-dsv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sam-parsons%2Fsnowpack-plugin-dsv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sam-parsons%2Fsnowpack-plugin-dsv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sam-parsons","download_url":"https://codeload.github.com/sam-parsons/snowpack-plugin-dsv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243672369,"owners_count":20328762,"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":["csv","snowpack-plugin","tsv"],"created_at":"2024-11-20T22:57:33.541Z","updated_at":"2025-03-15T01:40:53.979Z","avatar_url":"https://github.com/sam-parsons.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[npm]: https://img.shields.io/npm/v/snowpack-plugin-dsv\n[npm-url]: https://www.npmjs.com/package/snowpack-plugin-dsv\n[size]: https://packagephobia.now.sh/badge?p=snowpack-plugin-dsv\n[size-url]: https://packagephobia.now.sh/result?p=snowpack-plugin-dsv\n\n[![npm][npm]][npm-url]\n[![size][size]][size-url]\n[![libera manifesto](https://img.shields.io/badge/libera-manifesto-lightgrey.svg)](https://liberamanifesto.com)\n\n# snowpack-plugin-dsv\n\nSnowpack plugin that converts `.csv` and `.tsv` files into JavaScript modules with [d3-dsv](https://github.com/d3/d3-dsv).\n\n## Requirements\n\nThis plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v8.0.0+) and Snowpack v2.0.0+.\n\n## Install\n\nUsing npm:\n\n```console\nnpm install --save-dev snowpack-plugin-dsv\n```\n\n## Usage\n\nCreate a `snowpack.config.js` [configuration file](https://www.snowpack.dev/reference/configuration) and import the plugin to automatically detect and parse `.csv`, `.tsv`, and `.psv` files:\n\n```js\nconst dsv = require('snowpack-plugin-dsv');\n\nmodule.exports = {\n  mount: {\n    public: { url: '/', static: true },\n    src: { url: '/dist' },\n  },\n  plugins: ['snowpack-plugin-dsv'],\n};\n```\n\nFor other types of delimiters, set the `delimiter` property of the options object to the appropriate character. Note: You will have to set the file extension of your custom files to `.dsv`.\n\n```js\nmodule.exports = {\n  mount: { ... },\n  plugins: [['snowpack-plugin-dsv', { delimiter: '~' }]],\n};\n```\n\nIf you would like to use multiple files with different delimiters, populate the `delimiters` array with the appropriate file extensions. Note: Make sure the second character of the custom file extension \u003ci\u003eis\u003c/i\u003e the delimiter used in the data. Ex: If delimiting by `~`, the file extension should be `.~sv`.\n\n```js\nmodule.exports = {\n  mount: { ... },\n  plugins: [['snowpack-plugin-dsv', { delimiters: ['.~sv', '.%sv'] }]],\n};\n```\n\n## Practical Example\n\nSuppose that you have a CSV (or TSV!) file which contains some information on delicious fruits:\n\n```csv\ntype,count\napples,7\npears,4\nbananas,5\n```\n\nAnd suppose you'd like to import that CSV as an `Array` within some part of your code. After adding the plugin (as shown above), you may `import` (or `require`) the CSV file directly. The import will provide an `Array` of `Objects` representing rows from the CSV file:\n\n```js\nimport fruit from './fruit.csv';\n\nconsole.log(fruit);\n// [\n//   { type: 'apples', count: '7' },\n//   { type: 'pears', count: '4' },\n//   { type: 'bananas', count: '5' }\n// ]\n```\n\n## Options\n\n### `delimiter`\n\nType: `string`\u003cbr\u003e\nDefault: `null`\n\nIndicates the delimiter that will be used by an internal `dsvParse` method from `d3-dsv`. This delimiter will be used for all files with a `.dsv` extension.\n\n### `delimiters`\n\nType: `array`\u003cbr\u003e\nDefault: `null`\n\nDeclares multiple file extensions and delimiters to be used during build. The extension and delimiter are indicated by a custom file extension alone - a `.%sv` file will be automatically delimited with `%`.\n\n### `processRow`\n\nType: `function`\u003cbr\u003e\nDefault: `null`\n\nSpecifies a function which processes and manipulates each row in the parsed array. The function can manipulate the passed `row`.\n\nThis option could be used for converting numeric `string` values into `number` values - see example below.\n\n```js\ndsv({\n  processRows: (row, id) =\u003e {\n    Object.keys(row).forEach((key, id) =\u003e {\n      let value = row[key].trim();\n      row[key] = isNaN(Number(value)) ? value : Number(value);\n    });\n  },\n});\n```\n\n## Meta\n\n[LICENSE (MIT)](./LICENSE.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsam-parsons%2Fsnowpack-plugin-dsv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsam-parsons%2Fsnowpack-plugin-dsv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsam-parsons%2Fsnowpack-plugin-dsv/lists"}