(rules: string, forceJSON?: boolean)
| 7 | import { getRadarRulesUrl } from "./utils" |
| 8 | |
| 9 | export function parseRules(rules: string, forceJSON?: boolean) { |
| 10 | let incomeRules: unknown = rules |
| 11 | |
| 12 | if (typeof rules === "string") { |
| 13 | try { |
| 14 | incomeRules = JSON.parse(rules) |
| 15 | } catch (error) { |
| 16 | incomeRules = forceJSON ? {} : rules |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | if (!_.isPlainObject(incomeRules)) { |
| 21 | incomeRules = {} |
| 22 | } |
| 23 | |
| 24 | return _.mergeWith({}, defaultRules, incomeRules, (objValue, srcValue) => { |
| 25 | if (_.isFunction(srcValue)) { |
| 26 | return srcValue |
| 27 | } else if (_.isFunction(objValue)) { |
| 28 | return objValue |
| 29 | } |
| 30 | }) as Rules |
| 31 | } |
| 32 | |
| 33 | export function getRulesCount(rules: Rules) { |
| 34 | let index = 0 |
no outgoing calls
no test coverage detected