constructor()

in tools/pkglint/lib/packagejson.ts [68:87]


  constructor(public readonly fullPath: string) {
    this.json = JSON.parse(fs.readFileSync(fullPath, { encoding: 'utf-8' }));
    this.packageRoot = path.dirname(path.resolve(fullPath));
    this.packageName = this.json.name;

    const disabled = this.json.pkglint && this.json.pkglint.ignore;
    this.includeRules = _forceArray(this.json.pkglint && this.json.pkglint.include) || [/^.*$/];
    this.excludeRules = _forceArray(this.json.pkglint && this.json.pkglint.exclude) || (disabled ? [/^.*$/] : []);

    function _forceArray(arg: string | string[] | undefined): RegExp[] | undefined {
      if (arg == null) { return arg; }
      if (Array.isArray(arg)) { return arg.map(_toRegExp); }
      return [_toRegExp(arg)];
    }

    function _toRegExp(pattern: string): RegExp {
      pattern = pattern.split('*').map(s => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('.*');
      return new RegExp(`^${pattern}$`);
    }
  }