判断是否符合指定的规则

@param {string} asset 捕获的文件名
@param {Array} rules 规则列表
@return {boolean} 判断的结果
339405
function isIn(asset, rules) {
    for (let i = 0, len = rules.length; i < len; i++) {
        let rule = rules[i];
        if (typeof rule === 'function' && rule.call(this, asset)) {
            return true;
        }
        else if (typeof rule === 'object' && rule instanceof RegExp && rule.test(asset)) {
            return true;
        }
        else if (typeof rule === 'string' && asset.endsWith(rule)) {
            return true;
        }
    }

    return false;
}
104562
function rule(type = 'multi', terms = [], roles = []) {
  generation += 1;
  // FIXME ?? deepClone ??
  return {
    type: 'rule',
    generation,
    rule: {
      type,
      terms,
      roles,
    },
  };
}
527272
def check(self, file):
        
        result = []
        all_matches = []
        for filerules in os.listdir(self.rulepaths):
            try:
                rule = yara.compile(os.path.join(self.rulepaths, filerules))
            except yara.SyntaxError:
                continue
            matches = rule.match(file)
            if len(matches) > 0:
                for rulem in matches:
                    rule_family = "_".join([x for x in rulem.rule.replace("_", ".", 1).split("_")[:-1]])
                    if rule_family not in all_matches:
                        all_matches.append(rule_family)
        for rule_family in all_matches:
            rules_info_txt = requests.get('{}/family/{}'.format(self.baseurl, rule_family),
                                          auth=HTTPBasicAuth(self.user, self.pwd))
            rules_info_json = json.loads(rules_info_txt.text)
            result.append({
                'family': rule_family,
                'common_name': rules_info_json['common_name'],
                'description': rules_info_json['description'],
                'attribution': rules_info_json['attribution'],
                'alt_names': rules_info_json['alt_names'],
                'urls': rules_info_json['urls']
            })

        return result
500179
function isMatchRule(req, pathname, rule) {
  if (typeof rule === 'string') {
    return pathname.indexOf(rule) > -1;
  } else if (rule instanceof RegExp) {
    return rule.test(pathname);
  } else if (typeof rule === 'function') {
    return rule(pathname, req);
  }
}
1019583
function (type, group) {
    if (!config.assets) throw('No assets found in config');
    var t = config.assets[type];
    if (!t) throw('Asset type not found: ' + type);
    var g = t[group];
    if (!g) throw('Asset group not found: ' + group);

    if (!_.isArray(g)) g = [g];
    return _.chain(g).map(function (f) {
        return fss.source(f);
    }).map(function (f) {
        if (fs.lstatSync(f).isDirectory()) return fss.allSourceFilePaths(f);
        return f;
    }).flatten().uniq().filter(function (f) {
        var process = fss.isProcessableFile(f);
        var include = !fss.isHelperFile(_.last(f.split('/')));
        return process && include && !assetFileTypeMismatch(type, f);
    }).value();
}
104969
function rule(analyzer) {
	var re = {
		property: /^(\*|-ms-filter)/,
		selector: /^(\* html|html\s?>\s?body) /,
		value: /progid:DXImageTransform\.Microsoft|!ie$/
	};

	analyzer.setMetric('oldIEFixes');

	// * html // below IE7 fix
	// html>body // IE6 excluded fix
	// @see http://blogs.msdn.com/b/ie/archive/2005/09/02/460115.aspx
	analyzer.on('selector', function(rule, selector) {
		if (re.selector.test(selector)) {
			analyzer.incrMetric('oldIEFixes');
			analyzer.addOffender('oldIEFixes', selector);
		}
	});

	// *foo: bar // IE7 and below fix
	// -ms-filter // IE9 and below specific property
	// !ie // IE 7 and below equivalent of !important
	// @see http://www.impressivewebs.com/ie7-ie8-css-hacks/
	analyzer.on('declaration', function(rule, property, value) {
		if (re.property.test(property) || re.value.test(value)) {
			analyzer.incrMetric('oldIEFixes');
			analyzer.addOffender('oldIEFixes', format('%s {%s: %s}', rule.selectors.join(', '), property, value));
		}
	});
}
678609
function(rules, preventCombining) {

	var map = [], arr = {};
	var preventCombining = [].concat(preventCombining || []);
	preventCombining.splice(0, 0, '');
	preventCombining = preventCombining.join('|');

	// extracting every property
	for(var selector in rules) {
		var props = rules[selector];
		for(var prop in props) {
			map.push({
				selector: selector, 
				prop: prop, 
				value: props[prop], 
				combine: preventCombining.indexOf('|' + prop) < 0 && selector.indexOf('@font-face') < 0
			});
		}
	}

	// combining
	for(var i=0; i<map.length; i++) {
		if(map[i].combine === true && map[i].selector !== false) {
			for(var j=i+1;j<map.length; j++) {
				if(map[i].prop === map[j].prop && map[i].value === map[j].value) {
					map[i].selector += ', ' + map[j].selector.replace(/~~(.+)~~/, '').replace(/^%.*?%/, '');
					map[j].selector = false; // marking for removal
				}
			}
		}
	}

	// preparing the result
	for(var i=0; i<map.length; i++) {
		if(map[i].selector !== false) {
			if(!arr[map[i].selector]) arr[map[i].selector] = {}
			arr[map[i].selector][map[i].prop] = map[i].value;
		}
	}
	
	return arr;
}
112893
function (ruleString) {
    var rule = {},
      ruleArray;

    rule.name = ruleString;

    if (ruleString.indexOf(':') >= 0) {
      ruleArray = ruleString.split(':');
      rule.name = ruleArray[0];
      rule.value = ruleArray.slice(1).join(":");
    }

    return rule;
  }
363954
@Override
    @Path("/{assetPath}")
    @ApiOperation(value="Apply rules identified by assetPath.", notes="Query may contain runtime values")
    @ApiImplicitParams({
        @ApiImplicitParam(name="FactsObject", paramType="body", required=true, value="Input to apply rules against"),
        @ApiImplicitParam(name="assetPath", paramType="path", required=true, value="Identifies a .drl or .xlsx asset"),
        @ApiImplicitParam(name="rules-executor", paramType="header", required=false, value="Default is Drools")})
    public JSONObject post(String path, JSONObject content, Map<String,String> headers)
            throws ServiceException, JSONException {

        Asset rules = getRulesAsset(path);

        Operand input = new Operand(content);
        input.setContext(getContext(path));
        Query query = getQuery(path, headers);
        input.setParams(query.getFilters());
        input.setMeta(headers);

        JSONObject response = invokeRules(rules, input, getExecutor(headers));

        Status status = input.getStatus();
        if (status != null) {
            headers.put(Listener.METAINFO_HTTP_STATUS_CODE, String.valueOf(status.getCode()));
            if (response == null)
                return status.getJson();
        }

        return response;
    }
1046158
function readRules() {
    const rulesRoot = path.resolve(__dirname, "../../lib/rules")
    const result = fs.readdirSync(rulesRoot)
    const rules = []
    for (const name of result) {
        const ruleName = name.replace(/\.js$/u, "")
        const ruleId = `lodash-template/${ruleName}`

        const rule = require(path.join(rulesRoot, name))
        rule.meta.docs.ruleId = ruleId
        rule.meta.docs.ruleName = ruleName
        rules.push(rule)
    }
    return rules
}
424553
def assets(asset_options={})
      logger.debug "asset_options: #{asset_options.inspect}"
      # type of asset to create, used to guess the asset_folder name
      type = asset_options[:type] || :app_asset

      assets = []
      filters = asset_options[:filter] || ['.*']
      match_count = 0
      logger.debug "generating assets array with filter array: #{filters.join(',')}"

      assets_folder = asset_options[:assets_folder] || "assets"
      pattern = File.join(assets_folder, '*/')
      logger.debug "reading from asset type: '#{type}' from assets_folder:'#{assets_folder}' "

      # asset folder can be relative to main config file
      unless Pathname.new(pattern).absolute?
        # base_folder is determined from the configuration file
        # location, if it is not set, then the configuration file wasn't not found
        raise "configuration file not found" unless asset_options[:base_folder]
        base_folder = asset_options[:base_folder]
        pattern = File.expand_path(File.join(base_folder, pattern))
      end
      logger.debug "asset glob pattern: #{pattern}"
      folders = Dir.glob(pattern)
      logger.debug "user assets folder is empty: #{pattern}" if folders.empty?

      folders.sort.each do |folder|
        folder_basename = Pathname.new(folder).basename.to_s
        #logger.debug "matching folder: #{folder} using basename: #{folder_basename}"
        if filters.find {|filter| matches?(folder_basename, filter, asset_options)}
          logger.debug "match found for: #{folder_basename}"
          match_count += 1
          asset = RepoManager::AppAsset.create(type, folder, {})
          assets << asset
          break if ((asset_options[:match] == 'FIRST') || (asset_options[:match] == 'EXACT'))
          raise "match mode = ONE, multiple matching assets found filter" if (asset_options[:match] == 'ONE' && match_count > 1)
        end
      end

      assets
    end
953103
private boolean loadMatchRulesFromFile(String rulesUrl) {
	//load match rules from a local file
	try {
	    mCallbacks.printOutput("Loading match rules from file: " + rulesUrl);
            InputStream in = new URL(rulesUrl).openStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));

            processMatchRules(reader);
            
            return true;

	} catch (IOException e) {
	    scan.printStackTrace(e);
	} catch (NumberFormatException e) {
	    scan.printStackTrace(e);
	}
        
        return false;
    }
604288
function (logicalPath) {
        var assets = self.getAssetsForLogicalPath(logicalPath);
        return assets.map(function (asset) {
          return '<script src="' + self.prefix + '/' + asset + '"></script>';
        }).join('\n');
      }
970220
function Rule(ruleString, params, data) {
    Tools.call(this, ruleString);

    /**
     * @public
     * @memberOf {Rule}
     * @property
     * @type {Object}
     * */
    this.params = _.extend({
        basePath: '',
        queryEq: '=',
        querySep: '&'
    }, params);

    /**
     * @public
     * @memberOf {Rule}
     * @property
     * @type {Object}
     * */
    this.data = _.extend({
        name: uniqueId()
    }, data);

    /**
     * @protected
     * @memberOf {Rule}
     * @property
     * @type {Array<String>}
     * */
    this._pathParams = this._findPathParams();

    /**
     * @protected
     * @memberOf {Rule}
     * @property
     * @type {Object}
     * */
    this._queryParams = this._compileQueryParams();

    /**
     * @protected
     * @memberOf {Rule}
     * @property
     * @type {Array}
     * */
    this._queryParamsNames = _.keys(this._queryParams);

    this.params.types = _.extend({}, commonTypes, this.params.types);

    /**
     * @protected
     * @memberOf {Rule}
     * @property
     * @type {Object}
     * */
    this._kinds = _.mapValues(this.params.types, function (regex, kind) {
        return new Kind(kind, regex);
    });

    _.forEach([{
        rules: this._pathParams,
        defaultKind: 'Segment'
    }, {
        rules: this._pathRule.query,
        defaultKind: 'String'
    }], function (setup) {
        _.forEach(setup.rules, function (rule) {
            if (!rule.kind) {
                if (rule.regex) {
                    rule.setUniqueKindName();
                    this._kinds[rule.kind] = new Kind(rule.kind, rule.regex);
                } else {
                    rule.kind = setup.defaultKind;
                }
            }

            if (!_.has(this._kinds, rule.kind)) {
                throw new TypeError(f('Unknown %j parameter type %j', rule.name, rule.kind));
            }
        }, this);
    }, this);

    /**
     * @protected
     * @memberOf {Rule}
     * @property
     * @type {Object}
     * */
    this._paramsCount = this._compileParamsCount();

    /**
     * @protected
     * @memberOf {Rule}
     * @property
     * @type {RegExp}
     * */
    this._matchRegExp = this._compileMatchRegExp();
}
1325032
function CFG(rules) {
  let arr = [];

  arr.__proto__ = CFG.prototype;
  if (Array.isArray(rules)) {
    rules.forEach(arr.rule.bind(arr));
  }

  return arr;
}
490939
function Rules (options) {
  this.options = options;
  this._keep = [];
  this._remove = [];

  this.blankRule = {
    replacement: options.blankReplacement
  };

  this.keepReplacement = options.keepReplacement;

  this.defaultRule = {
    replacement: options.defaultReplacement
  };

  this.array = [];
  for (var key in options.rules) this.array.push(options.rules[key]);
}
338169
function rule() {
    var ret = this.seq(rulename, defined_as, elements, c_nl);

    var da = ret[2];
    if (da === "=") {
        return this.rules.addRule(ret[1], ret[3]);
    }
    if (da === "=/") {
        return this.rules.addAlternate(ret[1], ret[3]);
    }
    return this.fail();
}