{"id":18351602,"url":"https://github.com/Chris-Baker/pretty-print-object","last_synced_at":"2025-04-06T11:32:34.400Z","repository":{"id":35094193,"uuid":"205818574","full_name":"Chris-Baker/pretty-print-object","owner":"Chris-Baker","description":"Stringify an object/array like JSON.stringify just without all the double-quotes","archived":false,"fork":false,"pushed_at":"2023-10-17T23:39:42.000Z","size":790,"stargazers_count":5,"open_issues_count":3,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-10T14:18:42.840Z","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":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Chris-Baker.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2019-09-02T09:06:09.000Z","updated_at":"2025-02-14T05:59:41.000Z","dependencies_parsed_at":"2024-06-18T18:19:27.229Z","dependency_job_id":null,"html_url":"https://github.com/Chris-Baker/pretty-print-object","commit_stats":{"total_commits":29,"total_committers":2,"mean_commits":14.5,"dds":0.4482758620689655,"last_synced_commit":"328343f0574e6d6328a3241a96e15e71107adbfe"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chris-Baker%2Fpretty-print-object","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chris-Baker%2Fpretty-print-object/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chris-Baker%2Fpretty-print-object/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chris-Baker%2Fpretty-print-object/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Chris-Baker","download_url":"https://codeload.github.com/Chris-Baker/pretty-print-object/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247478152,"owners_count":20945257,"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-05T21:32:05.774Z","updated_at":"2025-04-06T11:32:34.145Z","avatar_url":"https://github.com/Chris-Baker.png","language":"TypeScript","funding_links":[],"categories":["Packages"],"sub_categories":[],"readme":"# Pretty print object\n[![License][license-image]][license-url] ![coverage-badge-green]\n \n\u003e Convert an object or array into a formatted string\n\nThis is a re-write of [stringify-object] in Typescript, modified to inline the dependencies and make it compatible with ES5 out of the box.\n\nUseful for when you want to get the string representation of an object in a formatted way.\n\nIt also handles circular references and lets you specify quote type.\n\n\n## Install\n\n```\n$ npm install @base2/pretty-print-object\n```\n\n\n## Usage\n\n```js\nimport { prettyPrint } from '@base2/pretty-print-object';\n\nconst obj = {\n    foo: 'bar',\n    'arr': [1, 2, 3],\n    nested: {\n        hello: \"world\"\n    }\n};\n\nconst pretty = prettyPrint(obj, {\n    indent: '  ',\n    singleQuotes: false\n});\n\nconsole.log(pretty);\n/*\n{\n    foo: \"bar\",\n    arr: [\n        1,\n        2,\n        3\n    ],\n    nested: {\n        hello: \"world\"\n    }\n}\n*/\n```\n\n\n## API\n\n### prettyPrint(input, [options])\n\nCircular references will be replaced with `\"[Circular]\"`.\n\nObject keys are only quoted when necessary, for example, `{'foo-bar': true}`.\n\n#### input\n\nType: `Object` `Array`\n\n#### options\n\nType: `Object`\n\n##### indent\n\nType: `string`\u003cbr\u003e\nDefault: `\\t`\n\nPreferred indentation.\n\n##### singleQuotes\n\nType: `boolean`\u003cbr\u003e\nDefault: `true`\n\nSet to false to get double-quoted strings.\n\n##### filter(obj, prop)\n\nType: `Function`\n\nExpected to return a `boolean` of whether to include the property `prop` of the object `obj` in the output.\n\n##### transform(obj, prop, originalResult)\n\nType: `Function`\u003cbr\u003e\nDefault: `undefined`\n\nExpected to return a `string` that transforms the string that resulted from stringifying `obj[prop]`. This can be used to detect special types of objects that need to be stringified in a particular way. The `transform` function might return an alternate string in this case, otherwise returning the `originalResult`.\n\nHere's an example that uses the `transform` option to mask fields named \"password\":\n\n```js\nimport { prettyPrint } from '@base2/pretty-print-object';\n\nconst obj = {\n    user: 'becky',\n    password: 'secret'\n};\n\nconst pretty = prettyPrint(obj, {\n    transform: (obj, prop, originalResult) =\u003e {\n        if (prop === 'password') {\n            return originalResult.replace(/\\w/g, '*');\n        }\n\n        return originalResult;\n    }\n});\n\nconsole.log(pretty);\n/*\n{\n    user: 'becky',\n    password: '******'\n}\n*/\n```\n\n\n##### inlineCharacterLimit\n\nType: `number`\n\nWhen set, will inline values up to `inlineCharacterLimit` length for the sake of more terse output.\n\nFor example, given the example at the top of the README:\n\n```js\nimport { prettyPrint } from '@base2/pretty-print-object';\n\nconst obj = {\n    foo: 'bar',\n    'arr': [1, 2, 3],\n    nested: {\n        hello: \"world\"\n    }\n};\n\nconst pretty = prettyPrint(obj, {\n    indent: '  ',\n    singleQuotes: false,\n    inlineCharacterLimit: 12\n});\n\nconsole.log(pretty);\n/*\n{\n    foo: \"bar\",\n    arr: [1, 2, 3],\n    nested: {\n        hello: \"world\"\n    }\n}\n*/\n```\n\nAs you can see, `arr` was printed as a one-liner because its string was shorter than 12 characters.\n\n[stringify-object]: https://www.npmjs.com/package/stringify-object\n[coverage-badge-green]: https://img.shields.io/badge/Coverage-100%25-brightgreen.svg\n[license-url]: https://opensource.org/licenses/BSD-2-Clause\n[license-image]: https://img.shields.io/badge/License-BSD%202--Clause-orange.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FChris-Baker%2Fpretty-print-object","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FChris-Baker%2Fpretty-print-object","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FChris-Baker%2Fpretty-print-object/lists"}