{"id":13447700,"url":"https://github.com/commenthol/serialize-to-js","last_synced_at":"2025-05-12T14:57:37.635Z","repository":{"id":30625471,"uuid":"34180905","full_name":"commenthol/serialize-to-js","owner":"commenthol","description":"serialize objects to javascript","archived":false,"fork":false,"pushed_at":"2024-02-21T02:37:25.000Z","size":79,"stargazers_count":26,"open_issues_count":3,"forks_count":13,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-17T15:13:27.625Z","etag":null,"topics":["javascript","serialize-objects"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/commenthol.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":"2015-04-18T20:07:02.000Z","updated_at":"2024-11-26T07:34:26.000Z","dependencies_parsed_at":"2024-06-18T13:54:50.018Z","dependency_job_id":"7f7d486d-8d19-4d55-97bc-df6a963cf435","html_url":"https://github.com/commenthol/serialize-to-js","commit_stats":{"total_commits":69,"total_committers":2,"mean_commits":34.5,"dds":0.04347826086956519,"last_synced_commit":"e82200d973d2764dee574675b5da03b69c83d231"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commenthol%2Fserialize-to-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commenthol%2Fserialize-to-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commenthol%2Fserialize-to-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commenthol%2Fserialize-to-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/commenthol","download_url":"https://codeload.github.com/commenthol/serialize-to-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253760395,"owners_count":21959930,"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":["javascript","serialize-objects"],"created_at":"2024-07-31T05:01:24.706Z","updated_at":"2025-05-12T14:57:37.610Z","avatar_url":"https://github.com/commenthol.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# serialize-to-js\n\n\u003e serialize objects to javascript\n\n[![NPM version](https://badge.fury.io/js/serialize-to-js.svg)](https://www.npmjs.com/package/serialize-to-js/)\n[![Build Status](https://github.com/commenthol/serialize-to-js/workflows/CI/badge.svg?branch=master\u0026event=push)](https://github.com/commenthol/serialize-to-js/actions/workflows/ci.yml?query=branch%3Amaster)\n\n\nSerialize objects into a string while checking circular structures and respecting references.\n\nThe following Objects are supported\n\n- String\n- Number\n- Boolean\n- Object\n- Array\n- RegExp\n- Error\n- Date\n- Buffer\n- Int8Array, Uint8Array, Uint8ClampedArray\n- Int16Array, Uint16Array\n- Int32Array, Uint32Array, Float32Array\n- Float64Array\n- Set\n- Map\n\n## Table of Contents\n\n\u003c!-- !toc (minlevel=2 omit=\"Table of Contents\") --\u003e\n\n* [Methods](#methods)\n  * [serialize](#serialize)\n* [Contribution and License Agreement](#contribution-and-license-agreement)\n* [License](#license)\n\n\u003c!-- toc! --\u003e\n\n## Methods\n\n### serialize\n\n`serialize(source, opts, opts.ignoreCircular, opts.reference)`\n\nserializes an object to javascript\n\n#### Example - serializing regex, date, buffer, ...\n\n```js\nconst serialize = require('serialize-to-js')\nconst obj = {\n  str: '\u003cscript\u003evar a = 0 \u003e 1\u003c/script\u003e',\n  num: 3.1415,\n  bool: true,\n  nil: null,\n  undef: undefined,\n  obj: { foo: 'bar' },\n  arr: [1, '2'],\n  regexp: /^test?$/,\n  date: new Date(),\n  buffer: new Buffer('data'),\n  set: new Set([1, 2, 3]),\n  map: new Map([['a': 1],['b': 2]])\n}\nconsole.log(serialize(obj))\n//\u003e '{str: \"\\u003Cscript\\u003Evar a = 0 \\u003E 1\\u003C\\u002Fscript\\u003E\",\n//\u003e   num: 3.1415, bool: true, nil: null, undef: undefined,\n//\u003e   obj: {foo: \"bar\"}, arr: [1, \"2\"], regexp: new RegExp(\"^test?$\", \"\"),\n//\u003e   date: new Date(\"2019-12-29T10:37:36.613Z\"),\n//\u003e   buffer: Buffer.from(\"ZGF0YQ==\", \"base64\"), set: new Set([1, 2, 3]),\n//\u003e   map: new Map([[\"a\", 1], [\"b\", 2]])}'\n```\n\n#### Example - serializing while respecting references\n\n```js\nvar serialize = require('serialize-to-js')\nvar obj = { object: { regexp: /^test?$/ } };\nobj.reference = obj.object;\nvar opts = { reference: true };\nconsole.log(serialize(obj, opts));\n//\u003e {object: {regexp: /^test?$/}}\nconsole.log(opts.references);\n//\u003e [ [ '.reference', '.object' ] ]\n```\n\n**Parameters**\n\n**source**: `Object | Array | function | Any`, source to serialize  \n**opts**: `Object`, options  \n**opts.ignoreCircular**: `Boolean`, ignore circular objects  \n**opts.reference**: `Boolean`, reference instead of a copy (requires post-processing of opts.references)  \n**opts.unsafe**: `Boolean`, do not escape chars `\u003c\u003e/`  \n**Returns**: `String`, serialized representation of `source`\n\n\n## Contribution and License Agreement\n\nIf you contribute code to this project, you are implicitly allowing your\ncode to be distributed under the MIT license. You are also implicitly\nverifying that all code is your original work or correctly attributed\nwith the source of its origin and licence.\n\n## License\n\nCopyright (c) 2016- commenthol (MIT License)\n\nSee [LICENSE][] for more info.\n\n[LICENSE]: ./LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommenthol%2Fserialize-to-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcommenthol%2Fserialize-to-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommenthol%2Fserialize-to-js/lists"}