{"id":18320578,"url":"https://github.com/lukasbach/uncomplex","last_synced_at":"2026-05-17T18:02:41.253Z","repository":{"id":57385843,"uuid":"268358630","full_name":"lukasbach/uncomplex","owner":"lukasbach","description":"JSON.stringify/parse for complex data structures","archived":false,"fork":false,"pushed_at":"2020-05-31T23:27:56.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-14T03:51:19.025Z","etag":null,"topics":["complex","json","parse","stringify","transform","uncomplex"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lukasbach.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-31T20:27:51.000Z","updated_at":"2020-05-31T23:27:58.000Z","dependencies_parsed_at":"2022-09-12T11:52:56.081Z","dependency_job_id":null,"html_url":"https://github.com/lukasbach/uncomplex","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lukasbach/uncomplex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukasbach%2Funcomplex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukasbach%2Funcomplex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukasbach%2Funcomplex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukasbach%2Funcomplex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukasbach","download_url":"https://codeload.github.com/lukasbach/uncomplex/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukasbach%2Funcomplex/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265467689,"owners_count":23770760,"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":["complex","json","parse","stringify","transform","uncomplex"],"created_at":"2024-11-05T18:16:44.893Z","updated_at":"2026-05-17T18:02:41.129Z","avatar_url":"https://github.com/lukasbach.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# uncomplex\n\n[![Build Status](https://travis-ci.com/lukasbach/uncomplex.svg?branch=master)](https://travis-ci.com/lukasbach/uncomplex)\n\n\u003e JSON.stringify/parse for complex data structures\n\nUncomplex is a library without dependencies for serializing and deserializing JavaScript datastructures\nthat contain complex objects such as class instances. It works be defining so called\n*EntityInterfaces* that detect whether they are compatible with a specified substructure,\nconvert it when serializing an object and reconvert it when parsing an object.\n\n## Quick Start\n\nInstall the package via\n\n    yarn add uncomplex\n    \nand call the following methods:\n\n```ts\nimport { Uncomplex } from 'uncomplex';\n\nconst uncomplex = Uncomplex.new().withEntityInterfaces(...entityInterfaces);\nconst stringified: string = uncomplex.stringifyObject(object);\nconst parsed: CustomDataStructure = uncomplex.parseObject(stringified);\n```\n\nYou can define a custom EntityInterface by implementing ``EntityInterface``:\n\n```ts\nexport interface UncomplexEntityInterface\u003cOriginal = any, Simplified extends object = object, SimplifyState extends object = any, ParseState extends object = SimplifyState\u003e {\n  entityId: string;\n  applicableClasses?: any[];\n  isApplicable?: (object: Original) =\u003e boolean;\n  simplifyObject: (object: Original, key: string | number | undefined, state: Partial\u003cSimplifyState\u003e) =\u003e Simplified;\n  parseObject: (object: Simplified, key: string | number | undefined, state: Partial\u003cParseState\u003e) =\u003e Original;\n}\n```\n    \nNote that either ``applicableClasses`` (specifies a list of classes for which ``instanceof`` is used\nto determine whether the class can be mapped by the EntityInterface) or ``isApplicable`` must be\nimplemented.\n\nAlternatively, the following EntityInterfaces are implemented and can be imported from\nthe uncomplex library:\n\n- ``BigIntEntityInterface``: Converts ``bigint`` instances\n- ``DateEntityInterface``: Converts ``Date`` instances\n- ``MapEntityInterface``: Converts ``Map`` instances\n- ``SymbolEntityInterface``: Converts ``symbol`` instances\n    \n## Basic Example\n\nThe following example can be found at ``examples/customDataStructure.ts`` and can be run\nvia ``yarn example:customDataStructure``.\n\n```ts\nclass Example {\n  public param: string;\n  constructor(param: string) {\n    this.param = param;\n  }\n}\n\nexport const ExampleEntityInterface: UncomplexEntityInterface\u003cExample, { p: string }\u003e = {\n  entityId: 'Example',\n  applicableClasses: [Example],\n  simplifyObject: object =\u003e ({ p: object.param }),\n  parseObject: object =\u003e new Example(object.p)\n};\n\nconst uncomplex = Uncomplex.new().withEntityInterfaces(ExampleEntityInterface);\nconst example = { ex: new Example('test') };\nconst asString = uncomplex.stringifyObject(example);\n\nconsole.log(asString);\n// {\"ex\":{\"p\":\"test\",\"__uncomplexId\":\"Example\"}}\n\nconst parsed = uncomplex.parseObject(asString);\nconsole.log(parsed.ex instanceof Example, parsed.ex.param);\n// true 'test'\n```\n\n## Example using predefined EntityInterfaces\n\nThe following example can be found at ``examples/nativeDataStructure.ts`` and can be run\nvia ``yarn example:nativeDataStructure``.\n\n```ts\nconst uncomplex = Uncomplex.new().withEntityInterfaces(\n  BigIntEntityInterface, DateEntityInterface, MapEntityInterface, SymbolEntityInterface);\n\nconst map = new Map();\nmap.set('a', 'aa');\nmap.set('b', 42);\n\nconst sym1 = Symbol('a');\nconst sym2 = Symbol('b');\n\nconst example = { bigInt: BigInt(9999999999999), date: new Date(1800000000000), map, sym1, sym2, sym1alt: sym1 };\nconst asString = uncomplex.stringifyObject(example);\n\nconsole.log(asString);\n// {\n//   \"bigInt\":{\"n\":\"9999999999999\",\"__uncomplexId\":\"BigInt\"},\n//   \"date\":{\"iso\":\"2027-01-15T08:00:00.000Z\",\"__uncomplexId\":\"Date\"},\n//   \"map\":{\"entries\":[[\"a\",\"aa\"],[\"b\",42]],\"__uncomplexId\":\"Map\"},\n//   \"sym1\":{\"id\":0,\"key\":\"a\",\"__uncomplexId\":\"Symbol\"},\n//   \"sym2\":{\"id\":1,\"key\":\"b\",\"__uncomplexId\":\"Symbol\"},\n//   \"sym1alt\":{\"id\":0,\"key\":\"a\",\"__uncomplexId\":\"Symbol\"}\n// }\n\nconst parsed = uncomplex.parseObject(asString);\nconsole.log(parsed);\n// { bigInt: 9999999999999n,\n//   date: 2027-01-15T08:00:00.000Z,\n//   map: Map { 'a' =\u003e 'aa', 'b' =\u003e 42 },\n//   sym1: Symbol(a),\n//   sym2: Symbol(b),\n//   sym1alt: Symbol(a) }\n\nconsole.log(parsed.sym1 === parsed.sym2, parsed.sym1 === parsed.sym1alt);\n// false, true\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukasbach%2Funcomplex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukasbach%2Funcomplex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukasbach%2Funcomplex/lists"}