int_32.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 | 0;
  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. Int32.prototype.toString = function (radix) {
  31. return this.value.toString(radix);
  32. };
  33. Int32.prototype.toJSON = function () {
  34. return this.value;
  35. };
  36. /** @internal */
  37. Int32.prototype.toExtendedJSON = function (options) {
  38. if (options && (options.relaxed || options.legacy))
  39. return this.value;
  40. return { $numberInt: this.value.toString() };
  41. };
  42. /** @internal */
  43. Int32.fromExtendedJSON = function (doc, options) {
  44. return options && options.relaxed ? parseInt(doc.$numberInt, 10) : new Int32(doc.$numberInt);
  45. };
  46. /** @internal */
  47. Int32.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () {
  48. return this.inspect();
  49. };
  50. Int32.prototype.inspect = function () {
  51. return "new Int32(" + this.valueOf() + ")";
  52. };
  53. return Int32;
  54. }());
  55. exports.Int32 = Int32;
  56. Object.defineProperty(Int32.prototype, '_bsontype', { value: 'Int32' });
  57. //# sourceMappingURL=int_32.js.map