int_32.js 1.7 KB

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