Files
SnowLuma/.pnpm-store/v11/files/23/339e26d83961e21f02a8e6dd4f596755b4312a46172f32232c229734b8b245acbc0a07536ac797ed93f8a224090f32bf0a9fe173a173e59cb65bfb67b4f6cd
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

58 lines
1.2 KiB
Plaintext

import type { SerovalNode } from 'seroval';
import { createPlugin } from 'seroval';
type DOMExceptionNode = {
name: SerovalNode;
message: SerovalNode;
};
const DOMExceptionPlugin = /* @__PURE__ */ createPlugin<
DOMException,
DOMExceptionNode
>({
tag: 'seroval-plugins/web/DOMException',
test(value) {
if (typeof DOMException === 'undefined') {
return false;
}
return value instanceof DOMException;
},
parse: {
sync(value, ctx) {
return {
name: ctx.parse(value.name),
message: ctx.parse(value.message),
};
},
async async(value, ctx) {
return {
name: await ctx.parse(value.name),
message: await ctx.parse(value.message),
};
},
stream(value, ctx) {
return {
name: ctx.parse(value.name),
message: ctx.parse(value.message),
};
},
},
serialize(node, ctx) {
return (
'new DOMException(' +
ctx.serialize(node.message) +
',' +
ctx.serialize(node.name) +
')'
);
},
deserialize(node, ctx) {
return new DOMException(
ctx.deserialize(node.message) as string,
ctx.deserialize(node.name) as string,
);
},
});
export default DOMExceptionPlugin;