Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions lib/operation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,10 @@ function median (size) {
* @throws {Error} Invalid parameters
*/
function blur (options) {
let sigma;
if (is.number(options)) {
sigma = options;
} else if (is.plainObject(options)) {
let sigma = options;
if (is.plainObject(options)) {
if (!is.number(options.sigma)) {
throw is.invalidParameterError('options.sigma', 'number between 0.3 and 1000', sigma);
throw is.invalidParameterError('options.sigma', 'number between 0.3 and 1000', options.sigma);
}
sigma = options.sigma;
if ('precision' in options) {
Expand Down
14 changes: 14 additions & 0 deletions test/unit/blur.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,18 @@ suite('Blur', () => {
sharp(fixtures.inputJpg).blur({ precision: 'invalid' });
}, /Expected number between 0.3 and 1000 for options.sigma but received undefined of type undefined/);
});

test('invalid options.sigma', (t) => {
t.plan(1);
t.assert.throws(() => {
sharp(fixtures.inputJpg).blur({ sigma: 'x' });
}, /Expected number between 0.3 and 1000 for options.sigma but received x of type string/);
});

test('invalid sigma', (t) => {
t.plan(1);
t.assert.throws(() => {
sharp(fixtures.inputJpg).blur('5');
}, /Expected number between 0.3 and 1000 for sigma but received 5 of type string/);
});
});
Loading