Skip to content

Commit 1556f58

Browse files
authored
refactor: replace lodash for native alternative (#2242)
- startsWith - noop - isFunction - isString - find Refs #2187
1 parent 2ea42d2 commit 1556f58

File tree

5 files changed

+7
-14
lines changed

5 files changed

+7
-14
lines changed

src/helpers.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import isObject from 'lodash/isObject';
2-
import startsWith from 'lodash/startsWith';
32

43
const toLower = (str) => String.prototype.toLowerCase.call(str);
54
const escapeString = (str) => str.replace(/[^\w]/gi, '_');
@@ -11,7 +10,7 @@ export function isOAS3(spec) {
1110
return false;
1211
}
1312

14-
return startsWith(oasVersion, '3');
13+
return oasVersion.startsWith('3');
1514
}
1615

1716
export function isSwagger2(spec) {
@@ -20,7 +19,7 @@ export function isSwagger2(spec) {
2019
return false;
2120
}
2221

23-
return startsWith(swaggerVersion, '2');
22+
return swaggerVersion.startsWith('2');
2423
}
2524

2625
// Strategy for determining operationId

src/http/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import 'cross-fetch/polyfill'; /* global fetch */
22
import qs from 'qs';
33
import jsYaml from 'js-yaml';
4-
import isFunction from 'lodash/isFunction';
54
import { Buffer } from 'buffer';
65
import { FormData, File, Blob } from 'formdata-node';
76

@@ -142,7 +141,7 @@ function serializeHeaderValue(value) {
142141
// Cookie: two
143142
// = { Cookie: [ "one", "two" ]
144143
export function serializeHeaders(headers = {}) {
145-
if (!isFunction(headers.entries)) return {};
144+
if (typeof headers.entries !== 'function') return {};
146145

147146
return Array.from(headers.entries()).reduce((acc, [header, value]) => {
148147
acc[header] = serializeHeaderValue(value);

src/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import startsWith from 'lodash/startsWith';
21
import Url from 'url';
32

43
import Http, { makeHttp, serializeRes, serializeHeaders } from './http';
@@ -88,7 +87,7 @@ Swagger.prototype.applyDefaults = function applyDefaults() {
8887
const { spec } = this;
8988
const specUrl = this.url;
9089
// TODO: OAS3: support servers here
91-
if (specUrl && startsWith(specUrl, 'http')) {
90+
if (specUrl && specUrl.startsWith('http')) {
9291
const parsed = Url.parse(specUrl);
9392
if (!spec.host) {
9493
spec.host = parsed.host;

src/specmap/helpers.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import traverse from 'traverse';
22
import URL from 'url';
3-
import isString from 'lodash/isString';
43

54
// This will match if the direct parent's key exactly matches an item.
65
const freelyNamedKeyParents = ['properties'];
@@ -59,7 +58,7 @@ export function generateAbsoluteRefPatches(
5958
const patches = [];
6059

6160
traverse(obj).forEach(function callback() {
62-
if (targetKeys.includes(this.key) && isString(this.node)) {
61+
if (targetKeys.includes(this.key) && typeof this.node === 'string') {
6362
const nodePath = this.path; // this node's path, relative to `obj`
6463
const fullPath = basePath.concat(this.path);
6564

src/specmap/index.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import find from 'lodash/find';
2-
import noop from 'lodash/noop';
3-
41
import lib from './lib';
52
import refs from './lib/refs';
63
import allOf from './lib/all-of';
@@ -9,6 +6,7 @@ import properties from './lib/properties';
96
import ContextTree from './lib/context-tree';
107

118
const HARD_LIMIT = 100;
9+
const noop = () => {};
1210

1311
class SpecMap {
1412
static getPluginName(plugin) {
@@ -154,8 +152,7 @@ class SpecMap {
154152
}
155153

156154
nextPlugin() {
157-
// Array.prototype.find doesn't work in IE 11 :(
158-
return find(this.wrappedPlugins, (plugin) => {
155+
return this.wrappedPlugins.find((plugin) => {
159156
const mutations = this.getMutationsForPlugin(plugin);
160157
return mutations.length > 0;
161158
});

0 commit comments

Comments
 (0)