{"name":"structured-clone-es","version":"2.0.0","keywords":["structured-clone","serialize","deserialize"],"author":{"name":"Andrea Giammarchi"},"license":"ISC","_id":"structured-clone-es@2.0.0","maintainers":[{"name":"antfu","email":"anthonyfu117@hotmail.com"}],"homepage":"https://github.com/antfu-collective/structured-clone-es#readme","bugs":{"url":"https://github.com/antfu-collective/structured-clone-es/issues"},"dist":{"shasum":"ab53cf4e2934c7b5fb17bda9761ac5e809d1b9cd","tarball":"http://registry-npm.ywwl.com/structured-clone-es/download/structured-clone-es-2.0.0.tgz","fileCount":5,"integrity":"sha512-5UuAHmBLXYPCl22xWJrFuGmIhBKQzxISPVz6E7nmTmTcAOpUzlbjKJsRrCE4vADmMQ0dzeCnlWn9XufnAGf76Q==","signatures":[{"sig":"MEYCIQCJTtQH3JmGJJO9oQ4flRGNvmFhkjAsxy+15eZJZM6PpgIhANT7Pnxir1OFV7tVZEYlCnZF4/KGjSn6o0c05DCUx7Hm","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/structured-clone-es@2.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":14772,"size":5093,"noattachment":false,"key":"/structured-clone-es/-/structured-clone-es-2.0.0.tgz"},"type":"module","_from":"file:structured-clone-es-2.0.0.tgz","types":"./dist/index.d.mts","exports":{".":"./dist/index.mjs","./package.json":"./package.json"},"scripts":{"dev":"tsdown --watch","lint":"eslint .","test":"vitest","build":"tsdown","start":"tsx src/index.ts","release":"bumpp","typecheck":"tsc --noEmit"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:c8bad579-0eb9-4512-bd7e-678c609f7144"}},"_resolved":"/tmp/5cb488017931273bf92db593eba89068/structured-clone-es-2.0.0.tgz","_integrity":"sha512-5UuAHmBLXYPCl22xWJrFuGmIhBKQzxISPVz6E7nmTmTcAOpUzlbjKJsRrCE4vADmMQ0dzeCnlWn9XufnAGf76Q==","repository":{"url":"git+https://github.com/antfu-collective/structured-clone-es.git","type":"git"},"_npmVersion":"11.9.0","description":"An env-agnostic serializer and deserializer with recursion ability and types beyond JSON, based on the HTML structured clone algorithm.","directories":{},"lint-staged":{"*":"eslint --fix"},"sideEffects":false,"_nodeVersion":"24.14.0","_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.21.0","pnpm":"^10.32.1","bumpp":"^10.4.1","eslint":"^10.0.3","tsdown":"^0.21.2","vitest":"^4.0.18","@antfu/ni":"^28.3.0","typescript":"^5.9.3","@types/node":"^25.4.0","lint-staged":"^16.3.3","@antfu/utils":"^9.3.0","simple-git-hooks":"^2.13.1","@vitest/coverage-v8":"3.2.4","@antfu/eslint-config":"^7.7.2"},"simple-git-hooks":{"pre-commit":"pnpm lint-staged"},"_npmOperationalInternal":{"tmp":"tmp/structured-clone-es_2.0.0_1773364568511_0.07107323538097576","host":"s3://npm-registry-packages-npm-production"},"readme":"# structured-clone-es\n\n[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![bundle][bundle-src]][bundle-href]\n[![JSDocs][jsdocs-src]][jsdocs-href]\n[![License][license-src]][license-href]\n\nAn env-agnostic serializer and deserializer with recursion ability and types beyond JSON, based on the [HTML structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm).\n\nPorted from [`@ungap/structured-clone`](https://github.com/ungap/structured-clone) by [Andrea Giammarchi](https://github.com/WebReflection), with TypeScript support and modern ESM packaging.\n\n> [!NOTE]\n> If you are targeting modern environments, the native [`structuredClone()`](https://developer.mozilla.org/en-US/docs/Web/API/structuredClone) is available in all major browsers and Node.js 17+. Use it directly for better performance.\n>\n> The main value of this package is the **`serialize` / `deserialize`** and **`stringify` / `parse`** utilities, which allow you to convert complex and recursive objects into JSON-safe representations — useful for sending structured data across processes or over the network (e.g. client-server RPC communication).\n>\n> Used by [Nuxt DevTools](https://github.com/nuxt/devtools), [Vite DevTools](https://github.com/nicepkg/vite-plugin-devtools), [Node Modules Inspector](https://github.com/nicepkg/node-modules-inspector), [ESLint Config Inspector](https://github.com/eslint/config-inspector), and more.\n\n## Install\n\n```bash\nnpm i structured-clone-es\n```\n\n## Usage\n\n### Serialize / Deserialize\n\nThe result of `serialize` can be safely stringified as JSON, even if the original data contains recursive references, `BigInt` values, typed arrays, and so on.\n\n```ts\nimport { deserialize, serialize } from 'structured-clone-es'\n\n// serialize any value into a JSON-compatible array of records\nconst serialized = serialize({ any: 'serializable' })\n\n// reconstruct the original object\nconst deserialized = deserialize(serialized)\n```\n\n### Stringify / Parse\n\nA convenience wrapper that combines `serialize` + `JSON.stringify` and `JSON.parse` + `deserialize`:\n\n```ts\nimport { parse, stringify } from 'structured-clone-es'\n\nconst str = stringify({ any: 'serializable' })\nconst obj = parse(str)\n```\n\n### structuredClone\n\nA pure `structuredClone` implementation is also exported. It always uses the serialize/deserialize path without relying on the runtime's native `structuredClone`.\n\n```ts\nimport { structuredClone } from 'structured-clone-es'\n\nconst cloned = structuredClone({ any: 'serializable' })\n```\n\nIf you need polyfill `globalThis.structuredClone`, you can attach it manually:\n\n```ts\nimport { structuredClone } from 'structured-clone-es'\n\nif (!('structuredClone' in globalThis)) {\n  globalThis.structuredClone = structuredClone\n}\n```\n\n## Supported Types\n\n- Primitives: `string`, `number`, `boolean`, `null`, `undefined`, `BigInt`\n- Collections: `Array`, `Object`, `Map`, `Set`\n- Typed Arrays: `Uint8Array`, `Uint16Array`, `Uint32Array`, `Int8Array`, `Int16Array`, `Int32Array`, `ArrayBuffer`, `DataView`\n- `Date`, `RegExp`, `Error`\n- Boxed primitives: `Boolean`, `Number`, `String`\n- Circular / recursive references\n\nSee the [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm#supported_types) for the full structured clone algorithm spec. Note that browser-specific types (Blob, File, ImageBitmap, etc.) are not supported by this library.\n\n## Lossy Mode\n\nBy default, `serialize` throws on incompatible types like `function` or `symbol`. Use the `lossy` option to silently replace them with `null` instead:\n\n```ts\nimport { structuredClone } from 'structured-clone-es'\n\nconst cloned = structuredClone(\n  {\n    method() { /* ignored */ },\n    special: Symbol('also ignored'),\n  },\n  { lossy: true },\n)\n```\n\n### JSON Mode\n\nThe `json` option implies `lossy` and additionally checks for `toJSON()` methods on objects:\n\n```ts\nimport { structuredClone } from 'structured-clone-es'\n\nconst cloned = structuredClone(\n  {\n    date: {\n      toJSON() {\n        return '2024-01-01'\n      },\n    },\n  },\n  { json: true },\n)\n```\n\nThe `stringify` / `parse` exports use both `json` and `lossy` by default.\n\n## Credits\n\nThis project is a TypeScript port of [`@ungap/structured-clone`](https://github.com/ungap/structured-clone), originally created by [Andrea Giammarchi](https://github.com/WebReflection) under the ISC license.\n\n## License\n\n[ISC](./LICENSE.md)\n\n<!-- Badges -->\n\n[npm-version-src]: https://img.shields.io/npm/v/structured-clone-es?style=flat&colorA=080f12&colorB=1fa669\n[npm-version-href]: https://npmjs.com/package/structured-clone-es\n[npm-downloads-src]: https://img.shields.io/npm/dm/structured-clone-es?style=flat&colorA=080f12&colorB=1fa669\n[npm-downloads-href]: https://npmjs.com/package/structured-clone-es\n[bundle-src]: https://img.shields.io/bundlephobia/minzip/structured-clone-es?style=flat&colorA=080f12&colorB=1fa669&label=minzip\n[bundle-href]: https://bundlephobia.com/result?p=structured-clone-es\n[license-src]: https://img.shields.io/github/license/antfu-collective/structured-clone-es.svg?style=flat&colorA=080f12&colorB=1fa669\n[license-href]: https://github.com/antfu-collective/structured-clone-es/blob/main/LICENSE\n[jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669\n[jsdocs-href]: https://www.jsdocs.io/package/structured-clone-es\n","publish_time":1773364568650,"_cnpm_publish_time":1773364568650,"dist-tags":{"latest":"2.0.1"}}