Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import _Messages from 'ember-validators/messages';
import { assign } from '@ember/polyfills';
import { capitalize, dasherize } from '@ember/string';
const Messages = assign({}, _Messages);
export default assign(Messages, {
// Blank and present are flipped in ember-validators. Need to flip them back here
blank: _Messages.present,
present: _Messages.blank,
getDescriptionFor(key = '') {
return capitalize(dasherize(key).split(/[_-]/g).join(' '));
}
});
import _Messages from 'ember-validators/messages';
import { assign } from '@ember/polyfills';
import { capitalize, dasherize } from '@ember/string';
const Messages = assign({}, _Messages);
export default assign(Messages, {
// Blank and present are flipped in ember-validators. Need to flip them back here
blank: _Messages.present,
present: _Messages.blank,
getDescriptionFor(key = '') {
return capitalize(dasherize(key).split(/[_-]/g).join(' '));
}
});
return (key, value, _oldValue, changes, content) => {
if (target && (changes[target] || (changes[target] === undefined && content[target]))) {
if ((changes[target] === targetValue) || (changes[target] === undefined && (content[target] === targetValue))) {
return true;
}
}
const result = validate('presence', value, options, null, key);
if (typeof result === 'boolean' || typeof result === 'string') {
return result;
}
// We flipped the meaning behind `present` and `blank` so switch the two
if (result.type === 'present') {
result.type = 'blank';
} else if (result.type === 'blank') {
result.type = 'present';
}
return buildMessage(key, result);
};
}
return (key, value, _oldValue, changes, content) => {
if (targets && !targets.some((target) => changes[target] || (changes[target] === undefined && content[target]))) {
return true;
}
let result = validate('presence', value, options, null, key);
if (typeof result === 'boolean' || typeof result === 'string') {
return result;
} else {
// We flipped the meaning behind `present` and `blank` so switch the two
if (result.type === 'present') {
result.type = 'blank';
} else if (result.type === 'blank') {
result.type = 'present';
}
return buildMessage(key, result);
}
};
}
export default function processResult(result) {
if (result && typeof result === 'object') {
let { type, context, message } = result;
if (message) {
return message;
}
set(context, 'description', Messages.getDescriptionFor(undefined, context));
return Messages.getMessageFor(type, context);
}
return result;
}
createErrorMessage(type, value, options) {
set(options, 'description', Messages.getDescriptionFor(undefined, options));
return Messages.getMessageFor(type, options);
}
};
createErrorMessage(type, value, options) {
set(options, 'description', Messages.getDescriptionFor(undefined, options));
return Messages.getMessageFor(type, options);
}
};
export default function processResult(result) {
if (result && typeof result === 'object') {
let { type, context, message } = result;
if (message) {
return message;
}
set(context, 'description', Messages.getDescriptionFor(undefined, context));
return Messages.getMessageFor(type, context);
}
return result;
}
isURL: computed('url', function() {
const url = get(this, 'url');
return regularExpressions.url.test(url);
}).readOnly()
});
}
if (type && !regex && regularExpressions[type]) {
regex = regularExpressions[type];
}
if (type === 'email') {
if (regex === regularExpressions.email) {
regex = formatEmailRegex(options);
}
set(options, 'regex', regex);
}
if (!canInvoke(value, 'match') || (regex && isEmpty(value.match(regex)) !== inverse)) {
return validationError(type || 'invalid', value, options);
}
return true;
}