{"name":"@ungap/structured-clone","version":"1.1.2","description":"A structuredClone polyfill","main":"./cjs/index.js","types":"./esm/index.d.ts","scripts":{"build":"npm run cjs && npm run rollup:json && npm run copy-d-ts-into-cjs && npm run test","cjs":"ascjs esm cjs","copy-d-ts-into-cjs":"node ./copy-d-ts.js","coverage":"c8 report --reporter=text-lcov > ./coverage/lcov.info","rollup:json":"rollup --config rollup/json.config.js","test":"c8 node test/index.js"},"keywords":["recursion","structured","clone","algorithm"],"author":{"name":"Andrea Giammarchi"},"license":"ISC","devDependencies":{"@rollup/plugin-node-resolve":"^15.0.2","@rollup/plugin-terser":"^0.4.1","ascjs":"^5.0.1","c8":"^7.13.0","coveralls":"^3.1.1","rollup":"^3.21.1"},"module":"./esm/index.js","type":"module","exports":{".":{"types":"./esm/index.d.ts","import":"./esm/index.js","default":"./cjs/index.js"},"./json":{"types":"./esm/json.d.ts","import":"./esm/json.js","default":"./cjs/json.js"},"./package.json":"./package.json"},"directories":{"test":"test"},"repository":{"type":"git","url":"git+https://github.com/ungap/structured-clone.git"},"bugs":{"url":"https://github.com/ungap/structured-clone/issues"},"homepage":"https://github.com/ungap/structured-clone#readme","gitHead":"a7b5f812d628bd01f9d776740734be771fbc4d02","_id":"@ungap/structured-clone@1.1.2","_nodeVersion":"19.9.0","_npmVersion":"8.19.2","dist":{"integrity":"sha512-eBZk6Gdvzt2nPs797retPUWURx+WXBFHgEgJbXi1jrv0Vvqv3SsoLv47L0KRJEIHN3/uFV+Rmtgfvam54i/vLw==","shasum":"251224107402bde1f70b3e96634ac9fc39a871da","tarball":"http://registry-npm.ywwl.com/@ungap/structured-clone/download/@ungap/structured-clone-1.1.2.tgz","fileCount":27,"unpackedSize":38207,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDj9qTbLaevfczIp+0NZwAUYnpwe3CjDMN1ebOwCfrLvAIhALq2qR7sBcORleu3fz0OFJYkBMOkToN0Tf0fH25f6d0p"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkUl4RACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpDMQ//T0Ku3s6SnP6isgcmgSWvwzuZvr0HicFSheVT3ErXD77xgA5w\r\nj6O9DZTzSY9VQWaQQbmu8fFEPLqSd6Bx8H2tOOEumMlx6Zy/GcHNLQ+epPHQ\r\nXp2txlV6qv/UF5mT0WHNjQIqEqoh7fVsFZ3T9UuP0O3vubyfd9l7iT5mvvki\r\nrISt+PDau8ms6s7hA55P+r2l9vLGrp/QQVy23XS26OBMFWW4SkHy+yqwWVl0\r\n0fVENn+M/qophSf4BJ1fAaWiYkfEKpU7MIdc7hLEZLAqQayzBp4x69DDnkUd\r\nJ9X4/6RsqlrsqtwQpNON4XzaeQ4Effp1QqVgRvMsgrFaOTRliRqsc+gVSAeG\r\nrJOlSsoHVV885qliZ0B43kQrORxvC9Rx13HDZ04SrTtVNw3FfVJhegf59Stg\r\nrMnIp+1D9y/x6mPpINSFb6GpGm+QNpCVfm/OoxxMVBVI80GRhepE4Krt5zH+\r\naFE2L0zZQES1me5njbkaekPkt463jNXobrUhBzOvqvCQYX7n2Ey90PpvcMQp\r\nReH6WelNHijzCR1tWFyAuWFZGw7Vbe+zQ3vfbf/iKfSgyYKhUr9lQpvC7tCi\r\nw7K26vlsOLrsoKhpb7lMKuzYHZpVoi4okWVSu8bxptnGhmyPz5hDxk1cYKMx\r\nXg6+btncrd7yaRujtaqEAXc0LY8zqxD/M50=\r\n=dxfS\r\n-----END PGP SIGNATURE-----\r\n","size":9385,"noattachment":false,"key":"/@ungap/structured-clone/-/@ungap/structured-clone-1.1.2.tgz"},"_npmUser":{"name":"webreflection","email":"andrea.giammarchi@gmail.com"},"maintainers":[{"name":"webreflection","email":"andrea.giammarchi@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/structured-clone_1.1.2_1683119633268_0.8290978780667055"},"_hasShrinkwrap":false,"readme":"# structuredClone polyfill\n\n[![Downloads](https://img.shields.io/npm/dm/@ungap/structured-clone.svg)](https://www.npmjs.com/package/@ungap/structured-clone) [![build status](https://github.com/ungap/structured-clone/actions/workflows/node.js.yml/badge.svg)](https://github.com/ungap/structured-clone/actions) [![Coverage Status](https://coveralls.io/repos/github/ungap/structured-clone/badge.svg?branch=main)](https://coveralls.io/github/ungap/structured-clone?branch=main)\n\nAn env agnostic serializer and deserializer with recursion ability and types beyond *JSON* from the *HTML* standard itself.\n\n  * [Supported Types](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm#supported_types)\n    * *not supported yet*: Blob, File, FileList, ImageBitmap, ImageData, and ArrayBuffer, but typed arrays are supported without major issues, but u/int8, u/int16, and u/int32 are the only safely suppored (right now).\n    * *not possible to implement*: the `{transfer: []}` option can be passed but it's completely ignored.\n  * [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/structuredClone)\n  * [Serializer](https://html.spec.whatwg.org/multipage/structured-data.html#structuredserializeinternal)\n  * [Deserializer](https://html.spec.whatwg.org/multipage/structured-data.html#structureddeserialize)\n\nSerialized values can be safely stringified as *JSON* too, and deserialization resurrect all values, even recursive, or more complex than what *JSON* allows.\n\n\n### Examples\n\nCheck the [100% test coverage](./test/index.js) to know even more.\n\n```js\n// as default export\nimport structuredClone from '@ungap/structured-clone';\nconst cloned = structuredClone({any: 'serializable'});\n\n// as independent serializer/deserializer\nimport {serialize, deserialize} from '@ungap/structured-clone';\n\n// the result can be stringified as JSON without issues\n// even if there is recursive data, bigint values,\n// typed arrays, and so on\nconst serialized = serialize({any: 'serializable'});\n\n// the result will be a replica of the original object\nconst deserialized = deserialize(serialized);\n```\n\n#### Global Polyfill\nNote: Only monkey patch the global if needed. This polyfill works just fine as an explicit import: `import structuredClone from \"@ungap/structured-clone\"`\n```js\n// Attach the polyfill as a Global function\nimport structuredClone from \"@ungap/structured-clone\";\nif (!(\"structuredClone\" in globalThis)) {\n  globalThis.structuredClone = structuredClone;\n}\n\n// Or don't monkey patch\nimport structuredClone from \"@ungap/structured-clone\"\n// Just use it in the file\nstructuredClone()\n```\n\n**Note**: Do not attach this module's default export directly to the global scope, whithout a conditional guard to detect a native implementation. In environments where there is a native global implementation of `structuredClone()` already, assignment to the global object will result in an infinite loop when `globalThis.structuredClone()` is called. See the example above for a safe way to provide the polyfill globally in your project.\n\n### Extra Features\n\nThere is no middle-ground between the structured clone algorithm and JSON:\n\n  * JSON is more relaxed about incompatible values: it just ignores these\n  * Structured clone is inflexible regarding incompatible values, yet it makes specialized instances impossible to reconstruct, plus it doesn't offer any helper, such as `toJSON()`, to make serialization possible, or better, with specific cases\n\nThis module specialized `serialize` export offers, within the optional extra argument, a **lossy** property to avoid throwing when incompatible types are found down the road (function, symbol, ...), so that it is possible to send with less worrying about thrown errors.\n\n```js\n// as default export\nimport structuredClone from '@ungap/structured-clone';\nconst cloned = structuredClone(\n  {\n    method() {\n      // ignored, won't be cloned\n    },\n    special: Symbol('also ignored')\n  },\n  {\n    // avoid throwing\n    lossy: true,\n    // avoid throwing *and* looks for toJSON\n    json: true\n  }\n);\n```\n\nThe behavior is the same found in *JSON* when it comes to *Array*, so that unsupported values will result as `null` placeholders instead.\n\n#### toJSON\n\nIf `lossy` option is not enough, `json` will actually enforce `lossy` and also check for `toJSON` method when objects are parsed.\n\nAlternative, the `json` exports combines all features:\n\n```js\nimport {stringify, parse} from '@ungap/structured-clone/json';\n\nparse(stringify({any: 'serializable'}));\n```\n","publish_time":1683119633464,"deprecated":"Potential CWE-502 - Update to 1.3.1 or higher","_cnpm_publish_time":1683119633464,"dist-tags":{"latest":"1.4.0"}}