SchemaStringOptions.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. 'use strict';
  2. const SchemaTypeOptions = require('./SchemaTypeOptions');
  3. /**
  4. * The options defined on a string schematype.
  5. *
  6. * #### Example:
  7. *
  8. * const schema = new Schema({ name: String });
  9. * schema.path('name').options; // SchemaStringOptions instance
  10. *
  11. * @api public
  12. * @inherits SchemaTypeOptions
  13. * @constructor SchemaStringOptions
  14. */
  15. class SchemaStringOptions extends SchemaTypeOptions {}
  16. const opts = require('./propertyOptions');
  17. /**
  18. * Array of allowed values for this path
  19. *
  20. * @api public
  21. * @property enum
  22. * @memberOf SchemaStringOptions
  23. * @type Array
  24. * @instance
  25. */
  26. Object.defineProperty(SchemaStringOptions.prototype, 'enum', opts);
  27. /**
  28. * Attach a validator that succeeds if the data string matches the given regular
  29. * expression, and fails otherwise.
  30. *
  31. * @api public
  32. * @property match
  33. * @memberOf SchemaStringOptions
  34. * @type RegExp
  35. * @instance
  36. */
  37. Object.defineProperty(SchemaStringOptions.prototype, 'match', opts);
  38. /**
  39. * If truthy, Mongoose will add a custom setter that lowercases this string
  40. * using JavaScript's built-in `String#toLowerCase()`.
  41. *
  42. * @api public
  43. * @property lowercase
  44. * @memberOf SchemaStringOptions
  45. * @type Boolean
  46. * @instance
  47. */
  48. Object.defineProperty(SchemaStringOptions.prototype, 'lowercase', opts);
  49. /**
  50. * If truthy, Mongoose will add a custom setter that removes leading and trailing
  51. * whitespace using [JavaScript's built-in `String#trim()`](https://masteringjs.io/tutorials/fundamentals/trim-string).
  52. *
  53. * @api public
  54. * @property trim
  55. * @memberOf SchemaStringOptions
  56. * @type Boolean
  57. * @instance
  58. */
  59. Object.defineProperty(SchemaStringOptions.prototype, 'trim', opts);
  60. /**
  61. * If truthy, Mongoose will add a custom setter that uppercases this string
  62. * using JavaScript's built-in [`String#toUpperCase()`](https://masteringjs.io/tutorials/fundamentals/uppercase).
  63. *
  64. * @api public
  65. * @property uppercase
  66. * @memberOf SchemaStringOptions
  67. * @type Boolean
  68. * @instance
  69. */
  70. Object.defineProperty(SchemaStringOptions.prototype, 'uppercase', opts);
  71. /**
  72. * If set, Mongoose will add a custom validator that ensures the given
  73. * string's `length` is at least the given number.
  74. *
  75. * Mongoose supports two different spellings for this option: `minLength` and `minlength`.
  76. * `minLength` is the recommended way to specify this option, but Mongoose also supports
  77. * `minlength` (lowercase "l").
  78. *
  79. * @api public
  80. * @property minLength
  81. * @memberOf SchemaStringOptions
  82. * @type Number
  83. * @instance
  84. */
  85. Object.defineProperty(SchemaStringOptions.prototype, 'minLength', opts);
  86. Object.defineProperty(SchemaStringOptions.prototype, 'minlength', opts);
  87. /**
  88. * If set, Mongoose will add a custom validator that ensures the given
  89. * string's `length` is at most the given number.
  90. *
  91. * Mongoose supports two different spellings for this option: `maxLength` and `maxlength`.
  92. * `maxLength` is the recommended way to specify this option, but Mongoose also supports
  93. * `maxlength` (lowercase "l").
  94. *
  95. * @api public
  96. * @property maxLength
  97. * @memberOf SchemaStringOptions
  98. * @type Number
  99. * @instance
  100. */
  101. Object.defineProperty(SchemaStringOptions.prototype, 'maxLength', opts);
  102. Object.defineProperty(SchemaStringOptions.prototype, 'maxlength', opts);
  103. /**
  104. * Sets default [populate options](/docs/populate.html#query-conditions).
  105. *
  106. * @api public
  107. * @property populate
  108. * @memberOf SchemaStringOptions
  109. * @type Object
  110. * @instance
  111. */
  112. Object.defineProperty(SchemaStringOptions.prototype, 'populate', opts);
  113. /*!
  114. * ignore
  115. */
  116. module.exports = SchemaStringOptions;