Skip to content

Commit 8e86267

Browse files
chore: remove extra deps
1 parent ed93f8c commit 8e86267

10 files changed

Lines changed: 29 additions & 214 deletions

File tree

index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
const _ = require('lodash');
43
const colorDiff = require('color-diff');
54
const img = require('./lib/image');
65
const areColorsSame = require('./lib/same-colors');
@@ -122,7 +121,7 @@ const buildDiffImage = async (img1, img2, options) => {
122121
};
123122

124123
const getToleranceFromOpts = (opts) => {
125-
if (!_.hasIn(opts, 'tolerance')) {
124+
if (!Object.hasOwn(opts, 'tolerance')) {
126125
return JND;
127126
}
128127

@@ -137,11 +136,13 @@ const prepareOpts = (opts) => {
137136
opts = opts || {};
138137
opts.tolerance = getToleranceFromOpts(opts);
139138

140-
return _.defaults(opts, {
139+
const defaults = {
141140
ignoreCaret: true,
142141
ignoreAntialiasing: true,
143142
antialiasingTolerance: 0
144-
});
143+
};
144+
145+
return Object.assign(defaults, opts);
145146
};
146147

147148
const getMaxDiffBounds = (first, second) => {

lib/image/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const fs = require('fs-extra');
3+
const fs = require('fs');
44
const NestedError = require('nested-error-stacks');
55
const sharp = require('sharp');
66
const OriginalIMG = require('./original-image');
@@ -19,7 +19,7 @@ exports.fromBuffer = async (buffer, opts) => {
1919

2020
exports.fromFile = async (filePath, opts = {}) => {
2121
try {
22-
const buffer = await fs.readFile(filePath);
22+
const buffer = await fs.promises.readFile(filePath);
2323
return exports.fromBuffer(buffer, opts);
2424
} catch (err) {
2525
throw new NestedError(`Can't load img file ${filePath}`, err);

lib/img-buffer/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

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

1414
exports.fromFile = async (filePath, opts = {}) => {
1515
try {
16-
const buffer = await fs.readFile(filePath);
16+
const buffer = await fs.promises.readFile(filePath);
1717
return exports.create(buffer, opts);
1818
} catch (err) {
1919
throw new NestedError(`Can't load img file ${filePath}`, err);

lib/utils.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
const _ = require('lodash');
43
const parseColor = require('parse-color');
54
const img = require('./image');
65
const buffer = require('./img-buffer');
@@ -88,7 +87,7 @@ exports.formatImages = (img1, img2) => {
8887
validators.validateImages(img1, img2);
8988

9089
return [img1, img2].map((i) => {
91-
return _.isObject(i) && !Buffer.isBuffer(i) ? i : {source: i, boundingBox: null};
90+
return i !== null && typeof i === 'object' && !Buffer.isBuffer(i) ? i : {source: i, boundingBox: null};
9291
});
9392
};
9493

lib/validators.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
'use strict';
22

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

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

2423
exports.validateImages = (img1, img2) => {
2524
[img1, img2].forEach((i) => {
26-
if (Buffer.isBuffer(i) || !_.isObject(i)) {
25+
if (Buffer.isBuffer(i) || i === null || typeof i !== 'object') {
2726
return;
2827
}
2928

0 commit comments

Comments
 (0)