export function parseNumber ( optionValue , errorMessage = "The value should be a number." ) { switch ( typeof optionValue ) { case "number" : { return optionValue ; } case "string" : { let result ; try { result = parseFloat ( optionValue ) ; } catch ( err ) { throw new Error ( errorMessage ) ; } if ( Number . isNaN ( result ) ) { throw new Error ( errorMessage ) ; } return result ; } case "undefined" : { return undefined ; } default : { throw new Error ( errorMessage ) ; } } }