mirror of
https://github.com/lovell/sharp.git
synced 2025-12-06 03:51:40 +01:00
Switch linter from semistandard to biome
Uses the recommended rules apart from complexity/useArrowFunction, which would affect about 1700 lines of code with little benefit right now. This is something that can be addressed over time.
This commit is contained in:
parent
a0af662d78
commit
b36237ddcb
@ -7,6 +7,4 @@ indent_size = 2
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
max_line_length = 120
|
||||
|
||||
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -13,7 +13,7 @@ jobs:
|
||||
- uses: actions/setup-node@v5
|
||||
with:
|
||||
node-version: "24"
|
||||
- run: npm install --ignore-scripts --omit=optional
|
||||
- run: npm install --ignore-scripts
|
||||
- run: npm run lint-cpp
|
||||
- run: npm run lint-js
|
||||
- run: npm run lint-licensing
|
||||
|
||||
29
biome.json
Normal file
29
biome.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"$schema": "https://biomejs.dev/schemas/2.2.4/schema.json",
|
||||
"vcs": {
|
||||
"enabled": true,
|
||||
"clientKind": "git",
|
||||
"useIgnoreFile": true
|
||||
},
|
||||
"files": {
|
||||
"ignoreUnknown": true
|
||||
},
|
||||
"linter": {
|
||||
"enabled": true,
|
||||
"rules": {
|
||||
"recommended": true,
|
||||
"complexity": {
|
||||
"useArrowFunction": "off"
|
||||
}
|
||||
}
|
||||
},
|
||||
"formatter": {
|
||||
"enabled": false,
|
||||
"useEditorconfig": true
|
||||
},
|
||||
"javascript": {
|
||||
"formatter": {
|
||||
"quoteStyle": "single"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
// @ts-check
|
||||
import { defineConfig } from 'astro/config';
|
||||
import starlight from '@astrojs/starlight';
|
||||
import { defineConfig } from 'astro/config';
|
||||
import starlightAutoSidebar from 'starlight-auto-sidebar';
|
||||
|
||||
import { version } from '../package.json';
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import jsdoc2md from 'jsdoc-to-markdown';
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
try {
|
||||
const { useGlobalLibvips, globalLibvipsVersion, log, spawnRebuild } = require('../lib/libvips');
|
||||
|
||||
@ -12,14 +10,14 @@ try {
|
||||
try {
|
||||
const addonApi = require('node-addon-api');
|
||||
log(`Found node-addon-api ${addonApi.version || ''}`);
|
||||
} catch (err) {
|
||||
} catch (_err) {
|
||||
log('Please add node-addon-api to your dependencies');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const gyp = require('node-gyp');
|
||||
log(`Found node-gyp ${gyp().version}`);
|
||||
} catch (err) {
|
||||
} catch (_err) {
|
||||
log('Please add node-gyp to your dependencies');
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const is = require('./is');
|
||||
|
||||
/**
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const color = require('@img/colour');
|
||||
const is = require('./is');
|
||||
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const is = require('./is');
|
||||
|
||||
/**
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const util = require('node:util');
|
||||
const stream = require('node:stream');
|
||||
const is = require('./is');
|
||||
@ -205,6 +203,7 @@ const debuglog = util.debuglog('sharp');
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
const Sharp = function (input, options) {
|
||||
// biome-ignore lint/complexity/noArguments: constructor factory
|
||||
if (arguments.length === 1 && !is.defined(input)) {
|
||||
throw new Error('Invalid input');
|
||||
}
|
||||
|
||||
2
lib/index.d.ts
vendored
2
lib/index.d.ts
vendored
@ -27,7 +27,7 @@
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import { Duplex } from 'stream';
|
||||
import type { Duplex } from 'node:stream';
|
||||
|
||||
//#region Constructor functions
|
||||
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const Sharp = require('./constructor');
|
||||
require('./input')(Sharp);
|
||||
require('./resize')(Sharp);
|
||||
|
||||
10
lib/input.js
10
lib/input.js
@ -1,8 +1,6 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const is = require('./is');
|
||||
const sharp = require('./sharp');
|
||||
|
||||
@ -54,7 +52,7 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
||||
const inputDescriptor = {
|
||||
autoOrient: false,
|
||||
failOn: 'warning',
|
||||
limitInputPixels: Math.pow(0x3FFF, 2),
|
||||
limitInputPixels: 0x3FFF ** 2,
|
||||
ignoreIcc: false,
|
||||
unlimited: false,
|
||||
sequentialRead: true
|
||||
@ -150,7 +148,7 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
||||
if (is.defined(inputOptions.limitInputPixels)) {
|
||||
if (is.bool(inputOptions.limitInputPixels)) {
|
||||
inputDescriptor.limitInputPixels = inputOptions.limitInputPixels
|
||||
? Math.pow(0x3FFF, 2)
|
||||
? 0x3FFF ** 2
|
||||
: 0;
|
||||
} else if (is.integer(inputOptions.limitInputPixels) && is.inRange(inputOptions.limitInputPixels, 0, Number.MAX_SAFE_INTEGER)) {
|
||||
inputDescriptor.limitInputPixels = inputOptions.limitInputPixels;
|
||||
@ -513,7 +511,7 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
||||
}
|
||||
}
|
||||
} else if (is.defined(inputOptions)) {
|
||||
throw new Error('Invalid input options ' + inputOptions);
|
||||
throw new Error(`Invalid input options ${inputOptions}`);
|
||||
}
|
||||
return inputDescriptor;
|
||||
}
|
||||
@ -525,7 +523,7 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
||||
* @param {string} encoding - unused
|
||||
* @param {Function} callback
|
||||
*/
|
||||
function _write (chunk, encoding, callback) {
|
||||
function _write (chunk, _encoding, callback) {
|
||||
/* istanbul ignore else */
|
||||
if (Array.isArray(this.options.input.buffer)) {
|
||||
/* istanbul ignore else */
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Is this value defined and not null?
|
||||
* @private
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const { spawnSync } = require('node:child_process');
|
||||
const { createHash } = require('node:crypto');
|
||||
const semverCoerce = require('semver/functions/coerce');
|
||||
@ -96,7 +94,7 @@ const isUnsupportedNodeRuntime = () => {
|
||||
/* istanbul ignore next */
|
||||
const isEmscripten = () => {
|
||||
const { CC } = process.env;
|
||||
return Boolean(CC && CC.endsWith('/emcc'));
|
||||
return Boolean(CC?.endsWith('/emcc'));
|
||||
};
|
||||
|
||||
const isRosetta = () => {
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const is = require('./is');
|
||||
|
||||
/**
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const path = require('node:path');
|
||||
const is = require('./is');
|
||||
const sharp = require('./sharp');
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const is = require('./is');
|
||||
|
||||
/**
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
// Inspects the runtime environment and exports the relevant sharp.node binary
|
||||
|
||||
const { familySync, versionSync } = require('detect-libc');
|
||||
@ -88,7 +86,7 @@ if (sharp) {
|
||||
` Found ${libcFound}`,
|
||||
` Requires ${libcRequires}`
|
||||
);
|
||||
} catch (errEngines) {}
|
||||
} catch (_errEngines) {}
|
||||
}
|
||||
if (isLinux && /\/snap\/core[0-9]{2}/.test(messages)) {
|
||||
help.push(
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const events = require('node:events');
|
||||
const detectLibc = require('detect-libc');
|
||||
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
// Populate the npm package for the current platform with the local build
|
||||
|
||||
const { copyFileSync, cpSync, readFileSync, writeFileSync, appendFileSync } = require('node:fs');
|
||||
|
||||
@ -97,7 +97,7 @@
|
||||
"test": "npm run lint && npm run test-unit",
|
||||
"lint": "npm run lint-cpp && npm run lint-js && npm run lint-licensing && npm run lint-types",
|
||||
"lint-cpp": "cpplint",
|
||||
"lint-js": "semistandard",
|
||||
"lint-js": "biome lint",
|
||||
"lint-licensing": "license-checker --production --summary --onlyAllow=\"Apache-2.0;BSD;ISC;LGPL-3.0-or-later;MIT\"",
|
||||
"lint-types": "tsd",
|
||||
"test-leak": "./test/leak/leak.sh",
|
||||
@ -168,6 +168,7 @@
|
||||
"@img/sharp-win32-x64": "0.34.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "^2.2.4",
|
||||
"@emnapi/runtime": "^1.5.0",
|
||||
"@img/sharp-libvips-dev": "1.2.3",
|
||||
"@img/sharp-libvips-dev-wasm32": "1.2.3",
|
||||
@ -186,7 +187,6 @@
|
||||
"node-addon-api": "^8.5.0",
|
||||
"node-gyp": "^11.4.2",
|
||||
"nyc": "^17.1.0",
|
||||
"semistandard": "^17.0.0",
|
||||
"tar-fs": "^3.1.1",
|
||||
"tsd": "^0.33.0"
|
||||
},
|
||||
@ -200,11 +200,6 @@
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
},
|
||||
"semistandard": {
|
||||
"env": [
|
||||
"mocha"
|
||||
]
|
||||
},
|
||||
"cc": {
|
||||
"linelength": "120",
|
||||
"filter": [
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const sharp = require('../');
|
||||
|
||||
const usingCache = !process.env.G_DEBUG;
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
process.env.UV_THREADPOOL_SIZE = 64;
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
const async = require('async');
|
||||
|
||||
const sharp = require('../../');
|
||||
@ -21,13 +19,12 @@ const timer = setInterval(function () {
|
||||
}, 100);
|
||||
|
||||
async.mapSeries([1, 1, 2, 4, 8, 16, 32, 64], function (parallelism, next) {
|
||||
const start = new Date().getTime();
|
||||
const start = Date.now();
|
||||
async.times(parallelism,
|
||||
function (id, callback) {
|
||||
/* jslint unused: false */
|
||||
function (_id, callback) {
|
||||
sharp(fixtures.inputJpg).resize(width, height).toBuffer(function (err, buffer) {
|
||||
buffer = null;
|
||||
callback(err, new Date().getTime() - start);
|
||||
callback(err, Date.now() - start);
|
||||
});
|
||||
},
|
||||
function (err, ids) {
|
||||
@ -37,7 +34,7 @@ async.mapSeries([1, 1, 2, 4, 8, 16, 32, 64], function (parallelism, next) {
|
||||
const mean = ids.reduce(function (a, b) {
|
||||
return a + b;
|
||||
}) / ids.length;
|
||||
console.log(parallelism + ' parallel calls: fastest=' + ids[0] + 'ms slowest=' + ids[ids.length - 1] + 'ms mean=' + mean + 'ms');
|
||||
console.log(`${parallelism} parallel calls: fastest=${ids[0]}ms slowest=${ids[ids.length - 1]}ms mean=${mean}ms`);
|
||||
next();
|
||||
}
|
||||
);
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const { execSync } = require('child_process');
|
||||
const fs = require('node:fs');
|
||||
const { execSync } = require('node:child_process');
|
||||
|
||||
const async = require('async');
|
||||
const Benchmark = require('benchmark');
|
||||
@ -12,7 +10,7 @@ const Benchmark = require('benchmark');
|
||||
const safeRequire = (name) => {
|
||||
try {
|
||||
return require(name);
|
||||
} catch (err) {}
|
||||
} catch (_err) {}
|
||||
return null;
|
||||
};
|
||||
|
||||
@ -280,7 +278,7 @@ async.series({
|
||||
});
|
||||
}
|
||||
}).on('cycle', function (event) {
|
||||
console.log('jpeg ' + String(event.target));
|
||||
console.log(`jpeg ${String(event.target)}`);
|
||||
}).on('complete', function () {
|
||||
callback(null, this.filter('fastest').map('name'));
|
||||
}).run();
|
||||
@ -505,7 +503,7 @@ async.series({
|
||||
});
|
||||
}
|
||||
}).on('cycle', function (event) {
|
||||
console.log('operations ' + String(event.target));
|
||||
console.log(`operations ${String(event.target)}`);
|
||||
}).on('complete', function () {
|
||||
callback(null, this.filter('fastest').map('name'));
|
||||
}).run();
|
||||
@ -579,7 +577,7 @@ async.series({
|
||||
});
|
||||
}
|
||||
}).on('cycle', function (event) {
|
||||
console.log('kernels ' + String(event.target));
|
||||
console.log(`kernels ${String(event.target)}`);
|
||||
}).on('complete', function () {
|
||||
callback(null, this.filter('fastest').map('name'));
|
||||
}).run();
|
||||
@ -735,7 +733,7 @@ async.series({
|
||||
sharp(inputPngBuffer)
|
||||
.resize(width, heightPng)
|
||||
.png({ compressionLevel: 6 })
|
||||
.toBuffer(function (err, data) {
|
||||
.toBuffer(function (err) {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -820,7 +818,7 @@ async.series({
|
||||
}
|
||||
});
|
||||
pngSuite.on('cycle', function (event) {
|
||||
console.log(' png ' + String(event.target));
|
||||
console.log(` png ${String(event.target)}`);
|
||||
}).on('complete', function () {
|
||||
callback(null, this.filter('fastest').map('name'));
|
||||
}).run();
|
||||
@ -881,7 +879,7 @@ async.series({
|
||||
});
|
||||
}
|
||||
}).on('cycle', function (event) {
|
||||
console.log('webp ' + String(event.target));
|
||||
console.log(`webp ${String(event.target)}`);
|
||||
}).on('complete', function () {
|
||||
callback(null, this.filter('fastest').map('name'));
|
||||
}).run();
|
||||
@ -892,7 +890,7 @@ async.series({
|
||||
}
|
||||
Object.keys(results).forEach(function (format) {
|
||||
if (results[format].toString().substr(0, 5) !== 'sharp') {
|
||||
console.log('sharp was slower than ' + results[format] + ' for ' + format);
|
||||
console.log(`sharp was slower than ${results[format]} for ${format}`);
|
||||
}
|
||||
});
|
||||
console.dir(sharp.cache());
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const imagemagick = require('imagemagick');
|
||||
const gm = require('gm');
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
const Benchmark = require('benchmark');
|
||||
|
||||
const sharp = require('../../');
|
||||
@ -73,5 +71,5 @@ new Benchmark.Suite('random').add('imagemagick', {
|
||||
console.log(String(event.target));
|
||||
}).on('complete', function () {
|
||||
const winner = this.filter('fastest').map('name');
|
||||
assert.strictEqual('sharp', String(winner), 'sharp was slower than ' + winner);
|
||||
assert.strictEqual('sharp', String(winner), `sharp was slower than ${winner}`);
|
||||
}).run();
|
||||
|
||||
10
test/fixtures/index.js
vendored
10
test/fixtures/index.js
vendored
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const path = require('node:path');
|
||||
const sharp = require('../../');
|
||||
const maxColourDistance = require('../../lib/sharp')._maxColourDistance;
|
||||
|
||||
@ -196,10 +194,10 @@ module.exports = {
|
||||
|
||||
assertMaxColourDistance: function (actualImagePath, expectedImagePath, acceptedDistance) {
|
||||
if (typeof actualImagePath !== 'string') {
|
||||
throw new TypeError('`actualImagePath` must be a string; got ' + actualImagePath);
|
||||
throw new TypeError(`\`actualImagePath\` must be a string; got ${actualImagePath}`);
|
||||
}
|
||||
if (typeof expectedImagePath !== 'string') {
|
||||
throw new TypeError('`expectedImagePath` must be a string; got ' + expectedImagePath);
|
||||
throw new TypeError(`\`expectedImagePath\` must be a string; got ${expectedImagePath}`);
|
||||
}
|
||||
if (typeof acceptedDistance !== 'number') {
|
||||
// Default threshold
|
||||
@ -207,7 +205,7 @@ module.exports = {
|
||||
}
|
||||
const distance = maxColourDistance(actualImagePath, expectedImagePath);
|
||||
if (distance > acceptedDistance) {
|
||||
throw new Error('Expected maximum absolute distance of ' + acceptedDistance + ', actual ' + distance);
|
||||
throw new Error(`Expected maximum absolute distance of ${acceptedDistance}, actual ${distance}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
// biome-ignore-all lint/correctness/noUnusedFunctionParameters: types only test file
|
||||
// biome-ignore-all lint/correctness/noUnusedVariables: types only test file
|
||||
|
||||
import sharp = require('../../');
|
||||
|
||||
import { createReadStream, createWriteStream } from 'fs';
|
||||
import { createReadStream, createWriteStream } from 'node:fs';
|
||||
|
||||
const input: Buffer = Buffer.alloc(0);
|
||||
const readableStream: NodeJS.ReadableStream = createReadStream(input);
|
||||
@ -79,7 +82,7 @@ sharp({
|
||||
let transformer = sharp()
|
||||
.resize(300)
|
||||
.on('info', (info: sharp.OutputInfo) => {
|
||||
console.log('Image height is ' + info.height);
|
||||
console.log(`Image height is ${info.height}`);
|
||||
});
|
||||
readableStream.pipe(transformer).pipe(writableStream);
|
||||
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
const fixtures = require('../fixtures');
|
||||
const sharp = require('../../');
|
||||
|
||||
@ -67,7 +65,7 @@ describe('Alpha transparency', function () {
|
||||
it('Do not flatten', function (done) {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.flatten(false)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer(function (err, _data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(4, info.channels);
|
||||
@ -78,7 +76,7 @@ describe('Alpha transparency', function () {
|
||||
it('Ignored for JPEG', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.flatten({ background: '#ff0000' })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer(function (err, _data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(3, info.channels);
|
||||
@ -100,7 +98,7 @@ describe('Alpha transparency', function () {
|
||||
|
||||
it('Enlargement with non-nearest neighbor interpolation shouldn’t cause dark edges', function () {
|
||||
const base = 'alpha-premultiply-enlargement-2048x1536-paper.png';
|
||||
const actual = fixtures.path('output.' + base);
|
||||
const actual = fixtures.path(`output.${base}`);
|
||||
const expected = fixtures.expected(base);
|
||||
return sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
||||
.resize(2048, 1536)
|
||||
@ -112,7 +110,7 @@ describe('Alpha transparency', function () {
|
||||
|
||||
it('Reduction with non-nearest neighbor interpolation shouldn’t cause dark edges', function () {
|
||||
const base = 'alpha-premultiply-reduction-1024x768-paper.png';
|
||||
const actual = fixtures.path('output.' + base);
|
||||
const actual = fixtures.path(`output.${base}`);
|
||||
const expected = fixtures.expected(base);
|
||||
return sharp(fixtures.inputPngAlphaPremultiplicationLarge)
|
||||
.resize(1024, 768)
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const { inputAvif, inputJpg, inputGifAnimated } = require('../fixtures');
|
||||
@ -20,8 +18,8 @@ describe('AVIF', () => {
|
||||
.resize(32)
|
||||
.jpeg()
|
||||
.toBuffer();
|
||||
const { size, ...metadata } = await sharp(data)
|
||||
.metadata();
|
||||
const { size, ...metadata } = await sharp(data).metadata();
|
||||
void size;
|
||||
assert.deepStrictEqual(metadata, {
|
||||
autoOrient: {
|
||||
height: 13,
|
||||
@ -49,8 +47,8 @@ describe('AVIF', () => {
|
||||
.resize(32)
|
||||
.avif({ effort: 0 })
|
||||
.toBuffer();
|
||||
const { size, ...metadata } = await sharp(data)
|
||||
.metadata();
|
||||
const { size, ...metadata } = await sharp(data).metadata();
|
||||
void size;
|
||||
assert.deepStrictEqual(metadata, {
|
||||
autoOrient: {
|
||||
height: 26,
|
||||
@ -77,8 +75,8 @@ describe('AVIF', () => {
|
||||
const data = await sharp(inputAvif)
|
||||
.resize(32)
|
||||
.toBuffer();
|
||||
const { size, ...metadata } = await sharp(data)
|
||||
.metadata();
|
||||
const { size, ...metadata } = await sharp(data).metadata();
|
||||
void size;
|
||||
assert.deepStrictEqual(metadata, {
|
||||
autoOrient: {
|
||||
height: 13,
|
||||
@ -106,8 +104,8 @@ describe('AVIF', () => {
|
||||
.resize(10)
|
||||
.avif({ effort: 0 })
|
||||
.toBuffer();
|
||||
const { size, ...metadata } = await sharp(data)
|
||||
.metadata();
|
||||
const { size, ...metadata } = await sharp(data).metadata();
|
||||
void size;
|
||||
assert.deepStrictEqual(metadata, {
|
||||
autoOrient: {
|
||||
height: 300,
|
||||
@ -136,8 +134,8 @@ describe('AVIF', () => {
|
||||
.sharpen()
|
||||
.avif({ effort: 0 })
|
||||
.toBuffer();
|
||||
const { size, ...metadata } = await sharp(data)
|
||||
.metadata();
|
||||
const { size, ...metadata } = await sharp(data).metadata();
|
||||
void size;
|
||||
assert.deepStrictEqual(metadata, {
|
||||
autoOrient: {
|
||||
height: 26,
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
const fixtures = require('../fixtures');
|
||||
const sharp = require('../../');
|
||||
|
||||
@ -14,7 +12,7 @@ describe('Bandbool per-channel boolean operations', function () {
|
||||
sharp.bool.eor
|
||||
]
|
||||
.forEach(function (op) {
|
||||
it(op + ' operation', function (done) {
|
||||
it(`${op} operation`, function (done) {
|
||||
sharp(fixtures.inputPngBooleanNoAlpha)
|
||||
.bandbool(op)
|
||||
.toColourspace('b-w')
|
||||
@ -23,7 +21,7 @@ describe('Bandbool per-channel boolean operations', function () {
|
||||
assert.strictEqual(200, info.width);
|
||||
assert.strictEqual(200, info.height);
|
||||
assert.strictEqual(1, info.channels);
|
||||
fixtures.assertSimilar(fixtures.expected('bandbool_' + op + '_result.png'), data, done);
|
||||
fixtures.assertSimilar(fixtures.expected(`bandbool_${op}_result.png`), data, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -31,7 +29,7 @@ describe('Bandbool per-channel boolean operations', function () {
|
||||
it('sRGB image retains 3 channels', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.bandbool('and')
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer(function (err, _data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(3, info.channels);
|
||||
done();
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const assert = require('assert');
|
||||
const fs = require('node:fs');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const fixtures = require('../fixtures');
|
||||
const sharp = require('../../');
|
||||
@ -18,7 +16,7 @@ describe('Boolean operation between two images', function () {
|
||||
sharp.bool.eor
|
||||
]
|
||||
.forEach(function (op) {
|
||||
it(op + ' operation, file', function (done) {
|
||||
it(`${op} operation, file`, function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.boolean(fixtures.inputJpgBooleanTest, op)
|
||||
@ -26,11 +24,11 @@ describe('Boolean operation between two images', function () {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('boolean_' + op + '_result.jpg'), data, done);
|
||||
fixtures.assertSimilar(fixtures.expected(`boolean_${op}_result.jpg`), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it(op + ' operation, buffer', function (done) {
|
||||
it(`${op} operation, buffer`, function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.boolean(inputJpgBooleanTestBuffer, op)
|
||||
@ -38,11 +36,11 @@ describe('Boolean operation between two images', function () {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('boolean_' + op + '_result.jpg'), data, done);
|
||||
fixtures.assertSimilar(fixtures.expected(`boolean_${op}_result.jpg`), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it(op + ' operation, raw', function (done) {
|
||||
it(`${op} operation, raw`, function (done) {
|
||||
sharp(fixtures.inputJpgBooleanTest)
|
||||
.raw()
|
||||
.toBuffer(function (err, data, info) {
|
||||
@ -54,7 +52,7 @@ describe('Boolean operation between two images', function () {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('boolean_' + op + '_result.jpg'), data, done);
|
||||
fixtures.assertSimilar(fixtures.expected(`boolean_${op}_result.jpg`), data, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../lib');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const assert = require('assert');
|
||||
const fs = require('node:fs');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const fixtures = require('../fixtures');
|
||||
const sharp = require('../../');
|
||||
@ -322,7 +320,7 @@ describe('composite', () => {
|
||||
describe('string gravity', () => {
|
||||
Object.keys(sharp.gravity).forEach(gravity => {
|
||||
it(gravity, done => {
|
||||
const expected = fixtures.expected('overlay-gravity-' + gravity + '.jpg');
|
||||
const expected = fixtures.expected(`overlay-gravity-${gravity}.jpg`);
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(80)
|
||||
.composite([{
|
||||
@ -344,7 +342,7 @@ describe('composite', () => {
|
||||
describe('tile and gravity', () => {
|
||||
Object.keys(sharp.gravity).forEach(gravity => {
|
||||
it(gravity, done => {
|
||||
const expected = fixtures.expected('overlay-tile-gravity-' + gravity + '.jpg');
|
||||
const expected = fixtures.expected(`overlay-tile-gravity-${gravity}.jpg`);
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(80)
|
||||
.composite([{
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const assert = require('node:assert');
|
||||
const fs = require('node:fs');
|
||||
|
||||
const sharp = require('../../lib');
|
||||
const fixtures = require('../fixtures');
|
||||
@ -32,7 +30,7 @@ describe('failOn', () => {
|
||||
isWarningEmitted = true;
|
||||
})
|
||||
.resize(32, 24)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer(function (err, _data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, isWarningEmitted);
|
||||
assert.strictEqual('png', info.format);
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Test fixtures', function () {
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const assert = require('assert');
|
||||
const fs = require('node:fs');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const assert = require('assert');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
@ -388,9 +386,8 @@ describe('Input/output', function () {
|
||||
});
|
||||
|
||||
it('Fail when output File is input File via Promise', function (done) {
|
||||
sharp(fixtures.inputJpg).toFile(fixtures.inputJpg).then(function (data) {
|
||||
assert(false);
|
||||
done();
|
||||
sharp(fixtures.inputJpg).toFile(fixtures.inputJpg).then(function () {
|
||||
done(new Error('Unexpectedly resolved Promise'));
|
||||
}).catch(function (err) {
|
||||
assert(err instanceof Error);
|
||||
assert.strictEqual('Cannot use same file for input and output', err.message);
|
||||
@ -409,9 +406,8 @@ describe('Input/output', function () {
|
||||
|
||||
it('Fail when output File is input File via Promise (relative output, absolute input)', function (done) {
|
||||
const relativePath = path.relative(process.cwd(), fixtures.inputJpg);
|
||||
sharp(fixtures.inputJpg).toFile(relativePath).then(function (data) {
|
||||
assert(false);
|
||||
done();
|
||||
sharp(fixtures.inputJpg).toFile(relativePath).then(function () {
|
||||
done(new Error('Unexpectedly resolved Promise'));
|
||||
}).catch(function (err) {
|
||||
assert(err instanceof Error);
|
||||
assert.strictEqual('Cannot use same file for input and output', err.message);
|
||||
@ -430,9 +426,8 @@ describe('Input/output', function () {
|
||||
|
||||
it('Fail when output File is input File via Promise (relative input, absolute output)', function (done) {
|
||||
const relativePath = path.relative(process.cwd(), fixtures.inputJpg);
|
||||
sharp(relativePath).toFile(fixtures.inputJpg).then(function (data) {
|
||||
assert(false);
|
||||
done();
|
||||
sharp(relativePath).toFile(fixtures.inputJpg).then(function () {
|
||||
done(new Error('Unexpectedly resolved Promise'));
|
||||
}).catch(function (err) {
|
||||
assert(err instanceof Error);
|
||||
assert.strictEqual('Cannot use same file for input and output', err.message);
|
||||
@ -449,9 +444,8 @@ describe('Input/output', function () {
|
||||
});
|
||||
|
||||
it('Fail when output File is empty via Promise', function (done) {
|
||||
sharp(fixtures.inputJpg).toFile('').then(function (data) {
|
||||
assert(false);
|
||||
done();
|
||||
sharp(fixtures.inputJpg).toFile('').then(function () {
|
||||
done(new Error('Unexpectedly resolved Promise'));
|
||||
}).catch(function (err) {
|
||||
assert(err instanceof Error);
|
||||
assert.strictEqual('Missing output file path', err.message);
|
||||
@ -522,7 +516,7 @@ describe('Input/output', function () {
|
||||
try {
|
||||
sharp().toFormat('zoinks');
|
||||
isValid = true;
|
||||
} catch (e) {}
|
||||
} catch (_err) {}
|
||||
assert(!isValid);
|
||||
done();
|
||||
});
|
||||
@ -633,7 +627,7 @@ describe('Input/output', function () {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.png({ compressionLevel: 1, force: false })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer(function (err, _data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -1059,7 +1053,7 @@ describe('Input/output', function () {
|
||||
});
|
||||
const badPipeline = sharp({ raw: { width: 840, height: 500, channels: 3 } })
|
||||
.toFormat('jpeg')
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer(function (err) {
|
||||
assert.strictEqual(err.message.indexOf('memory area too small') > 0, true);
|
||||
const readable = fs.createReadStream(fixtures.inputJPGBig);
|
||||
const inPipeline = sharp()
|
||||
@ -1067,10 +1061,7 @@ describe('Input/output', function () {
|
||||
.raw();
|
||||
const goodPipeline = sharp({ raw: { width: 840, height: 472, channels: 3 } })
|
||||
.toFormat('jpeg')
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
done();
|
||||
});
|
||||
.toBuffer(done);
|
||||
readable.pipe(inPipeline).pipe(goodPipeline);
|
||||
});
|
||||
readable.pipe(inPipeline).pipe(badPipeline);
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const assert = require('node:assert');
|
||||
const fs = require('node:fs');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const assert = require('assert');
|
||||
const fs = require('node:fs');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const assert = require('node:assert');
|
||||
const fs = require('node:fs');
|
||||
const semver = require('semver');
|
||||
const libvips = require('../../lib/libvips');
|
||||
|
||||
|
||||
@ -1,12 +1,10 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
describe('Linear adjustment', function () {
|
||||
const blackPoint = 70;
|
||||
@ -17,7 +15,7 @@ describe('Linear adjustment', function () {
|
||||
it('applies linear levels adjustment w/o alpha ch', function (done) {
|
||||
sharp(fixtures.inputJpgWithLowContrast)
|
||||
.linear(a, b)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer(function (err, data) {
|
||||
if (err) throw err;
|
||||
fixtures.assertSimilar(fixtures.expected('low-contrast-linear.jpg'), data, done);
|
||||
});
|
||||
@ -26,7 +24,7 @@ describe('Linear adjustment', function () {
|
||||
it('applies slope level adjustment w/o alpha ch', function (done) {
|
||||
sharp(fixtures.inputJpgWithLowContrast)
|
||||
.linear(a)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer(function (err, data) {
|
||||
if (err) throw err;
|
||||
fixtures.assertSimilar(fixtures.expected('low-contrast-slope.jpg'), data, done);
|
||||
});
|
||||
@ -35,7 +33,7 @@ describe('Linear adjustment', function () {
|
||||
it('applies offset level adjustment w/o alpha ch', function (done) {
|
||||
sharp(fixtures.inputJpgWithLowContrast)
|
||||
.linear(null, b)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer(function (err, data) {
|
||||
if (err) throw err;
|
||||
fixtures.assertSimilar(fixtures.expected('low-contrast-offset.jpg'), data, done);
|
||||
});
|
||||
@ -83,7 +81,7 @@ describe('Linear adjustment', function () {
|
||||
|
||||
it('per channel level adjustment', function (done) {
|
||||
sharp(fixtures.inputWebP)
|
||||
.linear([0.25, 0.5, 0.75], [150, 100, 50]).toBuffer(function (err, data, info) {
|
||||
.linear([0.25, 0.5, 0.75], [150, 100, 50]).toBuffer(function (err, data) {
|
||||
if (err) throw err;
|
||||
fixtures.assertSimilar(fixtures.expected('linear-per-channel.jpg'), data, done);
|
||||
});
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const assert = require('assert');
|
||||
const fs = require('node:fs');
|
||||
const assert = require('node:assert');
|
||||
const exifReader = require('exif-reader');
|
||||
const icc = require('icc');
|
||||
|
||||
@ -756,7 +754,7 @@ describe('Image metadata', function () {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(64)
|
||||
.withIccProfile(fixtures.path('hilutite.icm'))
|
||||
.toFile(output, function (err, info) {
|
||||
.toFile(output, function (err) {
|
||||
if (err) throw err;
|
||||
fixtures.assertMaxColourDistance(output, fixtures.expected('hilutite.jpg'), 9);
|
||||
done();
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const sharp = require('../../');
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Modulate', function () {
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
@ -104,7 +102,7 @@ describe('Negate', function () {
|
||||
const output = fixtures.path('output.unmodified-by-negate.png');
|
||||
sharp(fixtures.inputJpgWithLowContrast)
|
||||
.negate(false)
|
||||
.toFile(output, function (err, info) {
|
||||
.toFile(output, function (err) {
|
||||
if (err) throw err;
|
||||
fixtures.assertMaxColourDistance(output, fixtures.inputJpgWithLowContrast, 0);
|
||||
done();
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
@ -24,7 +22,7 @@ describe('Normalization', function () {
|
||||
sharp(fixtures.inputJpgWithLowContrast)
|
||||
.normalise()
|
||||
.raw()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer(function (err, data) {
|
||||
if (err) throw err;
|
||||
assertNormalized(data);
|
||||
done();
|
||||
@ -36,7 +34,7 @@ describe('Normalization', function () {
|
||||
.greyscale()
|
||||
.normalize()
|
||||
.raw()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer(function (err, data) {
|
||||
if (err) throw err;
|
||||
assertNormalized(data);
|
||||
done();
|
||||
@ -47,7 +45,7 @@ describe('Normalization', function () {
|
||||
sharp(fixtures.inputPngWithGreyAlpha)
|
||||
.normalise()
|
||||
.raw()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer(function (err, data) {
|
||||
if (err) throw err;
|
||||
assertNormalized(data);
|
||||
done();
|
||||
@ -90,7 +88,7 @@ describe('Normalization', function () {
|
||||
const output = fixtures.path('output.unmodified-png-with-one-color.png');
|
||||
sharp(fixtures.inputPngWithOneColor)
|
||||
.normalize()
|
||||
.toFile(output, function (err, info) {
|
||||
.toFile(output, function (err) {
|
||||
if (err) done(err);
|
||||
fixtures.assertMaxColourDistance(output, fixtures.inputPngWithOneColor, 0);
|
||||
done();
|
||||
@ -101,7 +99,7 @@ describe('Normalization', function () {
|
||||
sharp(fixtures.inputPngWithTransparency16bit)
|
||||
.normalise()
|
||||
.raw()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer(function (err, data) {
|
||||
if (err) throw err;
|
||||
assertNormalized(data);
|
||||
done();
|
||||
@ -112,7 +110,7 @@ describe('Normalization', function () {
|
||||
sharp(fixtures.inputJpgWithLowContrast)
|
||||
.normalise({ lower: 10, upper: 70 })
|
||||
.raw()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer(function (err, data) {
|
||||
if (err) throw err;
|
||||
assertNormalized(data);
|
||||
done();
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const assert = require('assert');
|
||||
const fs = require('node:fs');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
@ -137,6 +135,7 @@ describe('PNG', function () {
|
||||
.toBuffer();
|
||||
|
||||
const { size, ...metadata } = await sharp(data).metadata();
|
||||
void size;
|
||||
assert.deepStrictEqual(metadata, {
|
||||
autoOrient: {
|
||||
height: 68,
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
@ -200,7 +198,7 @@ describe('Raw pixel data', function () {
|
||||
});
|
||||
writable
|
||||
.jpeg()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer(function (err, _data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(32, info.width);
|
||||
@ -285,20 +283,20 @@ describe('Raw pixel data', function () {
|
||||
});
|
||||
});
|
||||
|
||||
for (const { constructor, depth, bits } of [
|
||||
{ constructor: Uint8Array, depth: undefined, bits: 8 },
|
||||
{ constructor: Uint8Array, depth: 'uchar', bits: 8 },
|
||||
{ constructor: Uint8ClampedArray, depth: 'uchar', bits: 8 },
|
||||
{ constructor: Int8Array, depth: 'char', bits: 8 },
|
||||
{ constructor: Uint16Array, depth: 'ushort', bits: 16 },
|
||||
{ constructor: Int16Array, depth: 'short', bits: 16 },
|
||||
{ constructor: Uint32Array, depth: 'uint', bits: 32 },
|
||||
{ constructor: Int32Array, depth: 'int', bits: 32 },
|
||||
{ constructor: Float32Array, depth: 'float', bits: 32 },
|
||||
{ constructor: Float64Array, depth: 'double', bits: 64 }
|
||||
for (const { type, depth, bits } of [
|
||||
{ type: Uint8Array, depth: undefined, bits: 8 },
|
||||
{ type: Uint8Array, depth: 'uchar', bits: 8 },
|
||||
{ type: Uint8ClampedArray, depth: 'uchar', bits: 8 },
|
||||
{ type: Int8Array, depth: 'char', bits: 8 },
|
||||
{ type: Uint16Array, depth: 'ushort', bits: 16 },
|
||||
{ type: Int16Array, depth: 'short', bits: 16 },
|
||||
{ type: Uint32Array, depth: 'uint', bits: 32 },
|
||||
{ type: Int32Array, depth: 'int', bits: 32 },
|
||||
{ type: Float32Array, depth: 'float', bits: 32 },
|
||||
{ type: Float64Array, depth: 'double', bits: 64 }
|
||||
]) {
|
||||
it(constructor.name, () =>
|
||||
sharp(new constructor(3), { raw: { width: 1, height: 1, channels: 3 } })
|
||||
it(type.name, () =>
|
||||
sharp(new type(3), { raw: { width: 1, height: 1, channels: 3 } })
|
||||
.raw({ depth })
|
||||
.toBuffer({ resolveWithObject: true })
|
||||
.then(({ data, info }) => {
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
@ -129,7 +127,7 @@ describe('Resize dimensions', function () {
|
||||
.resize(0x4000, 0x4000)
|
||||
.extract({ top: 0x2000, left: 0x2000, width: 256, height: 256 })
|
||||
.webp()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer(function (err, _data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('webp', info.format);
|
||||
assert.strictEqual(256, info.width);
|
||||
@ -149,7 +147,7 @@ describe('Resize dimensions', function () {
|
||||
assert.strictEqual(607, info.height);
|
||||
sharp(data)
|
||||
.resize(233, 131)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer(function (err, _data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('webp', info.format);
|
||||
assert.strictEqual(233, info.width);
|
||||
@ -169,7 +167,7 @@ describe('Resize dimensions', function () {
|
||||
sharp(data)
|
||||
.rotate(90)
|
||||
.resize(533, 800)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer(function (err, _data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(533, info.width);
|
||||
assert.strictEqual(800, info.height);
|
||||
@ -660,7 +658,7 @@ describe('Resize dimensions', function () {
|
||||
sharp(fixtures.inputTiff8BitDepth)
|
||||
.resize(210, 210, { kernel: 'nearest' })
|
||||
.png()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer(function (err, _data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(210, info.width);
|
||||
assert.strictEqual(210, info.height);
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
@ -173,8 +171,8 @@ describe('Rotation', function () {
|
||||
});
|
||||
|
||||
[-3690, -450, -90, 90, 450, 3690].forEach(function (angle) {
|
||||
it('Rotate by any 90-multiple angle (' + angle + 'deg)', function (done) {
|
||||
sharp(fixtures.inputJpg320x240).rotate(angle).toBuffer(function (err, data, info) {
|
||||
it(`Rotate by any 90-multiple angle (${angle}deg)`, function (done) {
|
||||
sharp(fixtures.inputJpg320x240).rotate(angle).toBuffer(function (err, _data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(240, info.width);
|
||||
assert.strictEqual(320, info.height);
|
||||
@ -184,8 +182,8 @@ describe('Rotation', function () {
|
||||
});
|
||||
|
||||
[-3750, -510, -150, 30, 390, 3630].forEach(function (angle) {
|
||||
it('Rotate by any 30-multiple angle (' + angle + 'deg)', function (done) {
|
||||
sharp(fixtures.inputJpg320x240).rotate(angle).toBuffer(function (err, data, info) {
|
||||
it(`Rotate by any 30-multiple angle (${angle}deg)`, function (done) {
|
||||
sharp(fixtures.inputJpg320x240).rotate(angle).toBuffer(function (err, _data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(397, info.width);
|
||||
assert.strictEqual(368, info.height);
|
||||
@ -195,8 +193,8 @@ describe('Rotation', function () {
|
||||
});
|
||||
|
||||
[-3780, -540, 0, 180, 540, 3780].forEach(function (angle) {
|
||||
it('Rotate by any 180-multiple angle (' + angle + 'deg)', function (done) {
|
||||
sharp(fixtures.inputJpg320x240).rotate(angle).toBuffer(function (err, data, info) {
|
||||
it(`Rotate by any 180-multiple angle (${angle}deg)`, function (done) {
|
||||
sharp(fixtures.inputJpg320x240).rotate(angle).toBuffer(function (err, _data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -446,7 +444,7 @@ describe('Rotation', function () {
|
||||
sharp(fixtures.inputJpg)
|
||||
.rotate(45)
|
||||
.rotate(90)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer(function (err, _data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(2225, info.width);
|
||||
assert.strictEqual(2725, info.height);
|
||||
@ -458,7 +456,7 @@ describe('Rotation', function () {
|
||||
sharp(fixtures.inputJpg)
|
||||
.rotate(90)
|
||||
.rotate(45)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer(function (err, _data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(3500, info.width);
|
||||
assert.strictEqual(3500, info.height);
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const assert = require('assert');
|
||||
const fs = require('node:fs');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
@ -711,7 +709,7 @@ describe('Image Stats', function () {
|
||||
|
||||
it('File input with corrupt header fails gracefully, Promise out', function () {
|
||||
return sharp(fixtures.inputJpgWithCorruptHeader)
|
||||
.stats().then(function (stats) {
|
||||
.stats().then(function () {
|
||||
throw new Error('Corrupt Header file');
|
||||
}).catch(function (err) {
|
||||
assert.ok(!!err);
|
||||
@ -724,7 +722,7 @@ describe('Image Stats', function () {
|
||||
fs.createReadStream(fixtures.inputJpgWithCorruptHeader).pipe(pipeline);
|
||||
|
||||
return pipeline
|
||||
.stats().then(function (stats) {
|
||||
.stats().then(function () {
|
||||
throw new Error('Corrupt Header file');
|
||||
}).catch(function (err) {
|
||||
assert.ok(!!err);
|
||||
@ -740,7 +738,7 @@ describe('Image Stats', function () {
|
||||
});
|
||||
|
||||
it('Non-existent file in, Promise out', function (done) {
|
||||
sharp('fail').stats().then(function (stats) {
|
||||
sharp('fail').stats().then(function () {
|
||||
throw new Error('Non-existent file');
|
||||
}, function (err) {
|
||||
assert.ok(!!err);
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const assert = require('assert');
|
||||
const fs = require('node:fs');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
@ -64,7 +62,7 @@ describe('Threshold', function () {
|
||||
it('threshold false (=0)', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.threshold(false)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer(function (err, data) {
|
||||
if (err) throw err;
|
||||
fixtures.assertSimilar(fixtures.inputJpg, data, done);
|
||||
});
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const assert = require('assert');
|
||||
const fs = require('node:fs');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const assert = require('assert');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const extractZip = require('extract-zip');
|
||||
|
||||
@ -47,7 +45,7 @@ const assertDeepZoomTiles = function (directory, expectedSize, expectedLevels, d
|
||||
.catch(done);
|
||||
};
|
||||
|
||||
const assertZoomifyTiles = function (directory, expectedTileSize, expectedLevels, done) {
|
||||
const assertZoomifyTiles = function (directory, expectedLevels, done) {
|
||||
fs.stat(path.join(directory, 'ImageProperties.xml'), function (err, stat) {
|
||||
if (err) throw err;
|
||||
assert.ok(stat.isFile());
|
||||
@ -57,7 +55,7 @@ const assertZoomifyTiles = function (directory, expectedTileSize, expectedLevels
|
||||
fs.readdirSync(path.join(directory, 'TileGroup0')).forEach(function (tile) {
|
||||
// Verify tile file name
|
||||
assert.ok(/^[0-9]+-[0-9]+-[0-9]+\.jpg$/.test(tile));
|
||||
const level = parseInt(tile.split('-')[0]);
|
||||
const level = Number(tile.split('-')[0]);
|
||||
maxTileLevel = Math.max(maxTileLevel, level);
|
||||
});
|
||||
|
||||
@ -67,7 +65,7 @@ const assertZoomifyTiles = function (directory, expectedTileSize, expectedLevels
|
||||
});
|
||||
};
|
||||
|
||||
const assertGoogleTiles = function (directory, expectedTileSize, expectedLevels, done) {
|
||||
const assertGoogleTiles = function (directory, expectedLevels, done) {
|
||||
// Get levels
|
||||
const dirents = fs.readdirSync(directory, { withFileTypes: true });
|
||||
const levels = dirents.filter(dirent => dirent.isDirectory()).map(dirent => dirent.name);
|
||||
@ -411,7 +409,7 @@ describe('Tile', function () {
|
||||
size: 512,
|
||||
depth: 'one'
|
||||
})
|
||||
.toFile(fixtures.path('output.512_depth_one.dzi'), function (err, info) {
|
||||
.toFile(fixtures.path('output.512_depth_one.dzi'), function (err) {
|
||||
if (err) throw err;
|
||||
// Verify only one depth generated
|
||||
assertDeepZoomTiles(directory, 512, 1, done);
|
||||
@ -427,7 +425,7 @@ describe('Tile', function () {
|
||||
size: 512,
|
||||
depth: 'onepixel'
|
||||
})
|
||||
.toFile(fixtures.path('output.512_depth_onepixel.dzi'), function (err, info) {
|
||||
.toFile(fixtures.path('output.512_depth_onepixel.dzi'), function (err) {
|
||||
if (err) throw err;
|
||||
// Verify only one depth generated
|
||||
assertDeepZoomTiles(directory, 512, 13, done);
|
||||
@ -443,7 +441,7 @@ describe('Tile', function () {
|
||||
size: 256,
|
||||
depth: 'onetile'
|
||||
})
|
||||
.toFile(fixtures.path('output.256_depth_onetile.dzi'), function (err, info) {
|
||||
.toFile(fixtures.path('output.256_depth_onetile.dzi'), function (err) {
|
||||
if (err) throw err;
|
||||
// Verify only one depth generated
|
||||
assertDeepZoomTiles(directory, 256, 5, done);
|
||||
@ -459,7 +457,7 @@ describe('Tile', function () {
|
||||
size: 256,
|
||||
skipBlanks: 0
|
||||
})
|
||||
.toFile(fixtures.path('output.256_skip_blanks.dzi'), function (err, info) {
|
||||
.toFile(fixtures.path('output.256_skip_blanks.dzi'), function (err) {
|
||||
if (err) throw err;
|
||||
// assert them 0_0.jpeg doesn't exist because it's a white tile
|
||||
const whiteTilePath = path.join(directory, '11', '0_0.jpeg');
|
||||
@ -510,7 +508,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(2225, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual(undefined, info.size);
|
||||
assertZoomifyTiles(directory, 256, 1, done);
|
||||
assertZoomifyTiles(directory, 1, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -531,7 +529,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(2225, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual(undefined, info.size);
|
||||
assertZoomifyTiles(directory, 256, 5, done);
|
||||
assertZoomifyTiles(directory, 5, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -552,7 +550,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(2225, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual(undefined, info.size);
|
||||
assertZoomifyTiles(directory, 256, 13, done);
|
||||
assertZoomifyTiles(directory, 13, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -576,7 +574,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(1536, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual(undefined, info.size);
|
||||
assertZoomifyTiles(directory, 256, 4, done);
|
||||
assertZoomifyTiles(directory, 4, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -733,7 +731,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(2225, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual(undefined, info.size);
|
||||
assertGoogleTiles(directory, 256, 1, done);
|
||||
assertGoogleTiles(directory, 1, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -754,7 +752,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(2225, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual(undefined, info.size);
|
||||
assertGoogleTiles(directory, 256, 5, done);
|
||||
assertGoogleTiles(directory, 5, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -778,7 +776,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(2074, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual(undefined, info.size);
|
||||
assertGoogleTiles(directory, 256, 5, done);
|
||||
assertGoogleTiles(directory, 5, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const inRange = require('../../lib/is').inRange;
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('node:assert');
|
||||
const semver = require('semver');
|
||||
const sharp = require('../../');
|
||||
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const assert = require('assert');
|
||||
const fs = require('node:fs');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user