MCPcopy Create free account
hub / github.com/angular/components / parseInput

Function parseInput

docs/tools/lighthouse-audit.mjs:177–203  ·  view source on GitHub ↗

* Parse CLI args and throw errors if any are invalid. * the validated URL, parsed minimum scores, and optional file path to write the report to

(args)

Source from the content-addressed store, hash-verified

175 * the validated URL, parsed minimum scores, and optional file path to write the report to
176 */
177function parseInput(args) {
178 const [url, minScoresRaw] = args;
179
180 if (!url) {
181 onError('Invalid arguments: <url> not specified.');
182 } else if (!minScoresRaw) {
183 onError('Invalid arguments: <min-scores> not specified.');
184 }
185
186 const minScores = parseMinScores(minScoresRaw || '');
187 const unknownCategories = Object.keys(minScores).filter(cat => !AUDIT_CATEGORIES.includes(cat));
188 const allValuesValid = Object.values(minScores).every(x => 0 <= x && x <= 1);
189
190 if (unknownCategories.length > 0) {
191 onError(
192 `Invalid arguments: <min-scores> contains unknown category(-ies): ${unknownCategories.join(
193 ', ',
194 )}`,
195 );
196 } else if (!allValuesValid) {
197 onError(
198 `Invalid arguments: <min-scores> has non-numeric or out-of-range values: ${minScoresRaw}`,
199 );
200 }
201
202 return {url, minScores};
203}
204
205/**
206 * @param {string} raw is either a number (in which case it is interpreted as `all:<min-score>`)

Callers 1

_mainFunction · 0.85

Calls 3

onErrorFunction · 0.85
parseMinScoresFunction · 0.85
filterMethod · 0.45

Tested by

no test coverage detected