mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Linter: apply all recommended biome settings
Enforces previously-skipped useArrowFunction check
This commit is contained in:
@@ -9,7 +9,7 @@ const assert = require('node:assert');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
const assertNormalized = function (data) {
|
||||
const assertNormalized = (data) => {
|
||||
let min = 255;
|
||||
let max = 0;
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
@@ -20,48 +20,48 @@ const assertNormalized = function (data) {
|
||||
assert.ok(max > 248, 'max too low');
|
||||
};
|
||||
|
||||
describe('Normalization', function () {
|
||||
it('spreads rgb image values between 0 and 255', function (_t, done) {
|
||||
describe('Normalization', () => {
|
||||
it('spreads rgb image values between 0 and 255', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithLowContrast)
|
||||
.normalise()
|
||||
.raw()
|
||||
.toBuffer(function (err, data) {
|
||||
.toBuffer((err, data) => {
|
||||
if (err) throw err;
|
||||
assertNormalized(data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('spreads grayscaled image values between 0 and 255', function (_t, done) {
|
||||
it('spreads grayscaled image values between 0 and 255', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithLowContrast)
|
||||
.greyscale()
|
||||
.normalize()
|
||||
.raw()
|
||||
.toBuffer(function (err, data) {
|
||||
.toBuffer((err, data) => {
|
||||
if (err) throw err;
|
||||
assertNormalized(data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('stretches greyscale images with alpha channel', function (_t, done) {
|
||||
it('stretches greyscale images with alpha channel', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithGreyAlpha)
|
||||
.normalise()
|
||||
.raw()
|
||||
.toBuffer(function (err, data) {
|
||||
.toBuffer((err, data) => {
|
||||
if (err) throw err;
|
||||
assertNormalized(data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps an existing alpha channel', function (_t, done) {
|
||||
it('keeps an existing alpha channel', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.resize(8, 8)
|
||||
.normalize()
|
||||
.toBuffer(function (err, data) {
|
||||
.toBuffer((err, data) => {
|
||||
if (err) throw err;
|
||||
sharp(data).metadata(function (err, metadata) {
|
||||
sharp(data).metadata((err, metadata) => {
|
||||
if (err) return done(err);
|
||||
assert.strictEqual(4, metadata.channels);
|
||||
assert.strictEqual(true, metadata.hasAlpha);
|
||||
@@ -71,13 +71,13 @@ describe('Normalization', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps the alpha channel of greyscale images intact', function (_t, done) {
|
||||
it('keeps the alpha channel of greyscale images intact', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithGreyAlpha)
|
||||
.resize(8, 8)
|
||||
.normalise()
|
||||
.toBuffer(function (err, data) {
|
||||
.toBuffer((err, data) => {
|
||||
if (err) throw err;
|
||||
sharp(data).metadata(function (err, metadata) {
|
||||
sharp(data).metadata((err, metadata) => {
|
||||
if (err) return done(err);
|
||||
assert.strictEqual(true, metadata.hasAlpha);
|
||||
assert.strictEqual(4, metadata.channels);
|
||||
@@ -87,76 +87,76 @@ describe('Normalization', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('does not alter images with only one color', function (_t, done) {
|
||||
it('does not alter images with only one color', (_t, done) => {
|
||||
const output = fixtures.path('output.unmodified-png-with-one-color.png');
|
||||
sharp(fixtures.inputPngWithOneColor)
|
||||
.normalize()
|
||||
.toFile(output, function (err) {
|
||||
.toFile(output, (err) => {
|
||||
if (err) done(err);
|
||||
fixtures.assertMaxColourDistance(output, fixtures.inputPngWithOneColor, 0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('works with 16-bit RGBA images', function (_t, done) {
|
||||
it('works with 16-bit RGBA images', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithTransparency16bit)
|
||||
.normalise()
|
||||
.raw()
|
||||
.toBuffer(function (err, data) {
|
||||
.toBuffer((err, data) => {
|
||||
if (err) throw err;
|
||||
assertNormalized(data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle luminance range', function (_t, done) {
|
||||
it('should handle luminance range', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithLowContrast)
|
||||
.normalise({ lower: 10, upper: 70 })
|
||||
.raw()
|
||||
.toBuffer(function (err, data) {
|
||||
.toBuffer((err, data) => {
|
||||
if (err) throw err;
|
||||
assertNormalized(data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow lower without upper', function () {
|
||||
it('should allow lower without upper', () => {
|
||||
assert.doesNotThrow(() => sharp().normalize({ lower: 2 }));
|
||||
});
|
||||
it('should allow upper without lower', function () {
|
||||
it('should allow upper without lower', () => {
|
||||
assert.doesNotThrow(() => sharp().normalize({ upper: 98 }));
|
||||
});
|
||||
it('should throw when lower is out of range', function () {
|
||||
it('should throw when lower is out of range', () => {
|
||||
assert.throws(
|
||||
() => sharp().normalise({ lower: -10 }),
|
||||
/Expected number between 0 and 99 for lower but received -10 of type number/
|
||||
);
|
||||
});
|
||||
it('should throw when upper is out of range', function () {
|
||||
it('should throw when upper is out of range', () => {
|
||||
assert.throws(
|
||||
() => sharp().normalise({ upper: 110 }),
|
||||
/Expected number between 1 and 100 for upper but received 110 of type number/
|
||||
);
|
||||
});
|
||||
it('should throw when lower is not a number', function () {
|
||||
it('should throw when lower is not a number', () => {
|
||||
assert.throws(
|
||||
() => sharp().normalise({ lower: 'fail' }),
|
||||
/Expected number between 0 and 99 for lower but received fail of type string/
|
||||
);
|
||||
});
|
||||
it('should throw when upper is not a number', function () {
|
||||
it('should throw when upper is not a number', () => {
|
||||
assert.throws(
|
||||
() => sharp().normalise({ upper: 'fail' }),
|
||||
/Expected number between 1 and 100 for upper but received fail of type string/
|
||||
);
|
||||
});
|
||||
it('should throw when the lower and upper are equal', function () {
|
||||
it('should throw when the lower and upper are equal', () => {
|
||||
assert.throws(
|
||||
() => sharp().normalise({ lower: 2, upper: 2 }),
|
||||
/Expected lower to be less than upper for range but received 2 >= 2/
|
||||
);
|
||||
});
|
||||
it('should throw when the lower is greater than upper', function () {
|
||||
it('should throw when the lower is greater than upper', () => {
|
||||
assert.throws(
|
||||
() => sharp().normalise({ lower: 3, upper: 2 }),
|
||||
/Expected lower to be less than upper for range but received 3 >= 2/
|
||||
|
||||
Reference in New Issue
Block a user