775ac7b58c
you must login with an BTP account in order to see the app
41 lines
1 KiB
JavaScript
41 lines
1 KiB
JavaScript
'use strict';
|
|
|
|
const _ = require('lodash');
|
|
const assert = require('assert');
|
|
const starMatch = require('./star-match');
|
|
const normalizeLevel = require('../common').normalizeLevel;
|
|
|
|
class LevelsContainer {
|
|
constructor() {
|
|
this._mappings = [];
|
|
}
|
|
|
|
set(componentPattern, level) {
|
|
assert(_.isString(componentPattern), 'Component pattern should be a string');
|
|
assert(_.isString(level), 'Level should be a string');
|
|
|
|
this._mappings.push({
|
|
pattern: componentPattern,
|
|
regex: starMatch.buildRegExp(componentPattern),
|
|
level: normalizeLevel(level)
|
|
});
|
|
}
|
|
|
|
unset(componentPattern) {
|
|
assert(_.isString(componentPattern), 'Component pattern should be a string');
|
|
|
|
_.remove(this._mappings, function (mapping) {
|
|
return mapping.pattern === componentPattern;
|
|
});
|
|
}
|
|
|
|
get(component) {
|
|
for (let i = this._mappings.length - 1; i >= 0; i--) {
|
|
if (this._mappings[i].regex.test(component)) {
|
|
return this._mappings[i].level;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = LevelsContainer;
|