Skip to content

Commit bc16d94

Browse files
chore: remove extra deps
1 parent ed93f8c commit bc16d94

10 files changed

Lines changed: 29 additions & 95 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

package-lock.json

Lines changed: 8 additions & 72 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
},
1010
"dependencies": {
1111
"color-diff": "^1.1.0",
12-
"fs-extra": "^8.1.0",
1312
"js-graph-algorithms": "1.0.18",
14-
"lodash": "^4.17.3",
1513
"nested-error-stacks": "^2.1.0",
1614
"parse-color": "^1.0.0",
1715
"sharp": "0.32.6"

test/ignore-caret-comparator.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 expect = require('chai').expect;
54
const sinon = require('sinon');
65
const proxyquire = require('proxyquire');
@@ -12,7 +11,7 @@ describe('IgnoreCaretComparator', () => {
1211
let areColorsSame;
1312

1413
const compareImages = (pixels, comparator) => {
15-
const emptyPixels = _.map(pixels, (pixelRow) => Array(pixelRow.length).fill(0));
14+
const emptyPixels = pixels.map(pixelRow => Array(pixelRow.length).fill(0));
1615
const width = pixels[0].length;
1716
const height = pixels.length;
1817

test/png/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const sinon = require('sinon');
44
const proxyquire = require('proxyquire');
5-
const fs = require('fs-extra');
5+
const fs = require('fs');
66

77
const stubBuffer = Buffer.from([123]);
88

@@ -16,7 +16,7 @@ describe('lib/image/index.js', () => {
1616
mkSharpImage_ = sandbox.stub();
1717
image = proxyquire('../../lib/image', {'sharp': mkSharpImage_});
1818

19-
sandbox.stub(fs, 'readFile').resolves(stubBuffer);
19+
sandbox.stub(fs.promises, 'readFile').resolves(stubBuffer);
2020
});
2121

2222
afterEach(() => sandbox.restore());
@@ -30,7 +30,7 @@ describe('lib/image/index.js', () => {
3030

3131
it('should throw error with file path and original error message at stack', async () => {
3232
parseError = new Error('test error');
33-
fs.readFile.withArgs('/filePath').rejects(parseError);
33+
fs.promises.readFile.withArgs('/filePath').rejects(parseError);
3434

3535
const error = await assert.isRejected(image.fromFile('/filePath'));
3636

test/validators.js

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

3-
const _ = require('lodash');
43
const {validateImages} = require('../lib/validators');
54

65
describe('lib/validators', () => {
@@ -27,10 +26,13 @@ describe('lib/validators', () => {
2726

2827
['left', 'top', 'right', 'bottom'].forEach((field) => {
2928
it(`required field "${field}" does not exist in "boundingBox"`, () => {
29+
const boundingBox = {left: 0, top: 0, right: 0, bottom: 0};
30+
delete boundingBox[field];
31+
3032
assert.throws(() => {
3133
return validateImages(
32-
{source: 'image-path', boundingBox: _.omit({left: 0, top: 0, right: 0, bottom: 0}, field)},
33-
{source: 'image-path', boundingBox: _.omit({left: 0, top: 0, right: 0, bottom: 0}, field)}
34+
{source: 'image-path', boundingBox},
35+
{source: 'image-path', boundingBox}
3436
);
3537
}, TypeError, `Field "${field}" does not exist`);
3638
});

0 commit comments

Comments
 (0)