symbol.js 911 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. 'use strict';
  2. /**
  3. * A class representation of the BSON Symbol type.
  4. */
  5. class BSONSymbol {
  6. /**
  7. * Create a Symbol type
  8. *
  9. * @param {string} value the string representing the symbol.
  10. */
  11. constructor(value) {
  12. this.value = value;
  13. }
  14. /**
  15. * Access the wrapped string value.
  16. *
  17. * @method
  18. * @return {String} returns the wrapped string.
  19. */
  20. valueOf() {
  21. return this.value;
  22. }
  23. /**
  24. * @ignore
  25. */
  26. toString() {
  27. return this.value;
  28. }
  29. /**
  30. * @ignore
  31. */
  32. inspect() {
  33. return this.value;
  34. }
  35. /**
  36. * @ignore
  37. */
  38. toJSON() {
  39. return this.value;
  40. }
  41. /**
  42. * @ignore
  43. */
  44. toExtendedJSON() {
  45. return { $symbol: this.value };
  46. }
  47. /**
  48. * @ignore
  49. */
  50. static fromExtendedJSON(doc) {
  51. return new BSONSymbol(doc.$symbol);
  52. }
  53. }
  54. Object.defineProperty(BSONSymbol.prototype, '_bsontype', { value: 'Symbol' });
  55. module.exports = BSONSymbol;