lh-avg
v1.9.6
Published
LightHouse average calculator
Downloads
8
Maintainers
Keywords
Readme
Install
npm i --save lh-avg
Usage
CLI
Usage: cli [options] <scoreStrings...>
LightHouse average calculator
Options:
-V, --version output the version number
-p, --percentage Return the result(s) in percentage form
-f, --format <format> Return the result(s) in a specific format (json, csv, md, html), default: text
-s, --split Split the string by metric
-d, --diff Shows the difference between the first row and subsequent ones
-n, --names <names> Add names to each results
-c, --config <config> Use the configuration from the specified path
-m, --multi <multi> Show multiple results (EXPERIMENTAL, please the config option for this)
-h, --help display help for command
Configuration
The CLI will look for configuration files following the cosmiconfig
approach:
lh-avg
property inpackage.json
.lh-avgrc
(using JSON or YAML syntax).lh-avgrc.json
.lh-avgrc.yaml
/.lh-avgrc.yml
/.lh-avgrc.js
lh-avg.config.js
It will first read the configuration (if it finds one) then look at the CLI options (which overrides the relevant configuration options).
Note: If it encounters a broken/invalid JSON configuration file, it will try to fix it and save the changes to the file itself. It won't be able to do the same for YAML files!
Example
{
"format": "md",
"split": true,
"percentage": true,
"inputs": [
"86/100/79/100/(1, 1, 6)",
"90/100/79/100/(1, 2, 6)"
],
"diff": true,
"names": ["`master`", "`pr`"],
"multi": {}
}
Imports
import average from 'lh-avg';
// Or
const average = require('lh-avg').default;
Example
import average from 'lh-avg';
const lightHouseScores = ['14 / 100 / 98 / 100 / (1, 0, 6)'];
console.log(average(lightHouseScores));
/* {
perf: 0.14,
a11y: 1,
bp: 0.98,
seo: 1,
pwa: { fnr: 0.3333333333333333, ins: 0, po: 0.8571428571428571 },
average: 0.6157823129251702
} */
console.log(average(lightHouseScores, { asPercentage: true }));
/* {
perf: '14%',
a11y: '100%',
bp: '98%',
seo: '100%',
pwa: { fnr: '33.33%', ins: '0%', po: '85.71%' },
average: '61.58%'
} */
For more documentation, please check ./doc/index.html
.
Contributing
Please consult CONTRIBUTING for guidelines on contributing to this project.
Author
lh-avg © Berkmann18, Released under the Apache-2.0 License.
Contributors ✨
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!