Skip to content

Commit 18e59cb

Browse files
committed
Switch to lodash cloneDeep method
1 parent 82d4e01 commit 18e59cb

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

integration.js

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

3-
let async = require('async');
4-
let config = require('./config/config');
5-
let path = require('path');
6-
let maxmind = require('maxmind');
7-
let ipaddr = require('ipaddr.js');
3+
const async = require('async');
4+
const config = require('./config/config');
5+
const maxmind = require('maxmind');
6+
const ipaddr = require('ipaddr.js');
7+
const cloneDeep = require('lodash.clonedeep');
88

99
let Logger;
1010
let cityLookup = null;
@@ -148,18 +148,6 @@ function _getCountryCode(cityData) {
148148
return 'O1';
149149
}
150150

151-
const cloneDeep = (entity, cache = new WeakMap()) => {
152-
const referenceTypes = ['Array', 'Object'];
153-
const entityType = Object.prototype.toString.call(entity);
154-
if (!new RegExp(referenceTypes.join('|')).test(entityType)) return entity;
155-
if (cache.has(entity)) {
156-
return cache.get(entity);
157-
}
158-
const c = new entity.constructor();
159-
cache.set(entity, c);
160-
return Object.assign(c, ...Object.keys(entity).map((prop) => ({ [prop]: cloneDeep(entity[prop], cache) })));
161-
};
162-
163151
function _lookupIp(entityObj, countryBlacklist, countryWhitelist, options, cb) {
164152
let cityData = cityLookup.getWithRoutingPrefix(entityObj.value);
165153
let asnData = asnLookup.getWithRoutingPrefix(entityObj.value);

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"async": "^3.2.0",
99
"maxmind": "polarityio/node-maxmind.git#master",
1010
"ipaddr.js": "^1.9.1",
11-
"papaparse": "^5.1.1"
11+
"papaparse": "^5.1.1",
12+
"lodash.clonedeep": "^4.5.0"
1213
}
1314
}

0 commit comments

Comments
 (0)