Skip to content

Commit 2120a1a

Browse files
authored
Avoid lodash where possible (#1122)
* Avoid lodash where possible Lodash is quote big project and it's required less with a time in modern environments. In this diff I bumped node support to 8+ and used native methods where possible instead of lodash. Later we can go further and completely remove it from the project. This can make the project much smaller. https://packagephobia.com/result?p=soap * Add missing semicolon * Tweak engines
1 parent 3e49710 commit 2120a1a

File tree

5 files changed

+26
-27
lines changed

5 files changed

+26
-27
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.33.0",
44
"description": "A minimal node SOAP client",
55
"engines": {
6-
"node": ">=4.0.0"
6+
"node": ">=10.0.0"
77
},
88
"author": "Vinay Pulim <[email protected]>",
99
"dependencies": {

soap-stub.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
var _ = require('lodash');
2-
31
var aliasedClientStubs = {};
42
var clientStubs = {};
53

@@ -124,7 +122,7 @@ function registerClient(alias, urlToWsdl, clientStub) {
124122
* Resets state associated with clientStubs.
125123
*/
126124
function reset() {
127-
_.forEach(clientStubs, resetStubbedMethods);
125+
Object.values(clientStubs).forEach(resetStubbedMethods);
128126
this.errOnCreateClient = false;
129127
}
130128

src/http.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import * as debugBuilder from 'debug';
77
import * as httpNtlm from 'httpntlm';
8-
import * as _ from 'lodash';
98
import * as req from 'request';
109
import * as url from 'url';
1110
import * as uuid from 'uuid/v4';
@@ -66,7 +65,9 @@ export class HttpClient {
6665
'Host': host + (isNaN(port) ? '' : ':' + port),
6766
};
6867
const mergeOptions = ['headers'];
69-
const attachments: IAttachment[] = exoptions.attachments || [];
68+
69+
const {attachments: _attachments, ...newExoptions } = exoptions;
70+
const attachments: IAttachment[] = _attachments || [];
7071

7172
if (typeof data === 'string' && attachments.length === 0 && !exoptions.forceMTOM) {
7273
headers['Content-Length'] = Buffer.byteLength(data, 'utf8');
@@ -120,7 +121,7 @@ export class HttpClient {
120121
options.body = data;
121122
}
122123

123-
for (const attr in _.omit(exoptions, ['attachments'])) {
124+
for (const attr in newExoptions) {
124125
if (mergeOptions.indexOf(attr) !== -1) {
125126
for (const header in exoptions[attr]) {
126127
options[attr][header] = exoptions[attr][header];

src/wsdl/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function trim(text) {
3232

3333
function deepMerge<A, B>(destination: A, source: B): A & B {
3434
return _.mergeWith(destination, source, (a, b) => {
35-
return _.isArray(a) ? a.concat(b) : undefined;
35+
return Array.isArray(a) ? a.concat(b) : undefined;
3636
});
3737
}
3838

@@ -495,7 +495,7 @@ export class WSDL {
495495
for (const n in refs) {
496496
const ref = refs[n];
497497
for (const href of ref.hrefs) {
498-
_.assign(href.obj, ref.obj);
498+
Object.assign(href.obj, ref.obj);
499499
}
500500
}
501501

@@ -1184,7 +1184,7 @@ export class WSDL {
11841184
includePath = this.options.wsdl_options.overrideImportLocation(includePath);
11851185
}
11861186

1187-
const options = _.assign({}, this.options);
1187+
const options = Object.assign({}, this.options);
11881188
// follow supplied ignoredNamespaces option
11891189
options.ignoredNamespaces = this._originalIgnoredNamespaces || this.options.ignoredNamespaces;
11901190
options.WSDL_CACHE = this.WSDL_CACHE;

test/client-test.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ var fs = require('fs'),
7272
request: function () { }
7373
};
7474
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl',
75-
_.assign({ httpClient: myHttpClient }, meta.options),
75+
Object.assign({ httpClient: myHttpClient }, meta.options),
7676
function (err, client) {
7777
assert.ok(client);
7878
assert.ifError(err);
@@ -85,7 +85,7 @@ var fs = require('fs'),
8585
var myRequest = function () {
8686
};
8787
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl',
88-
_.assign({ request: myRequest }, meta.options),
88+
Object.assign({ request: myRequest }, meta.options),
8989
function (err, client) {
9090
assert.ok(client);
9191
assert.ifError(err);
@@ -96,7 +96,7 @@ var fs = require('fs'),
9696

9797

9898
it('should allow customization of envelope', function (done) {
99-
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', _.assign({ envelopeKey: 'soapenv' }, meta.options), function (err, client) {
99+
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', Object.assign({ envelopeKey: 'soapenv' }, meta.options), function (err, client) {
100100
assert.ok(client);
101101
assert.ifError(err);
102102

@@ -109,7 +109,7 @@ var fs = require('fs'),
109109

110110

111111
it('should allow passing in XML strings', function (done) {
112-
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', _.assign({ envelopeKey: 'soapenv' }, meta.options), function (err, client) {
112+
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', Object.assign({ envelopeKey: 'soapenv' }, meta.options), function (err, client) {
113113
assert.ok(client);
114114
assert.ifError(err);
115115

@@ -135,7 +135,7 @@ var fs = require('fs'),
135135

136136
it('should allow disabling the wsdl cache', function (done) {
137137
var spy = sinon.spy(wsdl, 'open_wsdl');
138-
var options = _.assign({ disableCache: true }, meta.options);
138+
var options = Object.assign({ disableCache: true }, meta.options);
139139
soap.createClient(__dirname + '/wsdl/binding_document.wsdl', options, function (err1, client1) {
140140
assert.ok(client1);
141141
assert.ok(!err1);
@@ -279,7 +279,7 @@ var fs = require('fs'),
279279
});
280280

281281
it('Should preserve SOAP 1.2 "action" header when sending MTOM request', function (done) {
282-
soap.createClient(__dirname + '/wsdl/attachments.wsdl', _.assign({ forceSoap12Headers: true }, meta.options), function (initError, client) {
282+
soap.createClient(__dirname + '/wsdl/attachments.wsdl', Object.assign({ forceSoap12Headers: true }, meta.options), function (initError, client) {
283283
assert.ifError(initError);
284284

285285
client.MyOperation({}, function (error, response, body, soapHeader, rawRequest) {
@@ -291,7 +291,7 @@ var fs = require('fs'),
291291
})
292292

293293
it('Should send MTOM request even without attachment', function (done) {
294-
soap.createClient(__dirname + '/wsdl/attachments.wsdl', _.assign({ forceSoap12Headers: true }, meta.options), function (initError, client) {
294+
soap.createClient(__dirname + '/wsdl/attachments.wsdl', Object.assign({ forceSoap12Headers: true }, meta.options), function (initError, client) {
295295
assert.ifError(initError);
296296

297297
client.MyOperation({}, function (error, response, body, soapHeader, rawRequest) {
@@ -536,7 +536,7 @@ var fs = require('fs'),
536536
});
537537

538538
it('should add proper headers for soap12', function (done) {
539-
soap.createClient(__dirname + '/wsdl/default_namespace_soap12.wsdl', _.assign({ forceSoap12Headers: true }, meta.options), function (err, client) {
539+
soap.createClient(__dirname + '/wsdl/default_namespace_soap12.wsdl', Object.assign({ forceSoap12Headers: true }, meta.options), function (err, client) {
540540
assert.ok(client);
541541
assert.ifError(err);
542542

@@ -1143,7 +1143,7 @@ var fs = require('fs'),
11431143
on: function () { }
11441144
};
11451145
};
1146-
var options = _.assign({
1146+
var options = Object.assign({
11471147
request: mockRequestHandler,
11481148
}, meta.options);
11491149
soap.createClient(__dirname + '/wsdl/builtin_types.wsdl', options, function (err, client) {
@@ -1365,7 +1365,7 @@ var fs = require('fs'),
13651365
request: function () { }
13661366
};
13671367
soap.createClientAsync(__dirname + '/wsdl/default_namespace.wsdl',
1368-
_.assign({ httpClient: myHttpClient }, meta.options))
1368+
Object.assign({ httpClient: myHttpClient }, meta.options))
13691369
.then(function (client) {
13701370
assert.ok(client);
13711371
assert.equal(client.httpClient, myHttpClient);
@@ -1377,7 +1377,7 @@ var fs = require('fs'),
13771377
var myRequest = function () {
13781378
};
13791379
soap.createClientAsync(__dirname + '/wsdl/default_namespace.wsdl',
1380-
_.assign({ request: myRequest }, meta.options))
1380+
Object.assign({ request: myRequest }, meta.options))
13811381
.then(function (client) {
13821382
assert.ok(client);
13831383
assert.equal(client.httpClient._request, myRequest);
@@ -1395,7 +1395,7 @@ var fs = require('fs'),
13951395
});
13961396

13971397
it('should allow passing in XML strings', function (done) {
1398-
soap.createClientAsync(__dirname + '/wsdl/default_namespace.wsdl', _.assign({envelopeKey: 'soapenv'}, meta.options))
1398+
soap.createClientAsync(__dirname + '/wsdl/default_namespace.wsdl', Object.assign({envelopeKey: 'soapenv'}, meta.options))
13991399
.then(function (client) {
14001400
assert.ok(client);
14011401
var xmlStr = '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n\t<head>\n\t\t<title>404 - Not Found</title>\n\t</head>\n\t<body>\n\t\t<h1>404 - Not Found</h1>\n\t\t<script type="text/javascript" src="http://gp1.wpc.edgecastcdn.net/00222B/beluga/pilot_rtm/beluga_beacon.js"></script>\n\t</body>\n</html>';
@@ -1409,7 +1409,7 @@ var fs = require('fs'),
14091409

14101410
it('should allow customization of envelope', function (done) {
14111411
var client;
1412-
soap.createClientAsync(__dirname + '/wsdl/default_namespace.wsdl', _.assign({ envelopeKey: 'soapenv' }, meta.options))
1412+
soap.createClientAsync(__dirname + '/wsdl/default_namespace.wsdl', Object.assign({ envelopeKey: 'soapenv' }, meta.options))
14131413
.then(function (createdClient) {
14141414
assert.ok(createdClient);
14151415
client = createdClient;
@@ -1448,7 +1448,7 @@ var fs = require('fs'),
14481448

14491449
it('should allow disabling the wsdl cache', function (done) {
14501450
var spy = sinon.spy(wsdl, 'open_wsdl');
1451-
var options = _.assign({ disableCache: true }, meta.options);
1451+
var options = Object.assign({ disableCache: true }, meta.options);
14521452
soap.createClientAsync(__dirname + '/wsdl/binding_document.wsdl', options)
14531453
.then(function (client) {
14541454
assert.ok(client);
@@ -1484,7 +1484,7 @@ var fs = require('fs'),
14841484
describe('Client created with option normalizeNames', function(){
14851485

14861486
it('should create node-style method with normalized name (a valid Javascript identifier)', function (done) {
1487-
soap.createClient(__dirname + '/wsdl/non_identifier_chars_in_operation.wsdl', _.assign({ normalizeNames: true }, meta.options), function (err, client) {
1487+
soap.createClient(__dirname + '/wsdl/non_identifier_chars_in_operation.wsdl', Object.assign({ normalizeNames: true }, meta.options), function (err, client) {
14881488
assert.ok(client);
14891489
assert.ifError(err);
14901490
client.prefixed_MyOperation({},function(err, result){
@@ -1511,7 +1511,7 @@ var fs = require('fs'),
15111511
});
15121512

15131513
it('should create promise-style method with normalized name (a valid Javascript identifier)', function (done) {
1514-
soap.createClient(__dirname + '/wsdl/non_identifier_chars_in_operation.wsdl', _.assign({ normalizeNames: true }, meta.options), function (err, client) {
1514+
soap.createClient(__dirname + '/wsdl/non_identifier_chars_in_operation.wsdl', Object.assign({ normalizeNames: true }, meta.options), function (err, client) {
15151515
assert.ok(client);
15161516
assert.ifError(err);
15171517
client.prefixed_MyOperationAsync({})
@@ -1525,7 +1525,7 @@ var fs = require('fs'),
15251525
});
15261526

15271527
it('should not create methods with invalid Javascript identifier', function (done) {
1528-
soap.createClient(__dirname + '/wsdl/non_identifier_chars_in_operation.wsdl', _.assign({ normalizeNames: true }, meta.options), function (err, client) {
1528+
soap.createClient(__dirname + '/wsdl/non_identifier_chars_in_operation.wsdl', Object.assign({ normalizeNames: true }, meta.options), function (err, client) {
15291529
assert.ok(client);
15301530
assert.ifError(err);
15311531
assert.throws(function() {client['prefixed-MyOperationAsync']({});}, TypeError);

0 commit comments

Comments
 (0)