MCPcopy
hub / github.com/DIYgod/RSSHub-Radar / parseRules

Function parseRules

src/lib/rules.ts:9–31  ·  view source on GitHub ↗
(rules: string, forceJSON?: boolean)

Source from the content-addressed store, hash-verified

7import { getRadarRulesUrl } from "./utils"
8
9export 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
33export function getRulesCount(rules: Rules) {
34 let index = 0

Callers 5

getPageRSSHubFunction · 0.90
getWebsiteRSSHubFunction · 0.90
getDisplayedRulesFunction · 0.90
RulesFunction · 0.90
GeneralFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected