Skip to content

Commit

Permalink
Shorten some util code
Browse files Browse the repository at this point in the history
  • Loading branch information
zbjornson committed Aug 4, 2021
1 parent 65cef4c commit 5fb2355
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions lib/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,18 @@ exports.validateMetricName = function (name) {
return metricRegexp.test(name);
};

exports.validateLabelName = function (names) {
let valid = true;
(names || []).forEach(name => {
if (!labelRegexp.test(name)) {
valid = false;
}
});
return valid;
exports.validateLabelName = function (names = []) {
return names.every(name => labelRegexp.test(name));
};

exports.validateLabel = function validateLabel(savedLabels, labels) {
Object.keys(labels).forEach(label => {
if (savedLabels.indexOf(label) === -1) {
for (const label in labels) {
if (!savedLabels.includes(label)) {
throw new Error(
`Added label "${label}" is not included in initial labelset: ${util.inspect(
savedLabels,
)}`,
);
}
});
}
};

0 comments on commit 5fb2355

Please sign in to comment.