Socket
Socket
Sign inDemoInstall

amphtml-validator

Package Overview
Dependencies
5
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    amphtml-validator

Validator for AMP HTML (www.ampproject.org)


Version published
Weekly downloads
31K
decreased by-3.71%
Maintainers
1
Install size
210 kB
Created
Weekly downloads
 

Readme

Source

amphtml-validator Node.js package (Beta!)

HI THERE - THIS IS IN FLUX AND SOMEWHAT BROKEN - PLEASE DON'T USE IT YET TIL THIS MESSAGE IS GONE. THANKS MUCH. :-)

Using the command-line tool (Beta!)

  • Type ./index.sh in this directory to get started:
$ ./index.sh ../testdata/feature_tests/minimum_valid_amp.html
../testdata/feature_tests/minimum_valid_amp.html: PASS

$ ./index.sh ../testdata/feature_tests/several_errors.html
../testdata/feature_tests/several_errors.html:23:2 The attribute 'charset' may not appear in tag 'meta name= and content='.
../testdata/feature_tests/several_errors.html:26:2 The tag 'script' is disallowed except in specific forms.
../testdata/feature_tests/several_errors.html:32:2 The mandatory attribute 'height' is missing in tag 'amp-img'. (see https://www.ampproject.org/docs/reference/amp-img.html)
../testdata/feature_tests/several_errors.html:34:2 The attribute 'width' in tag 'amp-ad' is set to the invalid value '100%'. (see https://www.ampproject.org/docs/reference/amp-ad.html)
...

If you wish to install the Validator as a system command, install the NPM package manager (e.g. using apt-get in Ubuntu Linux) and run npm install -g in this directory. After that, you may type amphtml-validator in any directory to invoke the validator.

Using the NodeJS API (Beta!)

This API is new and still experimental, feedback is especially welcome. We may try to port to earlier versions of NodeJS if sufficient interest exists.

'use strict';
const ampValidator = require('amphtml-validator');

ampValidator.getInstance().then((validator) => {
  const result = validator.validateString('<html>Hello, world.</html>');
  ((result.status === 'PASS') ? console.log : console.error)(result.status);
  for (const error of result.errors) {
    let msg = 'line ' + error.line + ', col ' + error.col + ': ' + error.message;
    if (error.specUrl !== null) {
      msg += ' (see ' + error.specUrl + ')';
    }
    ((error.severity === 'ERROR') ? console.error : console.warn)(msg);
  }
});

FAQs

Last updated on 20 Jul 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc