This feature adds a very basic OpaqueReference class. The purpose of this class is to wrap user-specified values into "opaque references": references that are hidden from the serializer. An OpaqueReference contains two values: the original value it is trying to hide, and an optional replacement value, which is what the serializer "sees".
import { serialize, deserialize, OpaqueReference } from 'seroval';
const example = {
transparent: "This is a transparent value.",
opaque: new OpaqueReference('This is an opaque value.'),
};
// You can still access the original value:
console.log(example.opaque.value);
// but now it's different
const deserialized = deserialize(serialize(example));
console.log(deserialized.opaque); // undefined
Fixes #41
This feature adds a very basic
OpaqueReference
class. The purpose of this class is to wrap user-specified values into "opaque references": references that are hidden from the serializer. AnOpaqueReference
contains two values: the original value it is trying to hide, and an optional replacement value, which is what the serializer "sees".A replacement value can only be a value that seroval can serialize. By default, a replacement value is
undefined
.Example: