From 0d0f98d57184072680e8c6ec6510d33891b1da3a Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Fri, 25 Mar 2022 16:36:56 +0200 Subject: lib/rfs.js: throw a TypeError if options are invalid --- lib/rfs.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/rfs.js b/lib/rfs.js index a3e6d36..f76a835 100644 --- a/lib/rfs.js +++ b/lib/rfs.js @@ -3,10 +3,6 @@ const postcss = require('postcss'); const valueParser = require('postcss-value-parser'); -const BREAKPOINT_ERROR = 'breakpoint option is invalid, it should be set in `px`, `rem` or `em`.'; -const BREAKPOINT_UNIT_ERROR = 'breakpointUnit option is invalid, it should be `px`, `rem` or `em`.'; -const BASE_RFS_ERROR = 'baseValue option is invalid, it should be set in `px` or `rem`.'; - const defaultOptions = { baseValue: 20, unit: 'rem', @@ -31,7 +27,7 @@ module.exports = class { } else if (this.opts.baseValue.endsWith('rem')) { this.opts.baseValue = Number.parseFloat(this.opts.baseValue) * this.opts.remValue; } else { - console.error(BASE_RFS_ERROR); + throw new TypeError('`baseValue` option is invalid, it should be set in `px` or `rem`.'); } } @@ -41,12 +37,12 @@ module.exports = class { } else if (this.opts.breakpoint.endsWith('em')) { this.opts.breakpoint = Number.parseFloat(this.opts.breakpoint) * this.opts.remValue; } else { - console.error(BREAKPOINT_ERROR); + throw new TypeError('`breakpoint` option is invalid, it should be set in `px`, `rem` or `em`.'); } } if (!['px', 'rem', 'em'].includes(this.opts.breakpointUnit)) { - console.error(BREAKPOINT_UNIT_ERROR); + throw new TypeError('`breakpointUnit` option is invalid, it should be `px`, `rem` or `em`.'); } } -- cgit v1.2.3