From 3eb29d58d5e099a060abb12fc88304d20e6aa324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Neves?= Date: Thu, 25 Jun 2026 22:04:24 +0000 Subject: [PATCH] refactor: replace lodash/cloneDeep with native structuredClone MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Replace lodash/cloneDeep usage in bolt11.js with native structuredClone() - Remove lodash from package.json dependencies - Bundle size reduced by ~36 KB (1,813.88 kB → 1,777.73 kB) - structuredClone() is supported in all modern browsers and Node.js 17+ --- package-lock.json | 2 +- package.json | 1 - src/lib/bolt11.js | 6 +++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index ef5f5a3..026301b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,7 +27,6 @@ "coininfo": "git+https://github.com/cryptocoinjs/coininfo.git#dc3e6cc59e593ee7dbeb7c993485706e72d32743", "crypto-browserify": "^3.12.1", "framer-motion": "^12.40.0", - "lodash": "^4.17.15", "lucide-react": "^1.17.0", "react": "^19.0.0", "react-dom": "^19.0.0", @@ -6600,6 +6599,7 @@ "version": "4.18.1", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.18.1.tgz", "integrity": "sha512-dMInicTPVE8d1e5otfwmmjlxkZoUpiVLwyeTdUsi/Caj/gfzzblBcCE5sRHV/AsjuCmxWrte2TNGSYuCeCq+0Q==", + "dev": true, "license": "MIT" }, "node_modules/loupe": { diff --git a/package.json b/package.json index a40215c..edccdcc 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,6 @@ "coininfo": "git+https://github.com/cryptocoinjs/coininfo.git#dc3e6cc59e593ee7dbeb7c993485706e72d32743", "crypto-browserify": "^3.12.1", "framer-motion": "^12.40.0", - "lodash": "^4.17.15", "lucide-react": "^1.17.0", "react": "^19.0.0", "react-dom": "^19.0.0", diff --git a/src/lib/bolt11.js b/src/lib/bolt11.js index 56dfd78..b5d7c64 100644 --- a/src/lib/bolt11.js +++ b/src/lib/bolt11.js @@ -5,7 +5,7 @@ import secp256k1 from 'secp256k1' import { Buffer } from 'buffer' import BN from 'bn.js' import * as bitcoinjsAddress from 'bitcoinjs-lib/src/address' -import cloneDeep from 'lodash/cloneDeep' + import coininfo from 'coininfo' function createBitcoinJSNetwork (network, invoiceBech32, addressBech32) { @@ -383,7 +383,7 @@ function hrpToMillisat (hrpString, outputString) { } function sign (inputPayReqObj, inputPrivateKey) { - let payReqObj = cloneDeep(inputPayReqObj) + let payReqObj = structuredClone(inputPayReqObj) let privateKey = hexToBuffer(inputPrivateKey) if (payReqObj.complete && payReqObj.paymentRequest) return payReqObj @@ -458,7 +458,7 @@ function sign (inputPayReqObj, inputPrivateKey) { */ function encode (inputData, addDefaults) { // we don't want to affect the data being passed in, so we copy the object - let data = cloneDeep(inputData) + let data = structuredClone(inputData) // by default we will add default values to description, expire time, and min cltv if (addDefaults === undefined) addDefaults = true