{"id":16806034,"url":"https://github.com/haltcase/tablemark","last_synced_at":"2025-04-07T10:23:36.364Z","repository":{"id":57376318,"uuid":"79743728","full_name":"haltcase/tablemark","owner":"haltcase","description":"Generate markdown tables from JSON data.","archived":false,"fork":false,"pushed_at":"2024-04-02T23:27:11.000Z","size":109,"stargazers_count":75,"open_issues_count":0,"forks_count":12,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-05-02T04:34:56.656Z","etag":null,"topics":["array","convert","generate","hacktoberfest","json","json-data","markdown","table","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/haltcase.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"license","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":"2017-01-22T20:30:57.000Z","updated_at":"2024-06-18T14:05:43.926Z","dependencies_parsed_at":"2024-06-18T14:05:41.921Z","dependency_job_id":"f63a16b3-e8f6-4387-9240-479bddbfc3b5","html_url":"https://github.com/haltcase/tablemark","commit_stats":null,"previous_names":["citycide/tablemark"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haltcase%2Ftablemark","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haltcase%2Ftablemark/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haltcase%2Ftablemark/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haltcase%2Ftablemark/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/haltcase","download_url":"https://codeload.github.com/haltcase/tablemark/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247632686,"owners_count":20970202,"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":["array","convert","generate","hacktoberfest","json","json-data","markdown","table","typescript"],"created_at":"2024-10-13T09:49:55.532Z","updated_at":"2025-04-07T10:23:36.331Z","avatar_url":"https://github.com/haltcase.png","language":"TypeScript","readme":"# tablemark \u0026middot; [![Version](https://flat.badgen.net/npm/v/tablemark)](https://www.npmjs.com/package/tablemark) [![License](https://flat.badgen.net/npm/license/tablemark)](https://www.npmjs.com/package/tablemark) [![TypeScript](https://flat.badgen.net/badge/written%20in/TypeScript/294E80)](http://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html) [![GitHub Actions](https://flat.badgen.net/github/checks/haltcase/tablemark)](https://github.com/haltcase/tablemark/actions)\n\n\u003e Generate markdown tables from JSON data.\n\nRenders arrays of objects as markdown tables, complete with configuration\nfor renaming columns and left, center, or right-aligning them.\n\n## installation\n\n```sh\nyarn add tablemark\n\n# or\n\nnpm install tablemark\n```\n\n## usage\n\n```js\nimport tablemark from \"tablemark\"\n```\n\n```js\ntablemark([\n  { name: \"Bob\", age: 21, isCool: false },\n  { name: \"Sarah\", age: 22, isCool: true },\n  { name: \"Lee\", age: 23, isCool: true }\n])\n\n// | Name  | Age   | Is cool |\n// | :---- | :---- | :------ |\n// | Bob   | 21    | false   |\n// | Sarah | 22    | true    |\n// | Lee   | 23    | true    |\n```\n\n... displays as:\n\n\u003c!-- prettier-ignore-start --\u003e\n| Name  | Age   | Is cool |\n| :---- | :---- | :------ |\n| Bob   | 21    | false   |\n| Sarah | 22    | true    |\n| Lee   | 23    | true    |\n\u003c!-- prettier-ignore-end --\u003e\n\n## api\n\n```ts\ntablemark (input: InputData, options?: TablemarkOptions): string\n```\n\n\u003e **Arguments**\n\n- `InputData` input: the data to table-ify\n  - an array of objects or iterables\n- `TablemarkOptions` options:\n\n  |         key          |                type                 |  default   | description                                                     |\n  | :------------------: | :---------------------------------: | :--------: | --------------------------------------------------------------- |\n  |      `columns`       | `Array\u003cstring \\| ColumnDescriptor\u003e` |     -      | Array of column descriptors.                                    |\n  |    `caseHeaders`     |              `boolean`              |   `true`   | Sentence case headers derived from keys.                        |\n  |     `toCellText`     |    `(input: unknown) =\u003e string`     |     -      | Provide a custom \"toString\" function.                           |\n  | `padHeaderSeparator` |              `boolean`              |   `true`   | Whether to pad gutters of the header separator (alignment) row. |\n  |     `wrapWidth`      |              `number`               | `Infinity` | Wrap cell text at this length.                                  |\n  |  `wrapWithGutters`   |              `boolean`              |  `false`   | Add sides (`\\| \u003ccontent\u003e \\|`) to wrapped rows.                  |\n  |     `lineEnding`     |              `string`               |   `\"\\n\"`   | String used at end-of-line.                                     |\n\nThe `columns` array can either contain objects, in which case their\n`name` and `align` properties will be used to alter the display of\nthe column in the table, or any other type which will be coerced\nto a string if necessary and used as a replacement for the column\nname.\n\n\u003e **Returns**\n\n`string`: the resulting markdown formatted table\n\n\u003e **Throws**\n\n`TypeError`: when `input` is not iterable (e.g., an array)\u003cbr /\u003e\n`TypeError`: when an unknown column alignment option is provided\n\n### `options.columns`\n\n```js\ntablemark(\n  [\n    { name: \"Bob\", age: 21, isCool: false },\n    { name: \"Sarah\", age: 22, isCool: true },\n    { name: \"Lee\", age: 23, isCool: true }\n  ],\n  {\n    columns: [\n      \"first name\",\n      { name: \"how old\", align: \"center\" },\n      \"are they cool\"\n    ]\n  }\n)\n\n// | first name | how old | are they cool |\n// | :--------- | :-----: | :------------ |\n// | Bob        |   21    | false         |\n// | Sarah      |   22    | true          |\n// | Lee        |   23    | true          |\n```\n\n... displays as:\n\n\u003c!-- prettier-ignore-start --\u003e\n| first name | how old | are they cool |\n| :--------- | :-----: | :------------ |\n| Bob        |   21    | false         |\n| Sarah      |   22    | true          |\n| Lee        |   23    | true          |\n\u003c!-- prettier-ignore-end --\u003e\n\n### `options.padHeaderSeparator`\n\n```js\ntablemark(\n  [\n    { name: \"Bob\", age: 21, isCool: false },\n    { name: \"Sarah\", age: 22, isCool: true },\n    { name: \"Lee\", age: 23, isCool: true }\n  ],\n  {\n    columns: [{ align: \"left\" }, { align: \"center\" }, { align: \"right\" }]\n  }\n)\n\n// | first name | how old | are they cool |\n// |:-----------|:-------:|--------------:|\n// | Bob        |   21    | false         |\n// | Sarah      |   22    | true          |\n// | Lee        |   23    | true          |\n```\n\n... displays as:\n\n\u003c!-- prettier-ignore-start --\u003e\n| first name | how old | are they cool |\n|:-----------|:-------:|--------------:|\n| Bob        |   21    | false         |\n| Sarah      |   22    | true          |\n| Lee        |   23    | true          |\n\u003c!-- prettier-ignore-end --\u003e\n\n### `options.toCellText`\n\n```js\ntablemark(\n  [\n    { name: \"Bob\", pet_owner: true, studying: false },\n    { name: \"Sarah\", pet_owner: false, studying: true },\n    { name: \"Sarah\", pet_owner: true, studying: true }\n  ],\n  {\n    toCellText,\n    columns: [{ align: \"left\" }, { align: \"center\" }, { align: \"center\" }]\n  }\n)\n\nfunction toCellText(v) {\n  if (v === true) return \"✔\"\n  if (!v) return \"\"\n  return v\n}\n\n// | Name  | Pet owner | Studying |\n// | :---- | :-------: | :------: |\n// | Bob   |     ✔︎     |          |\n// | Sarah |           |    ✔     |\n// | Lee   |     ✔     |    ✔     |\n```\n\n### `options.wrapWidth`\n\nSet `options.wrapWidth` to wrap any content at that length onto a new\nadjacent line:\n\n```js\ntablemark(\n  [\n    { star: false, name: \"Benjamin\" },\n    { star: true, name: \"Jet Li\" }\n  ],\n  { wrapWidth: 5 }\n)\n\n// | Star  | Name  |\n// | :---- | :---- |\n// | false | Benja |\n//           min\n// | true  | Jet   |\n//           Li\n```\n\n\u003e To output valid [GitHub Flavored Markdown](https://github.github.com/gfm/) a\n\u003e cell must not contain newlines. Consider replacing those with `\u003cbr /\u003e` (e.g.,\n\u003e using `options.toCellText`).\n\n### `options.wrapWithGutters`\n\nEnable `wrapWithGutters` to add pipes on all lines:\n\n```js\ntablemark(\n  [\n    { star: false, name: \"Benjamin\" },\n    { star: true, name: \"Jet Li\" }\n  ],\n  { wrapWidth: 5, wrapWithGutters: true }\n)\n\n// | Star  | Name  |\n// | :---- | :---- |\n// | false | Benja |\n// |       | min   |\n// | true  | Jet   |\n// |       | Li    |\n```\n\n## see also\n\n- [`tablemark-cli`](https://github.com/haltcase/tablemark-cli) \u0026ndash; use this module from the command line\n\n## contributing\n\nSearch the [issues](https://github.com/haltcase/tablemark) if you come\nacross any trouble, open a new one if it hasn't been posted, or, if you're\nable, open a [pull request](https://help.github.com/articles/about-pull-requests/).\nContributions of any kind are welcome in this project.\n\nThe following people have already contributed their time and effort:\n\n- Thomas Jensen (**[@tjconcept](https://github.com/tjconcept)**)\n\nThank you!\n\n## license\n\nMIT © Bo Lingen / haltcase\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaltcase%2Ftablemark","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhaltcase%2Ftablemark","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaltcase%2Ftablemark/lists"}