@acot/core 中文文档教程

发布于 3年前 浏览 19 项目主页 更新于 3年前

@acot/core

该模块是 acot 的底层。

Installation

通过npm安装:

$ npm install --save @acot/core

Usage

以下是使用@acot/acot-preset-wcag预设包的例子。 从如何分别使用 Simple 和 Advanced 学习 @acot/core

Simple

在简单示例中,它依赖于以下包。

$ npm install --save puppeteer

以下是指定所有审核页面及其配置的示例。

import { Acot, PresetLoader } from '@acot/core';

const cwd = process.cwd();

(async () => {
  const loader = new PresetLoader(cwd);

  const acot = new Acot({
    parallel: 4,
    origin: 'http://localhost:8000',
    presets: [loader.load('@acot/wcag')],
    cwd,
  });

  acot.add('/', {
    rules: {
      '@acot/wcag/page-has-title': ['error', null],
      '@acot/wcag/page-has-valid-lang': ['warn', null],
    },
  });

  const summary = await acot.audit();

  console.log('errorCount: %f', summary.errorCount);
  console.log('warningCount: %f', summary.warningCount);
  console.log('passCount: %f', summary.passCount);
})();

Advanced

在高级示例中,使用了以下包。

下面是根据配置文件acot.config.js)进行审计的例子.

import { loadConfig, ConfigRouter } from '@acot/config';
import { findChrome } from '@acot/find-chrome';
import { Acot } from '@acot/core';

const cwd = process.cwd();

(async () => {
  const config = await loadConfig('.', { cwd });
  const router = new ConfigRouter(config);

  const acot = new Acot({
    parallel: 4,
    origin: 'http://localhost:8000',
    presets: config.presets ?? [],
    launchOptions: {
      executablePath: (await findChrome())!.executablePath,
    },
    cwd,
  });

  config.paths?.forEach((path) => {
    const entry = router.resolve(path);

    acot.add(path, {
      rules: entry.rules,
      presets: entry.presets,
      headers: entry.headers,
    });
  });

  const summary = await acot.audit();

  console.log('errorCount: %f', summary.errorCount);
  console.log('warningCount: %f', summary.warningCount);
  console.log('passCount: %f', summary.passCount);
})();

@acot/core

This module is a low layer of acot.

Installation

Install via npm:

$ npm install --save @acot/core

Usage

The following is an example of using the @acot/acot-preset-wcag preset package. Learn @acot/core from how to use Simple and Advanced respectively.

Simple

In the simple example, it depends on the following package.

$ npm install --save puppeteer

The following is an example of specifying all audited pages and their configuration.

import { Acot, PresetLoader } from '@acot/core';

const cwd = process.cwd();

(async () => {
  const loader = new PresetLoader(cwd);

  const acot = new Acot({
    parallel: 4,
    origin: 'http://localhost:8000',
    presets: [loader.load('@acot/wcag')],
    cwd,
  });

  acot.add('/', {
    rules: {
      '@acot/wcag/page-has-title': ['error', null],
      '@acot/wcag/page-has-valid-lang': ['warn', null],
    },
  });

  const summary = await acot.audit();

  console.log('errorCount: %f', summary.errorCount);
  console.log('warningCount: %f', summary.warningCount);
  console.log('passCount: %f', summary.passCount);
})();

Advanced

In the advanced example, the following package is used.

The following is an example of performing an audit according to the configuration file (acot.config.js).

import { loadConfig, ConfigRouter } from '@acot/config';
import { findChrome } from '@acot/find-chrome';
import { Acot } from '@acot/core';

const cwd = process.cwd();

(async () => {
  const config = await loadConfig('.', { cwd });
  const router = new ConfigRouter(config);

  const acot = new Acot({
    parallel: 4,
    origin: 'http://localhost:8000',
    presets: config.presets ?? [],
    launchOptions: {
      executablePath: (await findChrome())!.executablePath,
    },
    cwd,
  });

  config.paths?.forEach((path) => {
    const entry = router.resolve(path);

    acot.add(path, {
      rules: entry.rules,
      presets: entry.presets,
      headers: entry.headers,
    });
  });

  const summary = await acot.audit();

  console.log('errorCount: %f', summary.errorCount);
  console.log('warningCount: %f', summary.warningCount);
  console.log('passCount: %f', summary.passCount);
})();
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文