rsnext/packages/next/compiled/amphtml-validator/index.js

1 line
33 KiB
JavaScript
Raw Normal View History

module.exports=(()=>{var e={626:(e,t,n)=>{"use strict";const r=n(671);const o=n(747);const i=n(605);const s=n(211);const u=n(622);const a=n(254);const c=n(544);const l=n(191);const f=n(835);const p=n(669);const h=n(184);const m="amphtml-validator";function hasPrefix(e,t){return e.indexOf(t)==0}function isHttpOrHttpsUrl(e){return hasPrefix(e,"http://")||hasPrefix(e,"https://")}function readFromFile(e){return new c(function(t,n){o.readFile(e,"utf8",function(e,r){if(e){n(e)}else{t(r.trim())}})})}function readFromReadable(e,t){return new c(function(n,r){const o=[];t.setEncoding("utf8");t.on("data",function(e){o.push(e)});t.on("end",function(){n(o.join(""))});t.on("error",function(t){r(new Error("Could not read from "+e+" - "+t.message))})})}function readFromStdin(){return readFromReadable("stdin",process.stdin).then(function(e){process.stdin.resume();return e})}function readFromUrl(e,t){return new c(function(n,r){const o=hasPrefix(e,"http://")?i:s;const u=o.request(e,function(t){if(t.statusCode!==200){t.resume();r(new Error("Unable to fetch "+e+" - HTTP Status "+t.statusCode))}else{n(t)}});u.setHeader("User-Agent",t);u.on("error",function(t){r(new Error("Unable to fetch "+e+" - "+t.message))});u.end()}).then(readFromReadable.bind(null,e))}function ValidationResult(){this.status="UNKNOWN";this.errors=[]}function ValidationError(){this.severity="UNKNOWN_SEVERITY";this.line=1;this.col=0;this.message="";this.specUrl=null;this.code="UNKNOWN_CODE";this.params=[]}function Validator(e){this.sandbox=h.createContext();try{new h.Script(e).runInContext(this.sandbox)}catch(e){throw new Error("Could not instantiate validator.js - "+e.message)}}Validator.prototype.validateString=function(e,t){const n=this.sandbox.amp.validator.validateString(e,t);const r=new ValidationResult;r.status=n.status;for(let e=0;e<n.errors.length;e++){const t=n.errors[e];const o=new ValidationError;o.severity=t.severity;o.line=t.line;o.col=t.col;o.message=this.sandbox.amp.validator.renderErrorMessage(t);o.specUrl=t.specUrl;o.code=t.code;o.params=t.params;r.errors.push(o)}return r};const d={};function getInstance(e,t){const n=e||"https://cdn.ampproject.org/v0/validator.js";const r=t||m;if(d.hasOwnProperty(n)){return c.resolve(d[n])}const o=isHttpOrHttpsUrl(n)?readFromUrl(n,r):readFromFile(n);return o.then(function(e){let t;try{t=new Validator(e)}catch(e){throw e}d[n]=t;return t})}t.getInstance=getInstance;function newInstance(e){return new Validator(e)}t.newInstance=newInstance;function logValidationResult(e,t,n){if(t.status==="PASS"){process.stdout.write(e+": "+(n?r.green("PASS"):"PASS")+"\n")}for(let o=0;o<t.errors.length;o++){const i=t.errors[o];let s=e+":"+i.line+":"+i.col+" ";if(n){s+=(i.severity==="ERROR"?r.red:r.magenta)(i.message)}else{s+=i.message}if(i.specUrl){s+=" (see "+i.specUrl+")"}process.stderr.write(s+"\n")}}function main(){a.usage("[options] <fileOrUrlOrMinus...>\n\n"+' Validates the files or urls provided as arguments. If "-" is\n'+" specified, reads from stdin instead.").option("--validator_js <fileOrUrl>","The Validator Javascript.\n"+" Latest published version by default, or\n"+" dist/validator_minified.js (built with build.py)\n"+" for development.","https://cdn.ampproject.org/v0/validator.js").option("--user-agent <userAgent>","User agent string to use in requests.",m).option("--html_format <AMP|AMP4ADS|AMP4EMAIL>","The input format to be validated.\n"+" AMP by default.","AMP").option("--format <color|text|json>","How to format the output.\n"+' "color" displays errors/warnings/success in\n'+" red/orange/green.\n"+' "text" avoids color (e.g., useful in terminals not\n'+" supporting color).\n"+' "json" emits json corresponding to the ValidationResult\n'+" message in validator.proto.","color").parse(process.argv);if(a.args.length===0){a.outputHelp();process.exit(1)}if(a.html_format!=="AMP"&&a.html_format!=="AMP4ADS"&&a.html_format!=="AMP4EMAIL"){process.stderr.write('--html_format must be set to "AMP", "AMP4ADS", or "AMP4EMAIL".\n',function(){process.exit(1)})}if(a.format!=="color"&&a.format!=="text"&&a.fo