Skip to content

Commit

Permalink
Use native methods instead of Lodash
Browse files Browse the repository at this point in the history
  • Loading branch information
hagopj13 committed Jun 21, 2020
1 parent 4b48eb4 commit 66c9e33
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
"helmet": "^3.21.2",
"http-status": "^1.4.0",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.15",
"moment": "^2.24.0",
"mongoose": "^5.7.7",
"morgan": "^1.9.1",
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/user.controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const httpStatus = require('http-status');
const { pick } = require('lodash');
const pick = require('../utils/pick');
const ApiError = require('../utils/ApiError');
const catchAsync = require('../utils/catchAsync');
const { userService } = require('../services');
Expand Down
2 changes: 1 addition & 1 deletion src/middlewares/validate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Joi = require('@hapi/joi');
const httpStatus = require('http-status');
const { pick } = require('lodash');
const pick = require('../utils/pick');
const ApiError = require('../utils/ApiError');

const validate = (schema) => (req, res, next) => {
Expand Down
17 changes: 17 additions & 0 deletions src/utils/pick.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Create an object composed of the picked object properties
* @param {Object} object
* @param {string[]} keys
* @returns {Object}
*/
const pick = (object, keys) => {
return keys.reduce((obj, key) => {
if (object && Object.prototype.hasOwnProperty.call(object, key)) {
// eslint-disable-next-line no-param-reassign
obj[key] = object[key];
}
return obj;
}, {});
};

module.exports = pick;

0 comments on commit 66c9e33

Please sign in to comment.