mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 10:30:15 +02:00
Add support for non lower case extensions with toFormat
This commit is contained in:
parent
202083999e
commit
df7b8ba738
@ -188,7 +188,7 @@ function withMetadata (options) {
|
||||
* @throws {Error} unsupported format or options
|
||||
*/
|
||||
function toFormat (format, options) {
|
||||
const actualFormat = formats.get(is.object(format) && is.string(format.id) ? format.id : format);
|
||||
const actualFormat = formats.get((is.object(format) && is.string(format.id) ? format.id : format).toLowerCase());
|
||||
if (!actualFormat) {
|
||||
throw is.invalidParameterError('format', `one of: ${[...formats.keys()].join(', ')}`, format);
|
||||
}
|
||||
|
26
test/unit/toFormat.js
Normal file
26
test/unit/toFormat.js
Normal file
@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('toFormat', () => {
|
||||
it('accepts upper case characters as format parameter (string)', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.toFormat('PNG')
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('accepts upper case characters as format parameter (object)', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.toFormat({ id: 'PNG' })
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user