Skip to content
Merged
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
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const _ = require('lodash');
const colorDiff = require('color-diff');
const img = require('./lib/image');
const areColorsSame = require('./lib/same-colors');
Expand Down Expand Up @@ -152,7 +151,7 @@ const buildDiffImage = async (img1, img2, options) => {
};

const getToleranceFromOpts = (opts) => {
if (!_.hasIn(opts, 'tolerance')) {
if (!Object.hasOwn(opts, 'tolerance')) {
return JND;
}

Expand All @@ -167,11 +166,13 @@ const prepareOpts = (opts) => {
opts = opts || {};
opts.tolerance = getToleranceFromOpts(opts);

return _.defaults(opts, {
const defaults = {
ignoreCaret: true,
ignoreAntialiasing: true,
antialiasingTolerance: 0
});
};

return Object.assign(defaults, opts);
};

const getMaxDiffBounds = (first, second) => {
Expand Down
4 changes: 2 additions & 2 deletions lib/img-buffer/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const fs = require('fs-extra');
const fs = require('fs');
const NestedError = require('nested-error-stacks');
const OriginalBuffer = require('./original-buffer');
const BoundedBuffer = require('./bounded-buffer');
Expand All @@ -13,7 +13,7 @@ exports.create = (buffer, {boundingBox} = {}) => {

exports.fromFile = async (filePath, opts = {}) => {
try {
const buffer = await fs.readFile(filePath);
const buffer = await fs.promises.readFile(filePath);
return exports.create(buffer, opts);
} catch (err) {
throw new NestedError(`Can't load img file ${filePath}`, err);
Expand Down
3 changes: 1 addition & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const _ = require('lodash');
const parseColor = require('parse-color');
const img = require('./image');
const buffer = require('./img-buffer');
Expand Down Expand Up @@ -88,7 +87,7 @@ exports.formatImages = (img1, img2) => {
validators.validateImages(img1, img2);

return [img1, img2].map((i) => {
return _.isObject(i) && !Buffer.isBuffer(i) ? i : {source: i, boundingBox: null};
return i !== null && typeof i === 'object' && !Buffer.isBuffer(i) ? i : {source: i, boundingBox: null};
});
};

Expand Down
5 changes: 2 additions & 3 deletions lib/validators.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
'use strict';

const _ = require('lodash');
const {REQUIRED_IMAGE_FIELDS, REQUIRED_BOUNDING_BOX_FIELDS} = require('./constants');

const validateRequiredFields = (value, fields) => {
[].concat(fields).forEach((field) => {
if (!_.hasIn(value, field)) {
if (!value || !Object.hasOwn(value, field)) {
throw new TypeError(`Field "${field}" does not exist in ${JSON.stringify(value)}`);
}
});
Expand All @@ -23,7 +22,7 @@ const validateBoundingBoxCoords = ({boundingBox}) => {

exports.validateImages = (img1, img2) => {
[img1, img2].forEach((i) => {
if (Buffer.isBuffer(i) || !_.isObject(i)) {
if (Buffer.isBuffer(i) || i === null || typeof i !== 'object') {
return;
}

Expand Down
Loading