Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* validator('inclusion', {
* in: ['Admin'] // Input must be equal to 'Admin'
* })
* validator('inclusion', {
* range: [0, Infinity] // Input must be positive number
* })
* validator('inclusion', {
* range: [-Infinity, Infinity] // Input must be a number
* })
* ```
*
* @class Inclusion
* @module Validators
* @extends Base
*/
export default EmberValidator.extend({
_evType: 'inclusion'
});
* presence: true,
* message: 'should not be empty'
* })
*
* validator('presence', {
* presence: true,
* ignoreBlank: true,
* message: 'should not be empty or consist only of spaces'
* })
* ```
*
* @class Presence
* @module Validators
* @extends Base
*/
export default EmberValidator.extend({
_evType: 'presence',
/**
* Normalized options passed in.
* ```js
* validator('presence', true)
* // Becomes
* validator('presence', {
* presence: true
* })
* ```
*
* @method buildOptions
* @param {Object} options
* @param {Object} defaultOptions
* @param {Object} globalOptions
*
* ```javascript
* validator('number') // Simple check if the value is a number
* validator('number', {
* allowString: true,
* integer: true,
* gt: 5,
* lte: 100
* })
* ```
*
* @class Number
* @module Validators
* @extends Base
*/
export default EmberValidator.extend({
_evType: 'number'
});
* ## Examples:
*
* ```javascript
* validator('exclusion', {
* in: ['Admin', 'Super Admin']
* })
* validator('exclusion', {
* range: [0, 5] // Cannot be between 0 (inclusive) to 5 (inclusive)
* })
* ```
*
* @class Exclusion
* @module Validators
* @extends Base
*/
export default EmberValidator.extend({
_evType: 'exclusion'
});
* ## Examples
*
* ```javascript
* validator('collection', true)
* validator('collection', false)
* validator('collection', {
* collection: true,
* message: 'must be a collection'
* })
* ```
*
* @class Collection
* @module Validators
* @extends Base
*/
const Collection = EmberValidator.extend({
_evType: 'collection',
/**
* Normalized options passed in.
* ```js
* validator('collection', true)
* // Becomes
* validator('collection', {
* collection: true
* })
* ```
*
* @method buildOptions
* @param {Object} options
* @param {Object} defaultOptions
* @param {Object} globalOptions
* If you do not want to use the predefined regex for a specific type, you can do something like this
*
* ```javascript
* validator('format', {
* type: 'email',
* regex: /My Better Email Regexp/
* })
* ```
*
* This allows you to still keep the email error message but with your own custom regex.
*
* @class Format
* @module Validators
* @extends Base
*/
export default EmberValidator.extend({
_evType: 'format',
regularExpressions
});
*
* ```javascript
* email: validator('format', {
* type: 'email'
* })
* verifiedEmail: validator('confirmation', {
* on: 'email',
* message: 'Email addresses do not match'
* })
* ```
*
* @class Confirmation
* @module Validators
* @extends Base
*/
const Confirmation = EmberValidator.extend({
_evType: 'confirmation'
});
Confirmation.reopenClass({
getDependentsFor(attribute, options) {
let on = get(options, 'on');
assert(
`[validator:confirmation] [${attribute}] 'on' must be a string`,
typeof on === 'string'
);
return on ? [`model.${on}`] : [];
}
});
*
* ```javascript
* validator('date', {
* after: 'now',
* before: '1/1/2020',
* precision: 'day',
* format: 'M/D/YYY',
* errorFormat: 'M/D/YYY'
* })
* ```
*
* @class Date
* @module Validators
* @extends Base
*/
export default EmberValidator.extend({
_evType: 'date'
});
* <i aria-hidden="true" class="fa fa-hand-o-right"></i> [See All Options](#method_validate)
*
* Creates a link between this library and Ember-Data's [DS.Errors](http://emberjs.com/api/data/classes/DS.Errors.html)
* to fetch the latest message for the given attribute.
*
* ## Examples
*
* ```javascript
* validator('ds-error')
* ```
*
* @class DS Error
* @module Validators
* @extends Base
*/
const DSError = EmberValidator.extend({
_evType: 'ds-error'
});
DSError.reopenClass({
getDependentsFor(attribute) {
let { path, key } = getPathAndKey(attribute);
return [`model.${path}.${key}.[]`];
}
});
export default DSError;
*
* ```javascript
* validator('length', {
* is: 15
* })
* validator('length', {
* min: 5,
* max: 10
* })
* ```
*
* @class Length
* @module Validators
* @extends Base
*/
export default EmberValidator.extend({
_evType: 'length'
});