{"id":15414863,"url":"https://github.com/lxsmnsyc/ecmason","last_synced_at":"2025-04-19T12:40:52.700Z","repository":{"id":57219308,"uuid":"360962563","full_name":"lxsmnsyc/ecmason","owner":"lxsmnsyc","description":"JSON parse/stringify for modern ES objects","archived":false,"fork":false,"pushed_at":"2022-05-31T16:07:22.000Z","size":220,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-13T17:45:24.814Z","etag":null,"topics":["json","json-parser","parser"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/lxsmnsyc.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}},"created_at":"2021-04-23T17:43:03.000Z","updated_at":"2022-11-30T22:40:46.000Z","dependencies_parsed_at":"2022-08-28T23:23:02.064Z","dependency_job_id":null,"html_url":"https://github.com/lxsmnsyc/ecmason","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxsmnsyc%2Fecmason","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxsmnsyc%2Fecmason/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxsmnsyc%2Fecmason/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxsmnsyc%2Fecmason/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lxsmnsyc","download_url":"https://codeload.github.com/lxsmnsyc/ecmason/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249696081,"owners_count":21311814,"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":["json","json-parser","parser"],"created_at":"2024-10-01T17:05:05.214Z","updated_at":"2025-04-19T12:40:52.668Z","avatar_url":"https://github.com/lxsmnsyc.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ecmason\n\n\u003e JSON parse/stringify for modern ES objects\n\n[![NPM](https://img.shields.io/npm/v/ecmason.svg)](https://www.npmjs.com/package/ecmason) [![JavaScript Style Guide](https://badgen.net/badge/code%20style/airbnb/ff5a5f?icon=airbnb)](https://github.com/airbnb/javascript)\n\n## Install\n\n```bash\nnpm install --save ecmason\n```\n\n```bash\nyarn add ecmason\n```\n\n## Usage\n\n```tsx\nimport { parse, stringify, setup } from 'ecmason';\n\n// Call setup first\nsetup();\n\n// Support for Map\nconst a = new Map([\n  // Support for Dates\n  ['hello', new Date()],\n  // Support for Regex\n  ['world', /Hello World/],\n]);\n\n// Support for plain objects\nconst object = {\n  a,\n  // Support for Set\n  b: new Set([\n    // Support for NaN\n    NaN,\n    // Support for undefined\n    undefined,\n    // Support for infinity\n    Infinity,\n    -Infinity,\n  ]),\n  c: [\n    // Support for signed zeroes\n    +0,\n    -0,\n  ],\n};\n\n// Support for recursion\na.set('recursive', object);\n\nconst value = ecmason.stringify(object);\n\n// Output:\n// {\n//   \"tag\": \"RECURSIVE(OBJECT)\",\n//   \"value\": {\n//     \"id\": 1,\n//     \"value\": {\n//       \"a\": {\n//         \"tag\": \"RECURSIVE(MAP)\",\n//         \"value\": {\n//           \"id\": 2,\n//           \"value\": [\n//             [{\n//               \"tag\": \"PRIMITIVE\",\n//               \"value\": \"hello\"\n//             }, {\n//               \"tag\": \"DATE\",\n//               \"value\": \"2021-04-23T17:34:08.630Z\"\n//             }],\n//             [{\n//               \"tag\": \"PRIMITIVE\",\n//               \"value\": \"world\"\n//             }, {\n//               \"tag\": \"REGEXP\",\n//               \"value\": [\"Hello World\", \"\"]\n//             }],\n//             [{\n//               \"tag\": \"PRIMITIVE\",\n//               \"value\": \"recursive\"\n//             }, {\n//               \"tag\": \"RECURSIVE(OBJECT)\",\n//               \"value\": 1\n//             }]\n//           ]\n//         }\n//       },\n//       \"b\": {\n//         \"tag\": \"RECURSIVE(SET)\",\n//         \"value\": {\n//           \"id\": 3,\n//           \"value\": [{\n//             \"tag\": \"NAN\",\n//             \"value\": null\n//           }, {\n//             \"tag\": \"UNDEFINED\",\n//             \"value\": null\n//           }, {\n//             \"tag\": \"INF\",\n//             \"value\": null\n//           }, {\n//             \"tag\": \"-INF\",\n//             \"value\": null\n//           }]\n//         }\n//       },\n//       \"c\": {\n//         \"tag\": \"RECURSIVE(ARRAY)\",\n//         \"value\": {\n//           \"id\": 4,\n//           \"value\": [{\n//             \"tag\": \"+0\",\n//             \"value\": 0\n//           }, {\n//             \"tag\": \"-0\",\n//             \"value\": 0\n//           }]\n//         }\n//       }\n//     }\n//   }\n// }\nconsole.log(value);\n\n// Output (Node)\n// \u003cref *1\u003e {\n//   a: Map(3) {\n//     'hello' =\u003e 2021-04-23T17:34:08.630Z,\n//     'world' =\u003e /Hello World/,\n//     'recursive' =\u003e [Circular *1]\n//   },\n//   b: Set(4) { NaN, undefined, Infinity, -Infinity },\n//   c: [ 0, -0 ]\n// }\nconsole.log(ecmason.parse(value));\n```\n\n## Features\n\n### ECMAScript globals\n\nThe following are values and classes supported by `ecmason`, ordered from highest priority:\n\n- Literal Transformers\n  - `NaN`\n  - `Number.POSITIVE_INFINITY` or `Infinity`\n  - `Number.NEGATIVE_INFINITY` or `-Infinity`\n  - `-0`\n- Primitive Transformers\n  - `BigInt`\n  - `Symbol` (disabled; needs `ES2019`)\n  - `number`, `string`, `boolean` and `null`\n  - `undefined`\n- Object Transformers\n  - `RegExp`\n  - `Date`\n  - `Map`\n  - `Set`\n  - `Array`\n- Final Transformers\n  - `Object`\n\n### Custom transformers\n\nTo be documented\n\n### Recursive references\n\nRecursive references in `Map`, `Set`, `Array` and `Object` are handled as well.\n\n## Cons\n\nTo preserve data safety-ness, the output result of `stringify` is verbose, which is done in an AST-like implementation, which allows us to preserve contextual data. Plain parsing will be inconveniently make the data inaccessible.\n\n## License\n\nMIT © [lxsmnsyc](https://github.com/lxsmnsyc)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flxsmnsyc%2Fecmason","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flxsmnsyc%2Fecmason","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flxsmnsyc%2Fecmason/lists"}