mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 18:01:36 +03:00
2a55c5767f
no issue
- Convert validator to an npm dependency
- clean up validator imports
- fix validator function imports
- remove unused validator extensions
- Convert devicejs to an npm dependency
- Convert remaining used bower deps to npm deps
- 🔥 Remove bower & unused bower dependencies
- remove globals imports in favor of direct module imports where possible
39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
import BaseValidator from './base';
|
|
import validator from 'npm:validator';
|
|
import {isBlank} from '@ember/utils';
|
|
|
|
export default BaseValidator.create({
|
|
properties: ['label', 'url'],
|
|
|
|
label(model) {
|
|
let label = model.get('label');
|
|
let hasValidated = model.get('hasValidated');
|
|
|
|
if (isBlank(label)) {
|
|
model.get('errors').add('label', 'You must specify a label');
|
|
this.invalidate();
|
|
}
|
|
|
|
hasValidated.addObject('label');
|
|
},
|
|
|
|
url(model) {
|
|
let url = model.get('url');
|
|
let hasValidated = model.get('hasValidated');
|
|
/* eslint-disable camelcase */
|
|
let validatorOptions = {require_protocol: true};
|
|
/* eslint-enable camelcase */
|
|
let urlRegex = new RegExp(/^(\/|#|[a-zA-Z0-9-]+:)/);
|
|
|
|
if (isBlank(url)) {
|
|
model.get('errors').add('url', 'You must specify a URL or relative path');
|
|
this.invalidate();
|
|
} else if (url.match(/\s/) || (!validator.isURL(url, validatorOptions) && !url.match(urlRegex))) {
|
|
model.get('errors').add('url', 'You must specify a valid URL or relative path');
|
|
this.invalidate();
|
|
}
|
|
|
|
hasValidated.addObject('url');
|
|
}
|
|
});
|