{"id":28220955,"url":"https://github.com/morulus/smart-stringify-object","last_synced_at":"2025-06-26T15:32:37.332Z","repository":{"id":66348144,"uuid":"311665912","full_name":"morulus/smart-stringify-object","owner":"morulus","description":"Stringify object with the ability to insert the result of object methods as code","archived":false,"fork":false,"pushed_at":"2020-11-10T15:04:43.000Z","size":65,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-10T11:44:28.592Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/morulus.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,"zenodo":null}},"created_at":"2020-11-10T13:25:04.000Z","updated_at":"2020-11-10T15:04:52.000Z","dependencies_parsed_at":"2023-02-25T07:30:41.231Z","dependency_job_id":null,"html_url":"https://github.com/morulus/smart-stringify-object","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/morulus/smart-stringify-object","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morulus%2Fsmart-stringify-object","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morulus%2Fsmart-stringify-object/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morulus%2Fsmart-stringify-object/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morulus%2Fsmart-stringify-object/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/morulus","download_url":"https://codeload.github.com/morulus/smart-stringify-object/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morulus%2Fsmart-stringify-object/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262094630,"owners_count":23258009,"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":"2025-05-18T04:16:33.087Z","updated_at":"2025-06-26T15:32:37.267Z","avatar_url":"https://github.com/morulus.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e This is fork of [stringify-object](https://github.com/yeoman/stringify-object/blob/master/package.json)\n\nStringify object with code chunks insertion\n\n\n## Install\n\n```\n$ yarn add smart-stringify-object\n```\n\n\n## Usage\n\n```js\nvar obj = {\n\tfoo: 'bar',\n\t'arr': [1, 2, 3],\n\tnested: { hello: \"world\" },\n\tmethod: () =\u003e 'function () { return this.foo; }'\n};\n\nvar pretty = stringifyObject(obj, {\n\tindent: '  ',\n\tsingleQuotes: false,\n\tfunctions: 'exec'\n});\n\nconsole.log(pretty);\n/*\n{\n\tfoo: \"bar\",\n\tarr: [\n\t\t1,\n\t\t2,\n\t\t3\n\t],\n\tnested: {\n\t\thello: \"world\"\n\t},\n\tmethod: function () { return this.foo; }\n}\n*/\n```\n\n## Stringify functions\n\nYou can choose how exactly will be stringified object's properties of function type.\n\nBy default, the functions will be stringified as they were described in a code but you can use the functions as a tool to generate javascript code. There are two variants to use the functions in such a way:\n\n### Exec\n\nOption: `function: \"exec\"\n\nExecute a function and insert the result as a code chunk.\n\n```js\nconst obj = {\n\tname: path.basename(__filename),\n\tmodule: () =\u003e `require(${JSON.stringify(__filename)})`\n}\n\nstringify(obj, {\n\tfunctions: \"exec\"\n})\n/*\n{\n\tname: 'example.js',\n\tmodule: require(\"path/to/example.js\")\n}\n*/\n```\n\n### Extract\n\nOption: `function: \"extract\"`\n\nGet function's body and insert it as code chunk.\n\n```js\nvar obj = {\n\tkey: function() { Symbol() }\n}\n\nvar pretty = stringifyObject(obj, {\n\tfunctions: \"extract\"\n}\nconsole.log(pretty);\n/*\n{\n\tkey:  Symbol()\n}\n*/\n```\n\n## API\n\n### stringifyObject(input, [options])\n\nCircular references will be replaced with `\"[Circular]\"`.\n\n#### input\n\n*Required*  \nType: `object`, `array`\n\n#### options\n\n##### indent\n\nType: `string`  \nDefault: `'\\t'`\n\nChoose the indentation you prefer.\n\n##### singleQuotes\n\nType: `boolean`  \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 keep the object.\n\n##### inlineCharacterLimit\n\nType: `number`\nDefault: undefined\n\nWhen set, will inline values up to `inlineCharacterLimit` length for the sake\nof more terse output.\n\nFor example, given the example at the top of the README:\n\n```js\nvar obj = {\n\tfoo: 'bar',\n\t'arr': [1, 2, 3],\n\tnested: { hello: \"world\" }\n};\n\nvar pretty = stringifyObject(obj, {\n\tindent: '  ',\n\tsingleQuotes: false,\n\tinlineCharacterLimit: 12\n});\n\nconsole.log(pretty);\n/*\n{\n\tfoo: \"bar\",\n\tarr: [1, 2, 3],\n\tnested: {\n\t\thello: \"world\"\n\t}\n}\n*/\n```\n\nAs you can see, `arr` was printed as a one-liner because its string was shorter\nthan 12 characters.\n\n##### functions\n\nType: `\"extract\" | \"exec\" | false`   \nDefault: `false`\n\nChoose method to stringify functions\n\n- **extract** Extract function body as raw code\n- **exec** Execute function and use its result as raw code\n\nExctract example:\n```js\nvar obj = {\n\tkey: function() { Symbol() }\n}\n\nvar pretty = stringifyObject(obj, {\n\tfunctions: \"extract\"\n}\nconsole.log(pretty);\n/*\n{\n\tkey:  Symbol()\n}\n*/\n```\n\nExec example:\n```js\nvar moduleName = \"path/to/module.js\"\nvar obj = {\n\tmyModule: () =\u003e `require(${JSON.stringify(moduleName)})`\n}\n\nvar pretty = stringifyObject(obj, {\n\tfunctions: \"exec\"\n}\nconsole.log(pretty);\n/*\n{\n\tmyModule:  require(\"path/to/module.js\")\n}\n*/\n```\n\n## License\n\n[BSD license](http://opensource.org/licenses/bsd-license.php) © Vladimir Kalmykov, Yeoman Team\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorulus%2Fsmart-stringify-object","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmorulus%2Fsmart-stringify-object","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorulus%2Fsmart-stringify-object/lists"}