{"library":"replicator","title":"Advanced JavaScript Object Serialization","description":"replicator is a JavaScript library designed for advanced object serialization, addressing limitations of standard JSON.stringify. It currently stands at version 1.0.5, with an active release cadence indicated by recent patch versions. A key differentiator is its ability to correctly handle circular references within objects, preventing common serialization errors. Beyond standard JSON-serializable types, replicator offers built-in support for a wide array of JavaScript objects including `undefined`, `NaN`, `Date`, `RegExp`, `Error`, `Map`, `Set`, `ArrayBuffer`, and various Typed Arrays. This makes it suitable for complex data structures that would otherwise require manual transformation before serialization. Furthermore, the library is highly extensible, allowing developers to define custom type transforms to serialize and deserialize any bespoke object types. It is also agnostic to the underlying serialization format, enabling its use with JSON, BSON, Protobuf, or other encoders. This flexibility allows it to be adapted for diverse application needs, from IPC in Node.js to storing complex state in the browser.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install replicator"],"cli":null},"imports":["const Replicator = require('replicator');","import Replicator from 'replicator';","const replicator = new Replicator();\nreplicator.addTransforms(...);\nreplicator.encode(...);\nreplicator.decode(...);"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const Replicator = require('replicator');\n\nconst replicator = new Replicator();\n\nconst a = {};\na.b = a; // Create a circular reference\n\nconst complexObject = {\n    key1: new Set([1, 2, 3]),\n    key2: /\\s+/ig,\n    key3: a,\n    key4: new Date(),\n    key5: undefined,\n    key6: NaN,\n    key7: new Error('Something went wrong')\n};\n\nconsole.log('Original object:', complexObject);\n\nconst str = replicator.encode(complexObject);\nconsole.log('Encoded string:', str);\n\nconst obj = replicator.decode(str);\nconsole.log('Decoded object:', obj);\n\n// Verify circular reference\nconsole.log('Decoded circular reference:', obj.key3.b === obj.key3);\n// Verify Set decoding\nconsole.log('Decoded Set:', obj.key1 instanceof Set && obj.key1.has(1));","lang":"javascript","description":"Demonstrates basic encoding and decoding of an object with various built-in types, including Set, RegExp, Date, undefined, NaN, Error, and a circular reference.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}