UNPKG

dependency-cruiser

Version:

Validate and visualize dependencies. With your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.

40 lines (30 loc) 932 B
"use strict"; const VALID_SEVERITIES = /^(error|warn|info)$/; const DEFAULT_SEVERITY = 'warn'; const DEFAULT_RULE = 'unnamed'; function normalizeSeverity (pSeverity){ let lSeverity = pSeverity ? pSeverity : DEFAULT_SEVERITY; return Boolean(lSeverity.match(VALID_SEVERITIES)) ? lSeverity : DEFAULT_SEVERITY; } function normalizeName(pRule) { return pRule ? pRule : DEFAULT_RULE; } function normalizeRule(pRule) { return Object.assign( pRule, { severity : normalizeSeverity(pRule.severity), name : normalizeName(pRule.name) } ); } function normalize(pRuleSet) { if (pRuleSet.hasOwnProperty("allowed")){ pRuleSet.allowed = pRuleSet.allowed.map(normalizeRule); } if (pRuleSet.hasOwnProperty("forbidden")){ pRuleSet.forbidden = pRuleSet.forbidden.map(normalizeRule); } return pRuleSet; } module.exports = normalize;