1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-05 20:46:14 +01:00
fab-manager/app/frontend/src/javascript/directives/validators.js
2021-07-01 11:23:58 +02:00

56 lines
1.4 KiB
JavaScript

/* eslint-disable
no-return-assign,
no-undef,
no-useless-escape,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
'use strict';
Application.Directives.directive('url', [function () {
const URL_REGEXP = /^(https?:\/\/)([\da-z\.-]+)\.([-a-z0-9\.]{2,30})([\/\w \.-]*)*\/?$/;
return {
require: 'ngModel',
link (scope, element, attributes, ctrl) {
return ctrl.$validators.url = function (modelValue, viewValue) {
if (ctrl.$isEmpty(modelValue)) {
return true;
}
if (URL_REGEXP.test(viewValue)) {
return true;
}
// otherwise, this is invalid
return false;
};
}
};
}
]);
Application.Directives.directive('endpoint', [function () {
const ENDPOINT_REGEXP = /^\/?([-._~:?#\[\]@!$&'()*+,;=%\w]+\/?)*$/;
return {
require: 'ngModel',
link (scope, element, attributes, ctrl) {
return ctrl.$validators.endpoint = function (modelValue, viewValue) {
if (ctrl.$isEmpty(modelValue)) {
return true;
}
if (ENDPOINT_REGEXP.test(viewValue)) {
return true;
}
// otherwise, this is invalid
return false;
};
}
};
}
]);