SchemaStringOptions.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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()`.
  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()`.
  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. * @api public
  76. * @property minlength
  77. * @memberOf SchemaStringOptions
  78. * @type Number
  79. * @instance
  80. */
  81. Object.defineProperty(SchemaStringOptions.prototype, 'minlength', opts);
  82. /**
  83. * If set, Mongoose will add a custom validator that ensures the given
  84. * string's `length` is at most the given number.
  85. *
  86. * @api public
  87. * @property maxlength
  88. * @memberOf SchemaStringOptions
  89. * @type Number
  90. * @instance
  91. */
  92. Object.defineProperty(SchemaStringOptions.prototype, 'maxlength', opts);
  93. /*!
  94. * ignore
  95. */
  96. module.exports = SchemaStringOptions;