Skip to content

Commit

Permalink
[Chore][DEVX-522] Remove Buffer Module (#902)
Browse files Browse the repository at this point in the history
* chore(sdk-client-v3): remove buffer module

- remove all instance of the buffer module to ensure compatibility with client side applications

* chore(release-changeset): add release changeset

- uninstall buffer module
- add release changeset
  • Loading branch information
ajimae authored Jan 14, 2025
1 parent c5344e3 commit a08c782
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/gentle-ravens-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@commercetools/ts-client': patch
---

remove buffer module and replace with js native String.normalize function
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"@types/node": "^20.0.0",
"axios": "^1.7.7",
"babel-jest": "29.7.0",
"buffer": "^6.0.3",
"clean-webpack-plugin": "^4.0.0",
"codecov": "^3.2.5",
"esbuild": "^0.24.0",
Expand Down
10 changes: 6 additions & 4 deletions packages/sdk-client-v3/src/utils/byteLength.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
var Buffer = require('buffer/').Buffer

export default function byteLength<T>(body: T): string {
if (body && (typeof body === 'string' || body instanceof Uint8Array)) {
return Buffer.byteLength(body).toString()
if (body && typeof body === 'string') {
return body.normalize('NFD').length.toString()
}

if (body && body instanceof Uint8Array) {
return new TextDecoder().decode(body).length.toString()
}

if (body && typeof body === 'object') {
Expand Down

0 comments on commit a08c782

Please sign in to comment.