serializer.js 601 B

123456789101112131415161718192021222324252627282930
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.replacer = replacer;
  6. exports.reviver = reviver;
  7. function replacer(_key, value) {
  8. if (value instanceof RegExp) {
  9. return {
  10. __serialized_type: 'RegExp',
  11. source: value.source,
  12. flags: value.flags
  13. };
  14. }
  15. return value;
  16. }
  17. function reviver(_key, value) {
  18. if (typeof value === 'object' && value !== null) {
  19. // eslint-disable-next-line no-underscore-dangle
  20. if (value.__serialized_type === 'RegExp') {
  21. return new RegExp(value.source, value.flags);
  22. }
  23. }
  24. return value;
  25. }