{"id":23516304,"url":"https://github.com/stacksjs/ts-spreadsheets","last_synced_at":"2025-04-05T15:02:39.294Z","repository":{"id":258671088,"uuid":"867850673","full_name":"stacksjs/ts-spreadsheets","owner":"stacksjs","description":"📊 Easily manage \u0026 generate spreadsheets. CSV \u0026 Excel files supported.","archived":false,"fork":false,"pushed_at":"2025-03-29T04:30:50.000Z","size":1402,"stargazers_count":76,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-29T14:05:35.572Z","etag":null,"topics":["bun","csv","excel","library","spreadsheets","typescript"],"latest_commit_sha":null,"homepage":"https://ts-spreadsheets.netlify.app","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/stacksjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["stacksjs","chrisbbreuer"],"open_collective":"stacksjs"}},"created_at":"2024-10-04T21:10:50.000Z","updated_at":"2025-02-27T16:59:24.000Z","dependencies_parsed_at":"2024-11-26T06:22:36.979Z","dependency_job_id":"e9ddb9ec-e2f4-4c5e-9df8-186ea5c846c2","html_url":"https://github.com/stacksjs/ts-spreadsheets","commit_stats":{"total_commits":34,"total_committers":3,"mean_commits":"11.333333333333334","dds":"0.23529411764705888","last_synced_commit":"ab3726ba9250462385dc05cf7477705cd3768482"},"previous_names":["stacksjs/bun-spreadsheets","stacksjs/ts-spreadsheets"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacksjs%2Fts-spreadsheets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacksjs%2Fts-spreadsheets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacksjs%2Fts-spreadsheets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacksjs%2Fts-spreadsheets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stacksjs","download_url":"https://codeload.github.com/stacksjs/ts-spreadsheets/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246777791,"owners_count":20832033,"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":["bun","csv","excel","library","spreadsheets","typescript"],"created_at":"2024-12-25T15:07:45.656Z","updated_at":"2025-04-05T15:02:39.270Z","avatar_url":"https://github.com/stacksjs.png","language":"TypeScript","readme":"\u003cp align=\"center\"\u003e\u003cimg src=\"https://github.com/stacksjs/ts-spreadsheets/blob/main/.github/art/cover.jpg\" alt=\"Social Card of this Bun Spreadsheets repo\"\u003e\u003c/p\u003e\n\n[![npm version][npm-version-src]][npm-version-href]\n[![GitHub Actions][github-actions-src]][github-actions-href]\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n\u003c!-- [![npm downloads][npm-downloads-src]][npm-downloads-href] --\u003e\n\u003c!-- [![Codecov][codecov-src]][codecov-href] --\u003e\n\n# ts-spreadsheets\n\nEasily generate spreadsheets, like CSVs and Excel files.\n\n## Features\n\n- Generate CSV \u0026 Excel files\n- Store spreadsheets to disk\n- Download spreadsheets as a Response object\n- Simple API for creating and manipulating spreadsheets\n- Performant \u0026 dependency-free\n- Library \u0026 CLI support\n- Fully typed\n\n## Usage\n\nThere are two ways to interact with `ts-spreadsheets`: via the CLI or as a library.\n\n### Library\n\nAs a library, you will want to make sure to install it in your project:\n\n```bash\nbun install ts-spreadsheets\n```\n\n_Now, you can use the library in your project:_\n\n```ts\nimport { createSpreadsheet, spreadsheet } from 'ts-spreadsheets'\n\n// Create a spreadsheet\nconst data = {\n  headings: ['Name', 'Age', 'City'],\n  data: [\n    ['Chris Breuer', 30, 'Playa Vista'],\n    ['Avery Hill', 25, 'Santa Monica'],\n    ['Danny Johnson', 35, 'San Francisco']\n  ]\n}\n\n// Generate and manipulate spreadsheets\n\n// 1. Using createSpreadsheet function\nconst spreadsheet = createSpreadsheet(data) // defaults to csv\nconst csvSpreadsheet = createSpreadsheet(data, { type: 'csv' })\nconst excelSpreadsheet = createSpreadsheet(data, { type: 'excel' })\n\n// Store the spreadsheet to disk\nawait spreadsheet.store('output.csv')\n\n// Create a download response\nconst response1 = excelSpreadsheet.download('data.xlsx') // downloads and stores as data.xlsx on your filesystem\n\n// 2. Using spreadsheet object directly, and chain if desired\nconst csvContent = spreadsheet(data).generateCSV().store('output2.csv')\nconst csvContent2 = spreadsheet(data).csv().store('output3.csv') // same as above\n\nconst excelContent = spreadsheet(data).generateExcel()\nawait excelContent.store('output3.xlsx')\nconst response2 = await excelContent.download('output3.xlsx') // downloads and stores as output3.xlsx\n\n// 3. Accessing raw content\nconst rawCsvContent = spreadsheet(data).csv().getContent()\nconst rawCsvContent2 = spreadsheet(data).generateCSV().getContent()\nconst rawExcelContent = spreadsheet(data).excel().getContent()\nconst rawExcelContent2 = spreadsheet(data).generateExcel().getContent()\n\nconsole.log('CSV Content:', rawCsvContent)\nconsole.log('Excel Content:', rawExcelContent)\n```\n\n### Main Functions\n\n#### spreadsheet(data: Content)\n\nCreates a spreadsheet object with various methods.\n\n- `data`: An object containing `headings` and `data` for the spreadsheet.\n\nReturns an object with the following methods:\n\n- `csv()`: Generates a CSV SpreadsheetWrapper\n- `excel()`: Generates an Excel SpreadsheetWrapper\n- `store(path: string)`: Stores the spreadsheet to a file\n- `generateCSV()`: Generates a CSV SpreadsheetWrapper\n- `generateExcel()`: Generates an Excel SpreadsheetWrapper\n\n_Example:_\n\n```typescript\nconst csvWrapper = await spreadsheet(data).csv() // equivalent to spreadsheet(data).generateCSV()\n```\n\n#### createSpreadsheet(data: Content, options?: SpreadsheetOptions)\n\nCreates a SpreadsheetWrapper with the given data and options.\n\n- `data`: An object containing `headings` and `data` for the spreadsheet.\n- `options`: Optional. An object specifying the spreadsheet type ('csv' or 'excel').\n\nReturns a SpreadsheetWrapper.\n\n_Example:_\n\n```typescript\nconst spreadsheet = createSpreadsheet(data, { type: 'csv' })\n```\n\n### SpreadsheetWrapper Methods\n\n#### getContent()\n\nReturns the content of the spreadsheet as a string or Uint8Array.\n\n#### download(filename: string)\n\nCreates a download Response for the spreadsheet.\n\n- `filename`: The name of the file to be downloaded.\n\nReturns a Response object.\n\n#### store(path: string)\n\nStores the spreadsheet to a file.\n\n- `path`: The file path where the spreadsheet will be stored.\n\nReturns a Promise that resolves when the file is written.\n\n### Utility Functions\n\n#### spreadsheet.create(data: Content, options?: SpreadsheetOptions)\n\nCreates a SpreadsheetContent object.\n\n- `data`: An object containing `headings` and `data` for the spreadsheet.\n- `options`: Optional. An object specifying the spreadsheet type ('csv' or 'excel').\n\nReturns a SpreadsheetContent object.\n\n#### spreadsheet.generate(data: Content, options?: SpreadsheetOptions)\n\nGenerates spreadsheet content based on the given data and options.\n\n- `data`: An object containing `headings` and `data` for the spreadsheet.\n- `options`: Optional. An object specifying the spreadsheet type ('csv' or 'excel').\n\nReturns a string or Uint8Array representing the spreadsheet content.\n\n#### spreadsheet.generateCSV(content: Content)\n\nGenerates a CSV SpreadsheetWrapper.\n\n- `content`: An object containing `headings` and `data` for the spreadsheet.\n\nReturns a SpreadsheetWrapper for CSV, which can be used to chain other methods like `store()` or `download()`.\n\n_Example:_\n\n```typescript\nawait spreadsheet(data).generateCSV().store('output.csv')\n\n// if one can rely on the file extension to determine the type, you may do this:\nawait spreadsheet(data).store('output.csv')\n```\n\n#### spreadsheet.generateExcel(content: Content)\n\nGenerates an Excel SpreadsheetWrapper.\n\n- `content`: An object containing `headings` and `data` for the spreadsheet.\n\nReturns a SpreadsheetWrapper for Excel, which can be used to chain other methods like `store()` or `download()`.\n\n_Example:_\n\n```ts\nawait spreadsheet(data).store('output.xlsx')\n// or\nawait spreadsheet(data).generateExcel().store('output.xlsx')\n```\n\nTo view the full documentation, please visit [https://ts-spreadsheets.netlify.app](https://ts-spreadsheets.netlify.app).\n\n### CLI\n\nYou can also use the CLI to generate spreadsheets from JSON input:\n\n```bash\n# Create a spreadsheet from JSON input\nspreadsheets create data.json -o output.csv\nspreadsheets create data.json --type excel -o output.xlsx\n\n# Convert between formats\nspreadsheets convert input.csv output.xlsx\nspreadsheets convert input.xlsx output.csv\n\n# Validate JSON input format\nspreadsheets validate input.json\n```\n\nThe input json should follow this format:\n\n```json\n{\n  \"headings\": [\"Name\", \"Age\", \"City\"],\n  \"data\": [\n    [\"Chris Breuer\", 30, \"Playa Vista\"],\n    [\"Avery Hill\", 25, \"Santa Monica\"],\n    [\"Danny Johnson\", 35, \"San Francisco\"]\n  ]\n}\n```\n\n#### CLI Commands\n\n- `create`: Generate a spreadsheet from JSON input\n  - Options:\n    - `-t, --type \u003ctype\u003e`: Output type ('csv' or 'excel'), defaults to 'csv'\n    - `-o, --output \u003cpath\u003e`: Output file path\n- `convert`: Convert between spreadsheet formats\n  - Automatically detects format from file extensions\n  - Supports conversion between CSV and Excel formats\n- `validate`: Check if JSON input meets the required format\n  - Validates structure and data types\n  - Provides helpful error messages for invalid input\n\nAll commands support the `--help` flag for more information:\n\n```bash\nspreadsheets --help\nspreadsheets create --help\nspreadsheets convert --help\nspreadsheets validate --help\n```\n\n## Testing\n\n```bash\nbun test\n```\n\n## Changelog\n\nPlease see our [releases](https://github.com/stacksjs/stacks/releases) page for more information on what has changed recently.\n\n## Contributing\n\nPlease review the [Contributing Guide](https://github.com/stacksjs/contributing) for details.\n\n## Community\n\nFor help, discussion about best practices, or any other conversation that would benefit from being searchable:\n\n[Discussions on GitHub](https://github.com/stacksjs/stacks/discussions)\n\nFor casual chit-chat with others using this package:\n\n[Join the Stacks Discord Server](https://discord.gg/stacksjs)\n\n## Postcardware\n\n“Software that is free, but hopes for a postcard.” We love receiving postcards from around the world showing where `ts-spreadsheets` is being used! We showcase them on our website too.\n\nOur address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States 🌎\n\n## Sponsors\n\nWe would like to extend our thanks to the following sponsors for funding Stacks development. If you are interested in becoming a sponsor, please reach out to us.\n\n- [JetBrains](https://www.jetbrains.com/)\n- [The Solana Foundation](https://solana.com/)\n\n## Credits\n\n- [Chris Breuer](https://github.com/chrisbbreuer)\n- [All Contributors](https://github.com/stacksjs/ts-spreadsheets/contributors)\n\n## License\n\nThe MIT License (MIT). Please see [LICENSE](https://github.com/stacksjs/ts-spreadsheets/tree/main/LICENSE.md) for more information.\n\nMade with 💙\n\n\u003c!-- Badges --\u003e\n[npm-version-src]: https://img.shields.io/npm/v/ts-spreadsheets?style=flat-square\n[npm-version-href]: https://npmjs.com/package/ts-spreadsheets\n[github-actions-src]: https://img.shields.io/github/actions/workflow/status/stacksjs/ts-spreadsheets/ci.yml?style=flat-square\u0026branch=main\n[github-actions-href]: https://github.com/stacksjs/ts-spreadsheets/actions?query=workflow%3Aci\n\n\u003c!-- [codecov-src]: https://img.shields.io/codecov/c/gh/stacksjs/ts-spreadsheets/main?style=flat-square\n[codecov-href]: https://codecov.io/gh/stacksjs/ts-spreadsheets --\u003e\n","funding_links":["https://github.com/sponsors/stacksjs","https://github.com/sponsors/chrisbbreuer","https://opencollective.com/stacksjs"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstacksjs%2Fts-spreadsheets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstacksjs%2Fts-spreadsheets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstacksjs%2Fts-spreadsheets/lists"}