RegExpObjectSerializer.js 846 B

12345678910111213141516171819202122232425262728293031
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. */
  4. "use strict";
  5. /** @typedef {import("./ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
  6. /** @typedef {import("./ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
  7. class RegExpObjectSerializer {
  8. /**
  9. * Serializes this instance into the provided serializer context.
  10. * @param {RegExp} obj regexp
  11. * @param {ObjectSerializerContext} context context
  12. */
  13. serialize(obj, context) {
  14. context.write(obj.source);
  15. context.write(obj.flags);
  16. }
  17. /**
  18. * Restores this instance from the provided deserializer context.
  19. * @param {ObjectDeserializerContext} context context
  20. * @returns {RegExp} regexp
  21. */
  22. deserialize(context) {
  23. return new RegExp(context.read(), context.read());
  24. }
  25. }
  26. module.exports = RegExpObjectSerializer;