+35
| #!/usr/bin/env node | ||
| const pkg = require('../package.json'); | ||
| const dolbear = require('../index.js'); | ||
| const { Command } = require('commander'); | ||
| const program = new Command(); | ||
| program | ||
| .version(pkg.version) | ||
| .description(`${pkg.description} Use the number of cricket chirps to calculate the temperature. For celsius, count the number of chirps per 8 seconds. For fahrenheit, count the number of chirps per 15 seconds.`) | ||
| .option('--scale <c|f>', 'set the scale (fahrenheit or celsius)', 'c') | ||
| .arguments('number-of-chirps') | ||
| .action(run); | ||
| program.parse(process.argv); | ||
| function run(chirps) { | ||
| const programOpts = program.opts(); | ||
| switch (programOpts.scale) { | ||
| case 'c': | ||
| print(dolbear.Celsius(Number(chirps)), 'c'); | ||
| break; | ||
| case 'f': | ||
| print(dolbear.Fahrenheit(Number(chirps)), 'f'); | ||
| break; | ||
| default: | ||
| console.error('Invalid scale'); | ||
| } | ||
| } | ||
| function print(temp, scale) { | ||
| let scaleName = scale == 'c' ? 'Celsius' : 'Fahrenheit'; | ||
| console.log(`The estimated temperature based on your input is ${temp}° ${scaleName}.`); | ||
| } |
+2
-2
@@ -7,3 +7,3 @@ 'use strict'; | ||
| function dolbearTempCelcius (numberOfCricketsPer8Seconds) { | ||
| function dolbearTempCelsius (numberOfCricketsPer8Seconds) { | ||
| return numberOfCricketsPer8Seconds + 5; | ||
@@ -14,3 +14,3 @@ } | ||
| Fahrenheit: dolbearTempFahrenheit, | ||
| Celcius: dolbearTempCelcius | ||
| Celsius: dolbearTempCelsius | ||
| }; |
+12
-4
| { | ||
| "name": "dolbear", | ||
| "version": "1.0.0", | ||
| "version": "2.0.0", | ||
| "description": "Formula for Dolbear's Law.", | ||
| "main": "index.js", | ||
| "bin": "./bin/cli.js", | ||
| "scripts": { | ||
| "test": "node test/test.js" | ||
| }, | ||
| "files": [ | ||
| "files": [ | ||
| "index.js" | ||
@@ -14,3 +15,7 @@ ], | ||
| "type": "commonjs", | ||
| "keywords": ["dolbear", "crickets", "temperature"], | ||
| "keywords": [ | ||
| "dolbear", | ||
| "crickets", | ||
| "temperature" | ||
| ], | ||
| "author": "Lucas Holmquist", | ||
@@ -23,3 +28,6 @@ "engines": { | ||
| }, | ||
| "homepage": "https://github.com/salty-pig/dolbear#readme" | ||
| "homepage": "https://github.com/salty-pig/dolbear#readme", | ||
| "dependencies": { | ||
| "commander": "^10.0.1" | ||
| } | ||
| } |
+2
-2
@@ -20,3 +20,3 @@ # dolbear | ||
| For the temperature in Celcius: | ||
| For the temperature in Celsius: | ||
@@ -27,5 +27,5 @@ ``` | ||
| const numberOfCricketChirpsPer8Seconds = 5; | ||
| const temperature = dolbear.Celcius(numberOfCricketChirpsPer8Seconds); | ||
| const temperature = dolbear.Celsius(numberOfCricketChirpsPer8Seconds); | ||
| console.log(temperature); // 10 | ||
| ``` |
14020
8.99%5
25%40
263.64%1
Infinity%+ Added
+ Added