Skip to content

Commit cadb252

Browse files
committed
refactor(lodash): remove lodash
1 parent 5dec5dc commit cadb252

File tree

6 files changed

+22
-17
lines changed

6 files changed

+22
-17
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
"@types/express": "^4.17.3",
5454
"@types/is-glob": "^4.0.1",
5555
"@types/jest": "^26.0.22",
56-
"@types/lodash": "^4.14.168",
5756
"@types/micromatch": "^4.0.1",
5857
"@types/node": "^14.14.37",
5958
"@types/supertest": "^2.0.10",
@@ -79,9 +78,10 @@
7978
},
8079
"dependencies": {
8180
"@types/http-proxy": "^1.17.5",
81+
"camelcase": "^6.2.0",
8282
"http-proxy": "^1.18.1",
8383
"is-glob": "^4.0.1",
84-
"lodash": "^4.17.21",
84+
"is-plain-object": "^5.0.0",
8585
"micromatch": "^4.0.2"
8686
},
8787
"engines": {

src/config-factory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as _ from 'lodash';
1+
import { isPlainObject } from 'is-plain-object';
22
import * as url from 'url';
33
import { ERRORS } from './errors';
44
import { getInstance } from './logger';
@@ -74,7 +74,7 @@ function isStringShortHand(context: Filter) {
7474
* @return {Boolean} [description]
7575
*/
7676
function isContextless(context: Filter, opts: Options) {
77-
return _.isPlainObject(context) && (opts == null || Object.keys(opts).length === 0);
77+
return isPlainObject(context) && (opts == null || Object.keys(opts).length === 0);
7878
}
7979

8080
function configureLogger(options: Options) {

src/handlers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as _ from 'lodash';
1+
import * as camelCase from 'camelcase';
22
import { getInstance } from './logger';
33
const logger = getInstance();
44

@@ -21,7 +21,7 @@ export function getHandlers(options) {
2121
// all handlers for the http-proxy events are prefixed with 'on'.
2222
// loop through options and try to find these handlers
2323
// and add them to the handlers object for subscription in init().
24-
const eventName = _.camelCase('on ' + event);
24+
const eventName = camelCase('on ' + event);
2525
const fnHandler = options ? options[eventName] : null;
2626

2727
if (typeof fnHandler === 'function') {

src/path-rewriter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as _ from 'lodash';
1+
import { isPlainObject } from 'is-plain-object';
22
import { ERRORS } from './errors';
33
import { getInstance } from './logger';
44
const logger = getInstance();
@@ -42,12 +42,12 @@ export function createPathRewriter(rewriteConfig) {
4242
function isValidRewriteConfig(rewriteConfig) {
4343
if (typeof rewriteConfig === 'function') {
4444
return true;
45-
} else if (_.isPlainObject(rewriteConfig) && Object.keys(rewriteConfig).length !== 0) {
45+
} else if (isPlainObject(rewriteConfig) && Object.keys(rewriteConfig).length !== 0) {
4646
return true;
4747
} else if (
4848
rewriteConfig === undefined ||
4949
rewriteConfig === null ||
50-
_.isEqual(rewriteConfig, {})
50+
JSON.stringify(rewriteConfig) === '{}'
5151
) {
5252
return false;
5353
} else {
@@ -58,7 +58,7 @@ function isValidRewriteConfig(rewriteConfig) {
5858
function parsePathRewriteRules(rewriteConfig) {
5959
const rules = [];
6060

61-
if (_.isPlainObject(rewriteConfig)) {
61+
if (isPlainObject(rewriteConfig)) {
6262
for (const [key] of Object.entries(rewriteConfig)) {
6363
rules.push({
6464
regex: new RegExp(key),

src/router.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import * as _ from 'lodash';
1+
import { isPlainObject } from 'is-plain-object';
22
import { getInstance } from './logger';
33
const logger = getInstance();
44

55
export async function getTarget(req, config) {
66
let newTarget;
77
const router = config.router;
88

9-
if (_.isPlainObject(router)) {
9+
if (isPlainObject(router)) {
1010
newTarget = getTargetFromProxyTable(req, router);
1111
} else if (typeof router === 'function') {
1212
newTarget = await router(req);

yarn.lock

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -902,11 +902,6 @@
902902
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.5.tgz#dcce4430e64b443ba8945f0290fb564ad5bac6dd"
903903
integrity sha512-7+2BITlgjgDhH0vvwZU/HZJVyk+2XUlvxXe8dFMedNX/aMkaOq++rMAFXc0tM7ij15QaWlbdQASBR9dihi+bDQ==
904904

905-
"@types/lodash@^4.14.168":
906-
version "4.14.168"
907-
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.168.tgz#fe24632e79b7ade3f132891afff86caa5e5ce008"
908-
integrity sha512-oVfRvqHV/V6D1yifJbVRU3TMp8OT6o6BG+U9MkwuJ3U8/CsDHvalRpsxBqivn71ztOFZBTfJMvETbqHiaNSj7Q==
909-
910905
"@types/micromatch@^4.0.1":
911906
version "4.0.1"
912907
resolved "https://registry.yarnpkg.com/@types/micromatch/-/micromatch-4.0.1.tgz#9381449dd659fc3823fd2a4190ceacc985083bc7"
@@ -1705,6 +1700,11 @@ camelcase@^6.0.0:
17051700
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.0.0.tgz#5259f7c30e35e278f1bdc2a4d91230b37cad981e"
17061701
integrity sha512-8KMDF1Vz2gzOq54ONPJS65IvTUaB1cHJ2DMM7MbPmLZljDH1qpzzLsWdiN9pHh6qvkRVDTi/07+eNGch/oLU4w==
17071702

1703+
camelcase@^6.2.0:
1704+
version "6.2.0"
1705+
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.2.0.tgz#924af881c9d525ac9d87f40d964e5cea982a1809"
1706+
integrity sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg==
1707+
17081708
capture-exit@^2.0.0:
17091709
version "2.0.0"
17101710
resolved "https://registry.yarnpkg.com/capture-exit/-/capture-exit-2.0.0.tgz#fb953bfaebeb781f62898239dabb426d08a509a4"
@@ -3624,6 +3624,11 @@ is-plain-object@^2.0.3, is-plain-object@^2.0.4:
36243624
dependencies:
36253625
isobject "^3.0.1"
36263626

3627+
is-plain-object@^5.0.0:
3628+
version "5.0.0"
3629+
resolved "https://registry.yarnpkg.com/is-plain-object/-/is-plain-object-5.0.0.tgz#4427f50ab3429e9025ea7d52e9043a9ef4159344"
3630+
integrity sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==
3631+
36273632
is-potential-custom-element-name@^1.0.0:
36283633
version "1.0.0"
36293634
resolved "https://registry.yarnpkg.com/is-potential-custom-element-name/-/is-potential-custom-element-name-1.0.0.tgz#0c52e54bcca391bb2c494b21e8626d7336c6e397"

0 commit comments

Comments
 (0)