UNPKG

631 BJavaScriptView Raw
1const _get = require("lodash/get");
2
3/**
4 * Finds the first rule in the rule set that has name pName,
5 * and undefined if no such rule exists/ the rule is an 'allowed'
6 * rule.
7 *
8 * (this thing probably belongs in a model-like folder and not in utl)
9 * @param {IRuleSetType} pRuleSet - The rule set to search in
10 * @param {string} pName - The rule name to look for
11 * @return {IForbiddenRuleType|IAllowedRuleType} - a rule (or 'undefined' if nothing found)
12 */
13module.exports = function findRuleByName(pRuleSet, pName) {
14 return _get(pRuleSet, "forbidden", []).find(
15 (pForbiddenRule) => pForbiddenRule.name === pName
16 );
17};