MCPcopy Create free account
hub / github.com/Script-Hub-Org/Script-Hub / generateRule

Function generateRule

Rewrite-Parser.js:2903–3157  ·  view source on GitHub ↗
(node, platform, flags = {})

Source from the content-addressed store, hash-verified

2901}
2902// 生成规则
2903function generateRule(node, platform, flags = {}) {
2904 // 平台特性配置(保持不变)
2905 const platformFeatures = {
2906 mihomo: {
2907 supportsExtendedMatching: true,
2908 supportsNoResolve: true,
2909 supportsPreMatching: true,
2910 supportsSrc: true,
2911 rejectPolicyRegex: /^REJECT(-[A-Z]+)*$/,
2912 },
2913 surge: {
2914 supportsExtendedMatching: false,
2915 supportsNoResolve: true,
2916 supportsPreMatching: true,
2917 supportsSrc: false,
2918 rejectPolicyRegex: /^REJECT(-[A-Z]+)*$/,
2919 },
2920 loon: {
2921 supportsExtendedMatching: false,
2922 supportsNoResolve: false,
2923 supportsPreMatching: false,
2924 supportsSrc: false,
2925 rejectPolicyRegex: /^REJECT(-[A-Z]+)*$/,
2926 },
2927 }
2928
2929 const FLAG_SUPPORTED_TYPES = {
2930 extendedMatching: ['RULE-SET', 'DOMAIN-SET', 'DOMAIN-KEYWORD', 'DOMAIN-SUFFIX', 'DOMAIN', 'URL-REGEX'],
2931 noResolve: ['IP-CIDR', 'IP-CIDR6', 'GEOIP', 'IP-ASN', 'RULE-SET'],
2932 src: ['IP-CIDR', 'IP-CIDR6', 'GEOIP', 'IP-ASN', 'IP-SUFFIX'],
2933 preMatching: [
2934 'DOMAIN',
2935 'DOMAIN-SUFFIX',
2936 'DOMAIN-KEYWORD',
2937 'DOMAIN-SET',
2938 'DOMAIN-WILDCARD',
2939 'IP-CIDR',
2940 'IP-CIDR6',
2941 'GEOIP',
2942 'IP-ASN',
2943 'SUBNET',
2944 'DEST-PORT',
2945 'SRC-PORT',
2946 'SRC-IP',
2947 'RULE-SET',
2948
2949 'AND',
2950 'OR',
2951 'NOT',
2952 ],
2953 }
2954
2955 const LOGICAL_OPERATORS_ARITY = {
2956 AND: 'n',
2957 OR: 'n',
2958 NOT: 1,
2959 }
2960

Callers 1

modifyRuleFunction · 0.70

Calls 1

traverseTreeFunction · 0.70

Tested by

no test coverage detected