{"id":21391623,"url":"https://github.com/multiprocessio/preview","last_synced_at":"2025-06-28T05:36:42.478Z","repository":{"id":46491501,"uuid":"390052599","full_name":"multiprocessio/preview","owner":"multiprocessio","description":"A large-object previewer for JavaScript","archived":false,"fork":false,"pushed_at":"2022-01-02T20:50:54.000Z","size":164,"stargazers_count":13,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2023-03-03T23:04:33.718Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/multiprocessio.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}},"created_at":"2021-07-27T16:27:05.000Z","updated_at":"2022-03-24T08:27:00.000Z","dependencies_parsed_at":"2022-07-25T00:46:42.007Z","dependency_job_id":null,"html_url":"https://github.com/multiprocessio/preview","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multiprocessio%2Fpreview","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multiprocessio%2Fpreview/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multiprocessio%2Fpreview/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multiprocessio%2Fpreview/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/multiprocessio","download_url":"https://codeload.github.com/multiprocessio/preview/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225906326,"owners_count":17543134,"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":[],"created_at":"2024-11-22T13:35:22.382Z","updated_at":"2024-11-22T13:35:22.953Z","avatar_url":"https://github.com/multiprocessio.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Preview\n\nThis library helps showing snippets of large or small objects. It is\nparticularly useful when trying to render snippets of very large\nobjects.\n\n## Install\n\n```bash\n$ yarn add @multiprocess/preview\n```\n\n## Examples\n\nWhile this library is a huge improvement on naive implementations like\n`JSON.stringify(x).slice(0, 1000)` for large objects (say 70,000\nelements), it's easier to show a small object in an example. So we'll\ndisplay a small object but overwrite `preview`'s default number of\nresults to show.\n\n```javascript\nimport { preview } from '@multiprocess/preview';\n\n// The default is 20, so we make it smaller.\nconst startingNumber = 2;\n\nconsole.log(preview([\n  { a: 1, b: 3, c: 5 },\n  { a: 12, b: 8, c: 5 },\n  { a: 13, b: 3, c: 9 },\n], startingNumber));\n```\n\nOnce it reaches the starting number of keys, it stops printing\nelements. As it recurses into inner objects, the number of keys\nshrinks each time as well.\n\nHere is the output of the above script:\n\n```json\n[\n  { \"a\": 1, ... },\n  { \"a\": 12, ... },\n  ...\n]\n```\n\nEllipsis are literally printed. They are only printed if elements have\nbeen skipped by the preview.\n\n### Another example\n\nHere is another example of a more complex object:\n\n```\nimport { preview } from 'preview';\n\nconst startingNumber = 4;\nconsole.log(preview(\n  { a: 12, b: [1, 3, 4], c: null, d: { n: 'foo', m: 19, l: [12] } },\n  startingNumber,\n))\n```\n\nAnd the result:\n\n```json\n{\n  \"a\": 12,\n  \"b\": [ 1, 3, ... ],\n  \"c\": null,\n  \"d\": { \"l\": [ 12 ], \"m\": 19, ... }\n}\n```\n\nHere, ellipsis only show up in the inner objects and not the outer\nobject because no keys in the outer object were skipped. There were\nonly four keys and the starting number of keys was four.\n\n## Internals\n\nFor more details, check out this [blog\npost](https://datastation.multiprocess.io/blog/2021-07-15-writing-an-efficient-javascript-object-previewer.html).\n\n## Users\n\n* [DataStation](https://github.com/multiprocessio/datastation)\n\n## License\n\nApache-2.0, see [./LICENSE.md](./LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmultiprocessio%2Fpreview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmultiprocessio%2Fpreview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmultiprocessio%2Fpreview/lists"}