Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@ampproject/toolbox-validator-rules

ampproject196.1kApache-2.02.10.1

A library that helps query AMP Validator rules

amp

readme

AMP-Toolbox Validator Rules

npm version

Queries published AMP Validator rules and extracts information about required markup and attributes for all AMP formats.

Usage

Install via:

$ npm install @ampproject/toolbox-validator-rules

Including the Module

ES Module (Browser)

import validatorRules from '@ampproject/toolbox-validator-rules';

CommonJs (Node)

const validatorRules = require('@ampproject/toolbox-validator-rules');

Using the module

  // Loads the validator rules remotely with default options
  const rules = await validatorRules.fetch();


  // The raw unprocessed rules
  console.log(rules.raw);

  // All tags, combined with their respective attribute lists
  console.log(rules.tags);

  // All extensions
  console.log(rules.extensions);

  // Get all tag names used in AMP for Email
  // The supported formats are AMP, AMP4EMAIL, AMP4ADS and ACTIONS
  const tags = rules.getTagsForFormat('AMP4EMAIL');

  // Display their names
  console.log(tags.map(tag => tag.tagName));

  // Get information about an extension
  const ext = rules.getExtension('AMP4EMAIL', 'amp-carousel');

  // Display supported versions
  console.log(ext.versions);

Format of rules

The rules used closely follow the proto definitions from validator.proto.

Specifically:

  • The raw property is unprocessed ValidatorRules, the same format used by https://cdn.ampproject.org/v0/validator.json
  • The result of getTagsForFormat and the tags property is a list of TagSpec
  • The result of getExtension is ExtensionSpec with the htmlFormat field from TagSpec
  • The extensions property a list of ExtensionSpec with the htmlFormat field from TagSpec
  • The errors property combines ErrorFormat and ErrorSpecificity

Options

fetch optionally accepts an options object allowing you to customize its behaviour.

The following options are supported:

  • noCache: true to always fetch latest rules (by default, subsequent calls to fetch reuse the same result).
  • rules: object to use locally specified rules instead of fetching them from the AMP CDN.
  • url: override the URL where validator rules are fetched from.
  • source: one of 'local' (load rules from local file named "validator.json"), 'remote' (fetch rules from CDN) or 'auto' which is the default (tries looking for the local file first, then tries to fetch from CDN).

Example:

validatorRules.fetch({
  noCache: true,
  source: 'remote'
});

changelog

v2.8.0 (2021-05-31)

:rocket: Enhancement

:bug: Bug Fix

:memo: Documentation

Committers: 1

v2.7.6 (2021-02-01)

:rocket: Enhancement

:bug: Bug Fix

Committers: 1

v2.7.5 (2021-01-18)

:bug: Bug Fix

Committers: 4

v2.7.4 (2020-12-23)

:bug: Bug Fix

  • cli, core, linter, optimizer, runtime-fetch, validator-rules

Committers: 1

v2.7.3 (2020-12-17)

:rocket: Enhancement

:bug: Bug Fix

Committers: 1

v2.7.2 (2020-12-15)

:rocket: Enhancement

:bug: Bug Fix

:house: Internal

  • linter, optimizer

Committers: 5

v2.7.1 (2020-10-26)

:rocket: Enhancement

  • linter
  • optimizer
    • #911 Allow users to specify version numbers for auto imported extensions (@digijin)

:bug: Bug Fix

Committers: 11

v2.7.0-alpha.3 (2020-08-25)

:rocket: Enhancement

Committers: 1

v2.7.0-alpha.2 (2020-08-21)

:rocket: Enhancement

:bug: Bug Fix

:house: Internal

  • cache-url, cli, cors, linter, optimizer, runtime-fetch, runtime-version
  • linter
  • lighthouse-plugin-amp, linter, optimizer, update-cache

Committers: 3

v2.6.0 (2020-08-10)

:rocket: Enhancement

:bug: Bug Fix

:memo: Documentation

:house: Internal

Committers: 2

v2.5.14 (2020-07-24)

:rocket: Enhancement

:bug: Bug Fix

Committers: 3

v2.5.13 (2020-07-15)

:bug: Bug Fix

Committers: 1

v2.5.12 (2020-07-15)

:rocket: Enhancement

Committers: 2

v2.5.11 (2020-07-14)

:bug: Bug Fix

Committers: 1

v2.5.9 (2020-07-08)

:bug: Bug Fix

Committers: 1

v2.5.8 (2020-07-08)

:bug: Bug Fix

Committers: 1

v2.5.7 (2020-07-08)

:bug: Bug Fix

Committers: 1

v2.5.6 (2020-07-07)

:rocket: Enhancement

Committers: 1

v2.5.5 (2020-06-22)

:bug: Bug Fix

Committers: 1

v2.5.4 (2020-06-22)

:bug: Bug Fix

Committers: 1

v2.5.3 (2020-06-15)

:bug: Bug Fix

  • optimizer
    • #838 fix(optimizer): add missing dependency node-fetch (@merceyz)

Committers: 1

v2.5.2 (2020-06-11)

:bug: Bug Fix

:house: Internal

Committers: 2

v2.5.1 (2020-06-09)

:rocket: Enhancement

  • linter
  • cache-list, cli, core, cors, lighthouse-plugin-amp, linter, optimizer-express, optimizer, runtime-fetch, runtime-version, update-cache
  • cli, linter

:bug: Bug Fix

:house: Internal

Committers: 2

v2.5.0 (2020-05-29)

:rocket: Enhancement

:bug: Bug Fix

:house: Internal

Committers: 4

v2.4.0 (2020-05-13)

:bug: Bug Fix

:rocket: Enhancement

  • core, optimizer
  • linter
    • #755 Added og:image and alt text checks to linter for Stories (@Dbrown910)

:memo: Documentation

:house: Internal

Committers: 4

2.3.1 (2020-05-05)

:rocket: Enhancement

:bug: Bug Fix

:house: Internal

Committers: 5

2.3.0 (2020-04-15)

:rocket: Enhancement

  • runtime-fetch
    • #711 runtime-fetch: Update amp-geo for subdivision matching (@mdmower)
  • cli, optimizer
  • cli, runtime-version
    • #695 runtime-version: Update for custom hosts and lts (@mdmower)
  • cache-url
  • cache-url, cli
    • #705 Add support for serving types in createCacheUrl (@Enriqe)

:memo: Documentation

  • cors, optimizer-express, optimizer, update-cache
    • #690 Use relative links compatible with github&npmjs (@mdmower)
  • cli

:house: Internal

  • optimizer

Committers: 3

2.2.0 (2020-04-03)

:rocket: Enhancement

  • optimizer
    • #679 Update to use postcss and cssnano for SeparateKeyframes transform (@ijjk)
  • cli

:bug: Bug Fix

:house: Internal

Committers: 3

2.1.0 (2020-04-01)

:rocket: Enhancement

  • cli, download-runtime
    • #663 download-runtime: Add tool to download AMP runtime (@mdmower)
  • cache-url, cli
  • optimizer

:bug: Bug Fix

:memo: Documentation

:house: Internal

Committers: 4

2.0.1

:rocket: Enhancement

  • optimizer
    • #622 optimizer: Add meta tags for singleDoc self-host (@mdmower)

:bug: Bug Fix

:house: Internal

Committers: 3

2.0.0

Migration notes:

  • The SeparateKeyframe transformer's compress option has been renamed to minify. The same option will also be used by the MinifyHtml transformer. The default value continues to be true.
  • The API for implementing a custom transformer has changed. We no longer monkey patch the node class, but instead rely on helper methods defined in NodeUtils:

    const {firstChildByTag, appendChild, createElement} =
    require('@ampproject/toolbox-optimizer').NodeUtils; class CustomTransformer { constructor(config)
    { this.log_ = config.log.tag('CUSTOM'); } transform(tree, params) { this.log_.info('Running custom
    transformation for ', params.filePath); const html = firstChildByTag(tree, 'html'); if (!html)
    return; const head = firstChildByTag(html, 'head'); if (!head) return; const desc =
    createElement('meta', { name: 'description', content: 'this is just a demo', }); appendChild(head,
    desc); } }

:rocket: Enhancement

:bug: Bug Fix

:house: Internal

  • cli, core, cors, optimizer, update-cache
  • linter, optimizer-express
  • cache-list, cache-url, cli, core, cors, lighthouse-plugin-amp, linter, optimizer-express, optimizer, runtime-version, script-csp, update-cache, validator-rules
    • #568 Adds "repository" and "homepage" to every package.json (@fstanis)

Committers: 2

v1.1.2 (2019-10-15)

:bug: Bug Fix

Committers: 1

v1.1.2-alpha.0 (2019-10-09)

:rocket: Enhancement

  • optimizer
    • #518 optimizer: Make dynamic component URL rewrites optional (@mattwomple)

:bug: Bug Fix

  • optimizer

Committers: 2

v1.1.0 (2019-10-08)

:rocket: Enhancement

Committers: 4

v1.1.0-beta.1 (2019-09-19)

:rocket: Enhancement

:bug: Bug Fix

:house: Internal

Committers: 6