{"_id":"@alexdee2007/json5-to-table","_rev":"5-8a1618cecef13dcd9af630d74e433af0","name":"@alexdee2007/json5-to-table","dist-tags":{"latest":"0.2.5"},"versions":{"0.2.0":{"name":"@alexdee2007/json5-to-table","version":"0.2.0","description":"A tool for converting JSON data into tables, supports deep nested data, and supports schema definition","main":"dist/bundle.js","bin":{"json5-to-table":"bin/json5-to-table"},"repository":{"type":"git","url":"git+https://github.com/alexdee2007/json5-to-table.git"},"author":{"name":"hi@yet.run"},"license":"Apache-2.0","scripts":{"build":"webpack","test":"ava","prepublish":"yarn build"},"ava":{"files":["test/**/*.test.js"]},"keywords":["nested","json","table","schema","html","excel","json-to-table"],"devDependencies":{"@babel/core":"^7.15.5","@babel/preset-env":"^7.15.6","ava":"^3.15.0","babel-loader":"^8.2.2","webpack":"^5.51.1","webpack-cli":"^4.8.0"},"dependencies":{"json5":"^2.2.0","lodash":"^4.17.21","yargs":"^17.1.1"},"gitHead":"69415e5fc4d043dd933a56d465be16d73c244281","bugs":{"url":"https://github.com/alexdee2007/json5-to-table/issues"},"homepage":"https://github.com/alexdee2007/json5-to-table#readme","_id":"@alexdee2007/json5-to-table@0.2.0","_nodeVersion":"16.17.0","_npmVersion":"8.15.0","dist":{"integrity":"sha512-4kv/Qn5I7ouwTYlNvZeqMkvLQwKea6TBi9uz0dIBt0VtFxf1YGAQi8ehE5pnFZ6udPctblPsiWelQ2ViC6w93w==","shasum":"3b5e26c4ad05f2737d3e99be09efe660ab7527fd","tarball":"https://registry.npmjs.org/@alexdee2007/json5-to-table/-/json5-to-table-0.2.0.tgz","fileCount":5,"unpackedSize":78578,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDFjwfuLcJyDJCaP4+bJ3rLnXYShlQam6qF3/QxMgoeaQIgQE+GJzmStRVDUP84L7Ox0h250x1LoTRhJoRmB7Cccao="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJj80gOACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrzSQ/7BDCCSTWHEcFjuDm1GAlpPCLXqNZiLnIFStzxtge3MQvik/p5\r\nOMDXU+baeGj4Ek4cbpLM+12eTRpP8H8CSdnrZ36OEv3spSQiK4Ls5LIitaDe\r\nzA5DYdBcnKtx2WNKdZBUTy7y3l2xYcZN2O189ZMjQ1jwNhp/4bRUKbc2rQI5\r\nDWRC4eOYeUNgmK+cPwGNFzB5FGx2Az/olKQGKmggxS5b3GC9XQ7lsSJcFXOh\r\n4usJaJ9yTXe1fz/ITLNSiWrK2oMMhTDHY+4zppQdPN4T+I1xxHQ71BldPudX\r\nNn1JVG67Btkfbk6EWvBg4+qI0i0zFXaY5LiJuHPwmc3LWoFvsltyHFGKWfBp\r\naeucHnAJa1XoeHsaog/4qR642F6fBoHZcjUYgdkYUP8WKhvl+dTkmAODGSkw\r\nhWwMGUHXVDolM0cUGKJnVi381TcOo9dkdWDXguR0cyHaR8RajT07wgNJTuDU\r\nUTUVr9e1MdycG5cBrc4q+na4UnO7IcBqG4PokC0V7/DxAoijiQkBnfEUPXx0\r\n04ns6J+H6XyZZTm7yTwIorhbFnHtuGrDr7poIqBuTtvd3fBHannEAEg1TQVj\r\nIFx3RXX7v2eL4iqblQjYZsEgSGvZrK3+AQOYn+M3MPTWLwQ+yDqb/EBTbagV\r\nJ9Ht6y0RjzEEGyhCu1pqDwwGVfl7l3ScxNE=\r\n=0wL2\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"alexdee2007","email":"alexdee2007@bk.ru"},"directories":{},"maintainers":[{"name":"alexdee2007","email":"alexdee2007@bk.ru"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/json5-to-table_0.2.0_1676888077892_0.2878001862604871"},"_hasShrinkwrap":false},"0.2.1":{"name":"@alexdee2007/json5-to-table","version":"0.2.1","description":"A tool for converting JSON data into tables, supports deep nested data, and supports schema definition","main":"dist/bundle.js","bin":{"json5-to-table":"bin/json5-to-table"},"repository":{"type":"git","url":"git+https://github.com/alexdee2007/json5-to-table.git"},"author":{"name":"hi@yet.run"},"license":"Apache-2.0","scripts":{"build":"webpack","test":"ava","prepublish":"yarn build"},"ava":{"files":["test/**/*.test.js"]},"keywords":["nested","json","table","schema","html","excel","json-to-table"],"devDependencies":{"@babel/core":"^7.15.5","@babel/preset-env":"^7.15.6","ava":"^3.15.0","babel-loader":"^8.2.2","webpack":"^5.51.1","webpack-cli":"^4.8.0"},"dependencies":{"json5":"^2.2.0","lodash":"^4.17.21","yargs":"^17.1.1"},"gitHead":"9dd5d60efb8b6ed04dfb571152bb810a42ebfaa4","bugs":{"url":"https://github.com/alexdee2007/json5-to-table/issues"},"homepage":"https://github.com/alexdee2007/json5-to-table#readme","_id":"@alexdee2007/json5-to-table@0.2.1","_nodeVersion":"18.16.0","_npmVersion":"9.5.1","dist":{"integrity":"sha512-Q6YeG/oidsfKcaYDeVdbP2Ko03ZyqN5C8sWH+NbIcneMLJJUfG8Y7ctNHJj09AnrYPnpWU3h6pCn3F/C/fZMmQ==","shasum":"f60c375947966e8423599ea72e19129ccc41285c","tarball":"https://registry.npmjs.org/@alexdee2007/json5-to-table/-/json5-to-table-0.2.1.tgz","fileCount":5,"unpackedSize":78578,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCossZ7TmfJBUm42gVyYl3r+w4e8Xv/HTXtgHN2XpvFVAIgItn/BQhc8y71+q1fzmNXsBa+wfqpiKYrnc2Z1KBOIgg="}]},"_npmUser":{"name":"alexdee2007","email":"alexdee2007@bk.ru"},"directories":{},"maintainers":[{"name":"alexdee2007","email":"alexdee2007@bk.ru"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/json5-to-table_0.2.1_1698847880259_0.11430280600877185"},"_hasShrinkwrap":false},"0.2.2":{"name":"@alexdee2007/json5-to-table","version":"0.2.2","description":"A tool for converting JSON data into tables, supports deep nested data, and supports schema definition","main":"dist/bundle.js","bin":{"json5-to-table":"bin/json5-to-table"},"repository":{"type":"git","url":"git+https://github.com/alexdee2007/json5-to-table.git"},"author":{"name":"hi@yet.run"},"license":"Apache-2.0","scripts":{"build":"webpack","test":"ava","prepublish":"yarn build"},"ava":{"files":["test/**/*.test.js"]},"keywords":["nested","json","table","schema","html","excel","json-to-table"],"devDependencies":{"@babel/core":"^7.15.5","@babel/preset-env":"^7.15.6","ava":"^3.15.0","babel-loader":"^8.2.2","webpack":"^5.51.1","webpack-cli":"^4.8.0"},"dependencies":{"json5":"^2.2.0","lodash":"^4.17.21","yargs":"^17.1.1"},"gitHead":"b6761888bbd4f6ef47ad84abd93f832c941b8d3a","bugs":{"url":"https://github.com/alexdee2007/json5-to-table/issues"},"homepage":"https://github.com/alexdee2007/json5-to-table#readme","_id":"@alexdee2007/json5-to-table@0.2.2","_nodeVersion":"18.16.0","_npmVersion":"9.5.1","dist":{"integrity":"sha512-a0H1DL8EmP1q3pw4ppCU4zpJWtVQwgQGw92crBIrB5yCeCvjqrrhj3gTGJGJID+RFnENdmGKwkzTK1v+7Lyg8A==","shasum":"35ec780fd25a749ab4885c3b7170670f3d9509db","tarball":"https://registry.npmjs.org/@alexdee2007/json5-to-table/-/json5-to-table-0.2.2.tgz","fileCount":6,"unpackedSize":79324,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDMLfq7N9Lfj6UchxSX+wqa1AHx6N3zHVCsm1L2GffVRAIhAK0kcZJ5kqRffh8+3BNRxhpoETbibWGfnnSWgsykwDqi"}]},"_npmUser":{"name":"alexdee2007","email":"alexdee2007@bk.ru"},"directories":{},"maintainers":[{"name":"alexdee2007","email":"alexdee2007@bk.ru"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/json5-to-table_0.2.2_1698946423270_0.34537826618556755"},"_hasShrinkwrap":false},"0.2.3":{"name":"@alexdee2007/json5-to-table","version":"0.2.3","description":"A tool for converting JSON data into tables, supports deep nested data, and supports schema definition","main":"dist/bundle.js","bin":{"json5-to-table":"bin/json5-to-table"},"repository":{"type":"git","url":"git+https://github.com/alexdee2007/json5-to-table.git"},"author":{"name":"hi@yet.run"},"license":"Apache-2.0","scripts":{"build":"webpack","test":"ava","prepublish":"yarn build"},"ava":{"files":["test/**/*.test.js"]},"keywords":["nested","json","table","schema","html","excel","json-to-table"],"devDependencies":{"@babel/core":"^7.15.5","@babel/preset-env":"^7.15.6","ava":"^3.15.0","babel-loader":"^8.2.2","webpack":"^5.51.1","webpack-cli":"^4.8.0"},"dependencies":{"json5":"^2.2.0","lodash":"^4.17.21","yargs":"^17.1.1"},"gitHead":"f387ff221127bc45a3e383c60d8b95904161e3bb","bugs":{"url":"https://github.com/alexdee2007/json5-to-table/issues"},"homepage":"https://github.com/alexdee2007/json5-to-table#readme","_id":"@alexdee2007/json5-to-table@0.2.3","_nodeVersion":"18.16.0","_npmVersion":"9.5.1","dist":{"integrity":"sha512-WFZDrCqvjAF4iiq4GQjyNTH07kpS22ive53VQ2s2ppN1ZhYXyrYbno8uJRgBV720IZjiyNc515BiYy30qZgUqg==","shasum":"5bead582e81d69a83e8b555e45a28015b0ee6ca2","tarball":"https://registry.npmjs.org/@alexdee2007/json5-to-table/-/json5-to-table-0.2.3.tgz","fileCount":6,"unpackedSize":82953,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDBg4N267CJdK59fXqfpvW9DfSqw2XVNOWyddcFmoQb6AIgPBLMO/T7dh0Ze+TPdy9w4B3Qhq9GKK4V1+EhN5iIie0="}]},"_npmUser":{"name":"alexdee2007","email":"alexdee2007@bk.ru"},"directories":{},"maintainers":[{"name":"alexdee2007","email":"alexdee2007@bk.ru"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/json5-to-table_0.2.3_1699293497958_0.4435597912617213"},"_hasShrinkwrap":false},"0.2.4":{"name":"@alexdee2007/json5-to-table","version":"0.2.4","description":"A tool for converting JSON data into tables, supports deep nested data, and supports schema definition","main":"dist/bundle.js","bin":{"json5-to-table":"bin/json5-to-table"},"repository":{"type":"git","url":"git+https://github.com/alexdee2007/json5-to-table.git"},"author":{"name":"hi@yet.run"},"license":"Apache-2.0","scripts":{"build":"webpack","test":"ava","prepublish":"yarn build"},"ava":{"files":["test/**/*.test.js"]},"keywords":["nested","json","table","schema","html","excel","json-to-table"],"devDependencies":{"@babel/core":"^7.15.5","@babel/preset-env":"^7.15.6","ava":"^3.15.0","babel-loader":"^8.2.2","webpack":"^5.51.1","webpack-cli":"^4.8.0"},"dependencies":{"json5":"^2.2.0","lodash":"^4.17.21","yargs":"^17.1.1"},"_id":"@alexdee2007/json5-to-table@0.2.4","gitHead":"199153d5e5370815da5dafe22daf60bbeb63e48d","bugs":{"url":"https://github.com/alexdee2007/json5-to-table/issues"},"homepage":"https://github.com/alexdee2007/json5-to-table#readme","_nodeVersion":"20.9.0","_npmVersion":"10.2.4","dist":{"integrity":"sha512-HWZpDC11dQXZHpk6feMyacapWt+v6WWfq1DzMTi8LiQpuIK6CoGLepyVUYnB4W2dIh18N6pGJccmznkgHoUX3g==","shasum":"328371ad23414a6e3d58e0d8d5e3197b55cf9877","tarball":"https://registry.npmjs.org/@alexdee2007/json5-to-table/-/json5-to-table-0.2.4.tgz","fileCount":6,"unpackedSize":79254,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCi7orayw4NpquQlokgZoedQFK4zUnj1UCzN0V1nYMbQwIgO8HZ1YHRGjV1PAnexpnS+tFygVAZlT/HA9zY+NPGDtQ="}]},"_npmUser":{"name":"alexdee2007","email":"alexdee2007@bk.ru"},"directories":{},"maintainers":[{"name":"alexdee2007","email":"alexdee2007@bk.ru"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/json5-to-table_0.2.4_1701892055411_0.44373902044227775"},"_hasShrinkwrap":false},"0.2.5":{"name":"@alexdee2007/json5-to-table","version":"0.2.5","description":"A tool for converting JSON data into tables, supports deep nested data, and supports schema definition","main":"dist/bundle.js","bin":{"json5-to-table":"bin/json5-to-table"},"repository":{"type":"git","url":"git+https://github.com/alexdee2007/json5-to-table.git"},"author":{"name":"hi@yet.run"},"license":"Apache-2.0","scripts":{"build":"webpack","test":"ava","prepublish":"yarn build"},"ava":{"files":["test/**/*.test.js"]},"keywords":["nested","json","table","schema","html","excel","json-to-table"],"devDependencies":{"@babel/core":"^7.15.5","@babel/preset-env":"^7.15.6","ava":"^3.15.0","babel-loader":"^8.2.2","webpack":"^5.51.1","webpack-cli":"^4.8.0"},"dependencies":{"json5":"^2.2.0","lodash":"^4.17.21","yargs":"^17.1.1"},"_id":"@alexdee2007/json5-to-table@0.2.5","gitHead":"71c07cb21528f1c05b1f9e3208d1f50e13dff686","bugs":{"url":"https://github.com/alexdee2007/json5-to-table/issues"},"homepage":"https://github.com/alexdee2007/json5-to-table#readme","_nodeVersion":"20.9.0","_npmVersion":"10.2.4","dist":{"integrity":"sha512-NFpip6Lk+JcnlMpLk6EmtltX7EjOjHoln+MnRzt4Zy5vJCea7B8G+6gpoWMon4CrPJkB6YKRzBM5oF4YqtbU5A==","shasum":"1545f50bd489f0db7f64f45579f9b4d56416e47c","tarball":"https://registry.npmjs.org/@alexdee2007/json5-to-table/-/json5-to-table-0.2.5.tgz","fileCount":6,"unpackedSize":79534,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCQoEDI6w5iB2b9mFZgTafy9CvoeFeMMHmp5ZMb3MKLfAIgF3FxLV1pU/Dj9iWow3BhA94ffm08fDMpM/2dnP2agYg="}]},"_npmUser":{"name":"alexdee2007","email":"alexdee2007@bk.ru"},"directories":{},"maintainers":[{"name":"alexdee2007","email":"alexdee2007@bk.ru"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/json5-to-table_0.2.5_1701894151650_0.3597501804223029"},"_hasShrinkwrap":false}},"time":{"created":"2023-02-20T10:14:37.839Z","0.2.0":"2023-02-20T10:14:38.084Z","modified":"2023-12-06T20:22:32.096Z","0.2.1":"2023-11-01T14:11:20.413Z","0.2.2":"2023-11-02T17:33:43.466Z","0.2.3":"2023-11-06T17:58:18.133Z","0.2.4":"2023-12-06T19:47:35.601Z","0.2.5":"2023-12-06T20:22:31.936Z"},"maintainers":[{"name":"alexdee2007","email":"alexdee2007@bk.ru"}],"description":"A tool for converting JSON data into tables, supports deep nested data, and supports schema definition","homepage":"https://github.com/alexdee2007/json5-to-table#readme","keywords":["nested","json","table","schema","html","excel","json-to-table"],"repository":{"type":"git","url":"git+https://github.com/alexdee2007/json5-to-table.git"},"author":{"name":"hi@yet.run"},"bugs":{"url":"https://github.com/alexdee2007/json5-to-table/issues"},"license":"Apache-2.0","readme":"#json5-to-table\n\n> One of the best tools for converting JSON data into a table structure.\n\nAfter a series of polishing, it can be said that `json5-to-table` is currently one of the most convenient tools for converting JSON data into tables. It supports:\n\n- Nested JSON data, including arbitrarily deep arrays, objects, etc.\n- Built-in support for generating HTML and Excel formats.\n- Customizable headers.\n- Easy to expand, use the native `generateTable` function to assist in generating arbitrary formats.\n- Provides a command-line tool for cross-language development.\n\n## Install\n\nIt is recommended to install using Yarn or NPM:\n\n```bash\n//With Yarn\n$ yarn add json5-to-table\n\n// Or with NPM\n$ npm install json5-to-table\n```\n\nIt can also be installed globally in order to use the command line tools:\n\n```bash\n// Global install with Yarn\n$ yarn global add json5-to-table\n\n// Or global install with NPM\n$ npm install --global json5-to-table\n```\n\nYou can also add a script tag in the browser (please replace 0.1.x with the correct version, the released version can be viewed in [Releases](https://github.com/yetrun/json5-to-table/releases) ):\n\n```html\n<script\n  lang=\"javascript\"\n  src=\"https://github.com/yetrun/json5-to-table/releases/download/0.1.x/json5-to-table.js\"\n></script>\n```\n\nGenerate HTML format is supported by default. If you need to generate Excel format, you need to install the dependency package at the same time:\n\n```bash\n$ yarn add xlsx\n```\n\n## use\n\n### Import function and call\n\nIf installed via Yarn or NPM, import functions using CommonJS or ES6 syntax, e.g.\n\n```javascript\nimport { generateTable, generateHTMLTable, generateExcel, parseDataToSchema } from \"json5-to-table\";\n```\n\nIf used in a browser, use the global variable `JSON5_TO_TABLE`:\n\n```javascript\nconst { generateTable, generateHTMLTable, generateExcel, parseDataToSchema } = JSON5_TO_TABLE;\n```\n\nThen call the function to generate the table structure, for example, the following is to generate a table in HTML format:\n\n```javascript\nconst data = [\n  {\n    name: \"Jim\",\n    age: 18,\n    courses: [\n      { name: \"Music\", duration: \"3 hours\" },\n      { name: \"Basketball\", duration: \"2 hours\" }\n    ]\n  },\n  {\n    name: \"Lucy\",\n    age: 17,\n    courses: [\n      { name: \"Music\", duration: \"2 hours\" },\n      { name: \"Painting\", duration: \"2 hours and 30 minutes\" },\n      { name: \"Yoga\", duration: \"1 hour and 40 minutes\" }\n    ]\n  }\n];\n\nconst schema = [\n  { title: \"Name\", path: \"name\" },\n  { title: \"Age\", path: \"age\" },\n  {\n    title: \"Courses\",\n    path: \"courses\",\n    props: [\n      { title: \"Course Name\", path: \"name\" },\n      { title: \"Learning Duration\", path: \"duration\" }\n    ]\n  }\n];\n\ngenerateHTMLTable(data, schema);\n```\n\nThe table thus generated looks like this:\n\n<table>\n   <thead>\n     <tr>\n       <th rowSpan=\"2\">Name</th>\n       <th rowSpan=\"2\">Age</th>\n       <th colSpan=\"2\">Courses</th>\n     </tr>\n     <tr>\n       <th>Course Name</th>\n       <th>Learning Duration</th>\n     </tr>\n   </thead>\n   <tbody>\n     <tr>\n       <td rowSpan=\"2\">Jim</td>\n       <td rowSpan=\"2\">18</td>\n       <td>Music</td>\n       <td>3 hours</td>\n     </tr>\n     <tr>\n       <td>Basketball</td>\n       <td>2 hours</td>\n     </tr>\n     <tr>\n       <td rowSpan=\"3\">Lucy</td>\n       <td rowSpan=\"3\">17</td>\n       <td>Music</td>\n       <td>2 hours</td>\n     </tr>\n     <tr>\n       <td>Painting</td>\n       <td>2 hours and 30 minutes</td>\n     </tr>\n     <tr>\n       <td>Yoga</td>\n       <td>1 hour and 40 minutes</td>\n     </tr>\n   </tbody>\n</table>\n### Using command line tools\n\nAfter installing the package globally, you can use the command line tool `json5-to-table`. Its usage is as follows:\n\n```bash\n// View help documentation\n$ json5-to-table -h\n\n// Generate a table in HTML format, and output the table to the console\n$ json5-to-table -d <data-file> -e <schema-file> -p <options-file>\n\n// Generate a table in Excel format, and output the table to the console\n$ json5-to-table -d <data-file> --excel\n```\n\n**scenes to be used**\n\n1. It can be used as a tool to generate HTML or Excel tables through the command line.\n2. It supports channels and can be connected to other languages.\n\n**Special Note**\n\n1. The file supports JSON5 format.\n\n2. `<data-file>` supports All In One format. When `<schema-file>` and `<options-file>` are not specified, and the content of `<data-file>` is the following structure, get `data`,`from`<data-file>` schema`, `options`:\n\n   ```javascript\n   // <data-file> content\n   {\n     \"data\": [\n       //...\n     ],\n     \"schema\": [\n       //...\n     ],\n     \"options\": {\n       //...\n     }\n   }\n   ```\n\n3. When the `<data-file>` parameter is not specified, read from standard input.\n\n## Customize header structure\n\n### The role of Schema\n\n#### Customize header fields\n\nThere is a piece of data:\n\n```javascript\nconst data = [\n  { a: 1, b: 2, c: 3 },\n  { a: 4, b: 5, c: 6 }\n];\n```\n\nI want to generate tables only for the fields `a` and `b`, and filter the field `c`. At this time, I can use Schema. The definition of Schema is as follows:\n\n```javascript\nconst schema = [{ path: \"a\" }, { path: \"b\" }];\n```\n\nThen call `generateHTMLTable(data, schema)`, the generated table header will be as follows:\n\n<table>\n   <tr>\n     <th>a</th>\n     <th>b</th>\n   </tr>\n</table>\n\n#### `title`: Customize header text\n\nFor the same data above, we want to display the table header in uppercase A and B, which can be achieved by configuring the `title` option:\n\n```javascript\nconst schema = [\n  { title: \"A\", path: \"a\" },\n  { title: \"B\", path: \"b\" }\n];\n```\n\nIn addition to regular text, `title` has the following two special uses:\n\n1. When `title` is not given, the text is exported by `path`. For example `{ path: 'a' }` is equivalent to `{ title: 'a', path: 'a' }`.\n2. When `title` is equal to a blank string, but the header does not occupy row cells. With this feature, the display of scalar arrays in rows can be realized. For details, please refer to [Show long text arrays in rows](#Display long text arrays in rows).\n\n#### `path`: attribute extraction path for custom columns\n\n`path` is used to customize the path to extract data from this column. It actually supports multiple usages, listed as follows:\n\n- `''`: Extract complete data.\n- `'a'`: Extract field `a`.\n- `'a.b.c'`: Extract fields `a`, `b`, `c` in sequence, and arrays can be handled well in the middle.\n\n#### `props`: custom nested properties\n\nIf the data contains deep nesting, the deep `schema` can be customized through the `props` option. An example is as follows:\n\n```javascript\nconst data = [\n  { a: 1, b: { c: 2, d: 3 } },\n  { a: 4, b: { c: 5, d: 6 } }\n];\n```\n\n```javascript\nconst schema = [{ path: \"a\" }, { path: \"b\", props: [{ path: \"c\" }, { path: \"d\" }] }];\n```\n\nAt this time, call `generateHTMLTable(data, schema)`, and the table header will display the nested format:\n\n<table>\n   <tr>\n     <th rowSpan=\"2\">a</th>\n     <th colSpan=\"2\">b</th>\n   </tr>\n   <tr>\n     <th>c</th>\n     <th>d</th>\n   </tr>\n</table>\n\n#### Processing of arrays\n\nWhen generating tables, arrays and objects are not treated differently, and objects can be regarded as arrays containing the same elements. In order to understand this, a few examples are given to illustrate.\n\nFor the following two data, the table structures generated by them are the same:\n\n```javascript\nconst data1 = { a: 1, b: 2, c: 3 };\n\nconst data2 = [{ a: 1, b: 2, c: 3 }];\n```\n\nEven though inner fields are arrays, their generated format remains the same:\n\n```javascript\nconst data1 = [{ a: 1, b: { c: 2, d: 3 } }];\n\nconst data2 = [{ a: 1, b: [{ c: 2, d: 3 }] }];\n```\n\nThe following example illustrates how to display an array. First given an array (field `b`) with two elements inside:\n\n```JavaScript\nconst data = [\n   { a: 1, b: [\n     { c: 2, d: 3 },\n     { c: 4, d: 5 }\n   ]}\n]\n```\n\nGiven a Schema:\n\n```javascript\nconst schema = [{ path: \"a\" }, { path: \"b\", props: [{ path: \"c\" }, { path: \"d\" }] }];\n```\n\nThe resulting full table appears as:\n\n<table>\n   <thead>\n     <tr>\n       <th rowSpan=\"2\">a</th>\n       <th colSpan=\"2\">b</th>\n     </tr>\n     <tr>\n       <th>c</th>\n       <th>d</th>\n     </tr>\n   </thead>\n   <tbody>\n     <tr>\n       <td rowSpan=\"2\">1</td>\n       <td>2</td>\n       <td>3</td>\n     </tr>\n     <tr>\n       <td>4</td>\n       <td>5</td>\n     </tr>\n   </tbody>\n</table>\n\n### Data derivation table header\n\n#### Derivation method\n\nAny function that generates a table structure, including `generateTable`, `generateHTMLTable`, `generateExcel` contains two usages:\n\n1. Display the specified schema, for example:\n\n   ```javascript\n   generateHTMLTable(data, schema);\n   ```\n\n2. Implicit derivation of Schema, for example:\n   ```javascript\n   generateHTMLTable(data, null, { parseDataToSchema: \"stack\" });\n   ```\n\nHere are two derivation methods: `stack` and `flatten`. The difference between them is how to deal with nested headers. Given a piece of data with nesting:\n\n```javascript\nconst data = [\n  {\n    a: 1,\n    b: {\n      c: 2,\n      d: 3\n    }\n  }\n];\n```\n\nThe header generated using `stack` is:\n\n```javascript\ngenerateHTMLTable(data, null, { parseDataToSchema: \"stack\" });\n```\n\n<table>\n   <tr>\n     <th rowSpan=\"2\">a</th>\n     <th colSpan=\"2\">b</th>\n   </tr>\n   <tr>\n     <th>d</th>\n   </tr>\n</table>\n\nThe header generated using `flatten` is:\n\n```javascript\ngenerateHTMLTable(data, null, { parseDataToSchema: \"stack\" });\n```\n\n<table>\n   <tr>\n     <th>a</th>\n     <th>b.c</th>\n     <th>b.d</th>\n   </tr>\n</table>\n\nThe default strategy used is `stack`, which means\n\n```JavaScript\ngenerateHTMLTable(data)\n```\n\nEquivalent to\n\n```javascript\ngenerateHTMLTable(data, null, { parseDataToSchema: \"stack\" });\n```\n\n#### Derivation Questions\n\nAlthough implicit derivation can be used, I still don't recommend it here. The main reason is that the order of the columns cannot be guaranteed. For example for the following data:\n\n```javascript\nconst data = [\n  { a: 1, b: 2, c: 3 },\n  { c: 4, b: 5, a: 6 }\n];\n```\n\nThere is no guarantee that the columns will be in the order `a`, `b`, `c`. On the one hand, it depends on the implementation of the browser, on the other hand, the derivation algorithm does not make any guarantees.\n\nTherefore, it is always recommended to explicitly specify the Schema at any time. If you do not know enough about the Schema, you can use the `parseDataToSchema` function to export the Schema first, and then adjust it to what you need. Detailed techniques can be found in [Use parseDataToSchema to understand the usage of Schema](#Use -parsedatatoschema-understand the usage of -schema-).\n\n## API\n\n### `generateTable`\n\n**definition**\n\n```javascript\ngenerateTable(data, schema, options);\n```\n\n**describe**\n\nThe table format generated by this function is expressed as a JS object, and its main function is to provide a convenient intermediate format for conversion into other formats. In essence, both `generateHTMLTable` and `generateExcel` were quickly developed based on this function.\n\n**parameter explanation**\n\n- `data`: Arbitrary JavaScript data, including arrays, objects, numbers, strings, Null, Undefined, etc.\n- `schema`: Customize the header structure, its usage is explained in detail above.\n- `options`: options object, currently only one option is supported:\n  - `parseSchemaToData`: `\"stack\"` or `\"flatten\"`.\n\n**example**\n\n```\nconst data = [\n   {\n     a: 1,\n     b:[\n       { c: 2, d: 3 }\n     ]\n   },\n   {\n     a: 4,\n     b:[\n       { c: 5, d: 6 },\n       { c: 7, d: 8 }\n     ]\n   }\n]\n\nconst schema = [\n   { path: 'a' },\n   { path: 'b', props: [\n     { path: 'c' },\n     { path: 'd' }\n   ] }\n]\n\ngenerateTable(data, schema)\n```\n\nThe display output is:\n\n```javascript\n{\n   header: [\n     [\n       { row: 1, col: 1, val: 'a', rowSpan: 2, colSpan: 1 },\n       { row: 1, col: 2, val: 'b', rowSpan: 1, colSpan: 2 },\n       undefined\n     ],\n     [\n       undefined,\n       { row: 2, col: 2, val: 'c', rowSpan: 1, colSpan: 1 },\n       { row: 2, col: 3, val: 'd', rowSpan: 1, colSpan: 1 }\n     ]\n   ],\n   body: [\n     [\n       { row: 3, col: 1, val: 1, rowSpan: 1, colSpan: 1 },\n       { row: 3, col: 2, val: 2, rowSpan: 1, colSpan: 1 },\n       { row: 3, col: 3, val: 3, rowSpan: 1, colSpan: 1 }\n     ],\n     [\n       { row: 4, col: 1, val: 4, rowSpan: 2, colSpan: 1 },\n       { row: 4, col: 2, val: 5, rowSpan: 1, colSpan: 1 },\n       { row: 4, col: 3, val: 6, rowSpan: 1, colSpan: 1 }\n     ],\n     [\n       undefined,\n       { row: 5, col: 2, val: 7, rowSpan: 1, colSpan: 1 },\n       { row: 5, col: 3, val: 8, rowSpan: 1, colSpan: 1 }\n     ]\n   ]\n}\n```\n\n### `generateHTMLTable`\n\n**definition**\n\n```javascript\ngenerateHTMLTable(data, schema, options);\n```\n\n**effect**\n\nGenerate HTML table source code, the returned format is a string. The tags used in the generated HTML table include `<table>`, `<thead>`, `<tbody>`, `<tr>`, `<th>`, `<td>`, which can customize attributes for tags , including `class`, `style` and others.\n\n**parameter explanation**\n\n- `data` and `schema`: Same as `generateTable`.\n- `options`: options object, in addition to the options supported by `generateTable`, it also supports the following options:\n  - `attributes`: Declare the attributes used by the tag, see examples for specific usage.\n\n**example**\n\n```javascript\n// add label attribute\ngenerateHTMLTable(data, schema, {\n  attributes: {\n    table: { class: \"c-table\" },\n    thead: { class: \"c-table-header\" },\n    tbody: { class: \"c-table-body\" },\n    tr: { class: \"c-table-row\" },\n    \"thead.tr\": { style: \"background: light-blue\" },\n    \"tbody.tr\": { style: \"background: cyan\" },\n    th: { class: \"c-header-cell\" },\n    td: { class: \"c-data-cell\" }\n  }\n});\n```\n\n### `generateExcel`\n\n**Remark**\n\nThe dependency package `xlsx` needs to be installed at the same time.\n\n**definition**\n\n```javascript\ngenerateExcel(data, schema, options);\n```\n\n**effect**\n\nGenerate an Excel table.\n\n**parameter explanation**\n\n- `data` and `schema`: Same as `generateTable`.\n- `options`: options object, in addition to the options supported by `generateTable`, it also supports the following options:\n  - `writeTo`: A file path.\n\n**example**\n\n```javascript\n// write to file path\ngenerateExcel(data, schema, { writeTo: \"/tmp/example.xlsx\" });\n\n// write to standard output\ngenerateExcel(data, schema, { writeTo: \"/dev/stdout\" });\n```\n\n### `parseDataToSchema`\n\n**definition**\n\n```javascript\nparseDataToSchema(data, mode);\n```\n\n**effect**\n\nThe Schema is deduced from the data, and two derivation methods are supported.\n\n**parameter explanation**\n\n- `data`: data\n- `mode`: Derivation mode, supports two kinds of derivationThe derivation method `\"stack\"` and `\"flatten\"`. For the detailed difference, please refer to the **Data Derivation Table** section.\n\n## skills\n\n#### Display scalar array\n\nAlthough rare, if we encounter the following array data:\n\n```javascript\nconst data = [\"A\", \"B\", \"C\"];\n```\n\nDisplayed in a grid by default:\n\n<table>\n   <tbody>\n     <tr>\n       <td>A,B,C</td>\n     </tr>\n   </tbody>\n</table>\n\nWe want to display it in other lines. In this case, we can satisfy the purpose by customizing a blank `path`:\n\n```javascript\nconst schema = { title: \"Data\", path: \"\" };\n```\n\nThe display will be:\n\n<table>\n   <thead>\n     <tr>\n       <th>Data</th>\n     </tr>\n   </thead>\n   <tbody>\n     <tr>\n       <td>A</td>\n     </tr>\n     <tr>\n       <td>B</td>\n     </tr>\n     <tr>\n       <td>C</td>\n     </tr>\n   </tbody>\n</table>\n\n#### Display the long text array in separate lines\n\nArrays use the `array.toString()` method to display text in cells, and the display effect of `[1, 2, 3]` is `1,2,3`. If you encounter a long text array, for example:\n\n```javascript\nconst data = {\n  short: 1,\n  long: [\n    \"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\",\n    \"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\",\n    \"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\"\n  ]\n};\n```\n\nThe default display will not be good enough. At this time, the row display of the array can be realized by customizing the Schema:\n\n```javascript\nconst schema = [{ path: \"short\" }, { path: \"long\", props: [{ title: \"\", path: \"\" }] }];\n```\n\nThe display will look like this:\n\n<table>\n   <thead>\n     <tr>\n       <th>short</th>\n       <th>long</th>\n     </tr>\n   </thead>\n   <tbody>\n     <tr>\n       <td rowSpan=\"3\">1</td>\n       <td>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA</td>\n     </tr>\n     <tr>\n       <td>BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB</td>\n     </tr>\n     <tr>\n       <td>CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC</td>\n     </tr>\n   </tbody>\n</table>\n\n**explain**\n\nSpecial usage of `title` and `path` are used here. A `title` with an empty string does not occupy the grid of the header, and a `path` with an empty string extracts the complete data. Since the data is an array, extract the complete data inside the array instead.\n\n#### Use `parseDataToSchema` to understand the usage of Schema\n\nSome students may not know the usage of Schema at the beginning. At this time, you can use `parseDataToSchema` to derive the Schema and print it out on the console. The printed result can be adjusted to meet your needs.\n\n```javascript\nimport { generateHTMLTable, parseDataToSchema } from \"@yetrun/json-to-table\";\n\nconst data = [\n  //...\n];\n\n// View Schema\nconsole.log(parseDataToSchema(data));\n\n// Copy the Schema from the console and adjust it according to your needs\nconst schema = [\n  //...\n];\n\n// Explicitly apply Schema and generate tables\ngenerateHTMLTable(data, schema);\n```\n\n## contribute\n\nYou can submit a PR to improve this project, or clone the source code for secondary development. Here are the commands commonly used during development:\n\n```bash\n# run unit tests\n$ yarn test\n\n# build and package\n$ yarn build\n```\n\n## License\n","readmeFilename":"README.md"}