1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-21 14:29:40 +02:00
portainer/app/kubernetes/helpers/formValidationHelper.js
cong meng f2faccdb10
feat(k8s): better form validation for configuration keys (#4728) (#4733)
Co-authored-by: Simon Meng <simon.meng@portainer.io>
2021-02-27 01:53:47 +01:00

26 lines
586 B
JavaScript

import _ from 'lodash-es';
class KubernetesFormValidationHelper {
static getInvalidKeys(names) {
const res = {};
_.forEach(names, (name, index) => {
const valid = /^[-._a-zA-Z0-9]+$/.test(name);
if (!valid) {
res[index] = true;
}
});
return res;
}
static getDuplicates(names) {
const groupped = _.groupBy(names);
const res = {};
_.forEach(names, (name, index) => {
if (groupped[name].length > 1 && name) {
res[index] = name;
}
});
return res;
}
}
export default KubernetesFormValidationHelper;