Skip to content

Commit

Permalink
Removes all non-dev usage of lodash to minimize bundle size (#822)
Browse files Browse the repository at this point in the history
* Drop all lodash usage (except in tests)
* Add NYC's coverage output to .gitignore
  • Loading branch information
Shaptic committed May 16, 2023
1 parent f817f85 commit 0d97789
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
/libdocs/
/dist/
/coverage/
/.nyc_output/
/jsdoc/
.DS_Store
.idea/
js-stellar-base/
js-stellar-base/
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"karma-sinon-chai": "^2.0.2",
"karma-webpack": "^5.0.0",
"lint-staged": "^13.2.1",
"lodash": "^4.17.21",
"minami": "^1.1.1",
"mocha": "^10.2.0",
"node-polyfill-webpack-plugin": "^2.0.1",
Expand All @@ -139,7 +140,6 @@
"bignumber.js": "^9.1.1",
"detect-node": "^2.0.4",
"eventsource": "^2.0.2",
"lodash": "^4.17.21",
"randombytes": "^2.1.0",
"stellar-base": "v9.0.0-beta.2",
"toml": "^3.0.0",
Expand Down
3 changes: 1 addition & 2 deletions src/account_response.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* tslint:disable:variable-name */

import forIn from "lodash/forIn";
import { Account as BaseAccount } from "stellar-base";
import { Horizon } from "./horizon_api";
import { ServerApi } from "./server_api";
Expand Down Expand Up @@ -57,7 +56,7 @@ export class AccountResponse {
this._baseAccount = new BaseAccount(response.account_id, response.sequence);
// Extract response fields
// TODO: do it in type-safe manner.
forIn(response, (value, key) => {
Object.entries(response).forEach(([key, value]) => {
(this as any)[key] = value;
});
}
Expand Down
4 changes: 1 addition & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import clone from "lodash/clone";

interface Configuration {
/**
* Allow connecting to http servers, default: `false`. This must be set to false in production deployments!
Expand All @@ -20,7 +18,7 @@ const defaultConfig: Configuration = {
timeout: 0,
};

let config = clone(defaultConfig);
let config = Object.assign({}, defaultConfig);

/**
* Global config class.
Expand Down
11 changes: 5 additions & 6 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* tslint:disable:variable-name no-namespace */

import BigNumber from "bignumber.js";
import isEmpty from "lodash/isEmpty";
import merge from "lodash/merge";
import {
Asset,
FeeBumpTransaction,
Expand Down Expand Up @@ -83,7 +81,7 @@ export class Server {
? Config.isAllowHttp()
: opts.allowHttp;

const customHeaders: any = {};
const customHeaders: object = {};

if (opts.appName) {
customHeaders["X-App-Name"] = opts.appName;
Expand All @@ -94,10 +92,11 @@ export class Server {
if (opts.authToken) {
customHeaders["X-Auth-Token"] = opts.authToken;
}
if (!isEmpty(customHeaders)) {
if (Object.keys(customHeaders).length > 0) {
HorizonAxiosClient.interceptors.request.use((config) => {
// merge the custom headers with an existing headers
config.headers = merge(customHeaders, config.headers);
// merge the custom headers with an existing headers, where customs
// override defaults
config.headers = Object.assign(config.headers, customHeaders);

return config;
});
Expand Down
3 changes: 1 addition & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import clone from "lodash/clone";
import randomBytes from "randombytes";
import {
Account,
Expand Down Expand Up @@ -676,7 +675,7 @@ export namespace Utils {
): string[] {
const hashedSignatureBase = transaction.hash();

const txSignatures = clone(transaction.signatures);
const txSignatures = [...transaction.signatures]; // shallow copy for safe splicing
const signersFound = new Set<string>();

for (const signer of signers) {
Expand Down

0 comments on commit 0d97789

Please sign in to comment.