int_32.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Int32 = void 0;
  4. /**
  5. * A class representation of a BSON Int32 type.
  6. * @public
  7. */
  8. var Int32 = /** @class */ (function () {
  9. /**
  10. * Create an Int32 type
  11. *
  12. * @param value - the number we want to represent as an int32.
  13. */
  14. function Int32(value) {
  15. if (!(this instanceof Int32))
  16. return new Int32(value);
  17. if (value instanceof Number) {
  18. value = value.valueOf();
  19. }
  20. this.value = +value;
  21. }
  22. /**
  23. * Access the number value.
  24. *
  25. * @returns returns the wrapped int32 number.
  26. */
  27. Int32.prototype.valueOf = function () {
  28. return this.value;
  29. };
  30. /** @internal */
  31. Int32.prototype.toJSON = function () {
  32. return this.value;
  33. };
  34. /** @internal */
  35. Int32.prototype.toExtendedJSON = function (options) {
  36. if (options && (options.relaxed || options.legacy))
  37. return this.value;
  38. return { $numberInt: this.value.toString() };
  39. };
  40. /** @internal */
  41. Int32.fromExtendedJSON = function (doc, options) {
  42. return options && options.relaxed ? parseInt(doc.$numberInt, 10) : new Int32(doc.$numberInt);
  43. };
  44. /** @internal */
  45. Int32.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () {
  46. return this.inspect();
  47. };
  48. Int32.prototype.inspect = function () {
  49. return "new Int32(" + this.valueOf() + ")";
  50. };
  51. return Int32;
  52. }());
  53. exports.Int32 = Int32;
  54. Object.defineProperty(Int32.prototype, '_bsontype', { value: 'Int32' });
  55. //# sourceMappingURL=int_32.js.map