Skip to content

Commit

Permalink
fix(core): make isBuffer browser compliant
Browse files Browse the repository at this point in the history
Closes: #2480
  • Loading branch information
Romakita committed Oct 26, 2023
1 parent 81f3bb8 commit 09ef730
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 39 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@
]
},
"resolutions": {
"mongoose": "6.5.1"
"mongoose": "6.5.1",
"crypto-js": "4.2.0"
},
"collective": {
"type": "opencollective",
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/utils/objects/isBuffer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {isBuffer} from "./isBuffer";
import {isBuffer, isUint8Array} from "./isBuffer";

describe("isBuffer", () => {
it("should return true", () => {
expect(isBuffer(Buffer.from(""))).toBeTruthy();
expect(isBuffer(Buffer)).toBeTruthy();
expect(isUint8Array(Uint8Array)).toBeTruthy();
expect(isUint8Array(Uint8Array.from([0, 1]))).toBeTruthy();
});
it("should return false", () => {
expect(isBuffer({})).toBeFalsy();
Expand Down
13 changes: 12 additions & 1 deletion packages/core/src/utils/objects/isBuffer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import {nameOf} from "./nameOf";

/**
* Tests to see if the object is Buffer
* @param target
* @returns {boolean}
*/
export function isBuffer(target: any): target is Buffer {
return !!(target && (target === Buffer || target instanceof Buffer));
// is Class
if (target && "isBuffer" in target && typeof target.isBuffer === "function") {
return true;
}

return isUint8Array(target);
}

export function isUint8Array(target: any): target is Uint8Array {
return !!(target && (target === Uint8Array || target instanceof Uint8Array));
}
4 changes: 2 additions & 2 deletions packages/engines/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"tinyliquid": "^0.2.34",
"toffee": "^0.3.6",
"twig": "^1.15.2",
"twing": "^5.0.2",
"twing": "5.1.4",
"underscore": "^1.11.0",
"vash": "^0.13.0",
"velocityjs": "^2.0.1",
Expand All @@ -95,4 +95,4 @@
"view"
],
"peerDependencies": {}
}
}
43 changes: 9 additions & 34 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5479,11 +5479,6 @@
dependencies:
"@types/lodash" "*"

"@types/luxon@^1.4.0":
version "1.27.1"
resolved "https://registry.yarnpkg.com/@types/luxon/-/luxon-1.27.1.tgz#aceeb2d5be8fccf541237e184e37ecff5faa9096"
integrity sha512-cPiXpOvPFDr2edMnOXlz3UBDApwUfR+cpizvxCy0n3vp9bz/qe8BWzHPIEFcy+ogUOyjKuCISgyq77ELZPmkkg==

"@types/mdast@^3.0.0":
version "3.0.10"
resolved "https://registry.yarnpkg.com/@types/mdast/-/mdast-3.0.10.tgz#4724244a82a4598884cbbe9bcfd73dff927ee8af"
Expand Down Expand Up @@ -9084,11 +9079,6 @@ camelcase@^1.0.2, camelcase@^1.2.1:
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-1.2.1.tgz#9bb5304d2e0b56698b2c758b08a3eaa9daa58a39"
integrity sha1-m7UwTS4LVmmLLHWLCKPqqdqlijk=

camelcase@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-4.1.0.tgz#d545635be1e33c542649c69173e5de6acfae34dd"
integrity sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0=

camelcase@^5.0.0, camelcase@^5.3.1:
version "5.3.1"
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-5.3.1.tgz#e3c9b31569e106811df242f715725a1f4c494320"
Expand Down Expand Up @@ -10486,10 +10476,10 @@ crypto-browserify@^3.0.0, crypto-browserify@^3.11.0:
randombytes "^2.0.0"
randomfill "^1.0.3"

crypto-js@^3.1.9-1:
version "3.3.0"
resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-3.3.0.tgz#846dd1cce2f68aacfa156c8578f926a609b7976b"
integrity sha512-DIT51nX0dCfKltpRiXV+/TVZq+Qq2NgF4644+K7Ttnla7zEzqc+kjJyiB96BHNyUTBxyjzRcZYpUdZa+QAqi6Q==
crypto-js@4.1.2, crypto-js@^3.1.9-1:
version "4.2.0"
resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.2.0.tgz#4d931639ecdfd12ff80e8186dba6af2c2e856631"
integrity sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==

crypto-random-string@^2.0.0:
version "2.0.0"
Expand Down Expand Up @@ -15050,7 +15040,7 @@ is-hexadecimal@^1.0.0:
resolved "https://registry.yarnpkg.com/is-hexadecimal/-/is-hexadecimal-1.0.4.tgz#cc35c97588da4bd49a8eedd6bc4082d44dcb23a7"
integrity sha512-gyPJuv83bHMpocVYoqof5VDiZveEoGoFL8m3BXNb2VW8Xs+rz9kqO8LOQ5DH6EsuvilT1ApazU0pyl+ytbPtlw==

is-integer@^1.0.4, is-integer@^1.0.7:
is-integer@^1.0.4:
version "1.0.7"
resolved "https://registry.yarnpkg.com/is-integer/-/is-integer-1.0.7.tgz#6bde81aacddf78b659b6629d629cadc51a886d5c"
integrity sha1-a96Bqs3feLZZtmKdYpytxRqIbVw=
Expand Down Expand Up @@ -15111,11 +15101,6 @@ is-number@^3.0.0:
dependencies:
kind-of "^3.0.2"

is-number@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/is-number/-/is-number-5.0.0.tgz#c393bc471e65de1a10a6abcb20efeb12d2b88166"
integrity sha512-LmVHHP5dTJwrwZg2Jjqp7K5jpvcnYvYD1LMpvGadMsMv5+WXoDSLBQ0+zmuBJmuZGh2J2K845ygj/YukxUnr4A==

is-number@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/is-number/-/is-number-7.0.0.tgz#7535345b896734d5f80c4d06c50955527a14f12b"
Expand Down Expand Up @@ -17807,11 +17792,6 @@ merge2@^1.2.3, merge2@^1.3.0, merge2@^1.4.1:
resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae"
integrity sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==

merge@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/merge/-/merge-1.2.1.tgz#38bebf80c3220a8a487b6fcfb3941bb11720c145"
integrity sha512-VjFo4P5Whtj4vsLzsYBu5ayHhoHJ0UqNm7ibvShmbmoz7tGi0vXaoJbGdB+GmDMLUdg8DpQXEIeVDAe8MaABvQ==

merge@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/merge/-/merge-2.1.1.tgz#59ef4bf7e0b3e879186436e8481c06a6c162ca98"
Expand Down Expand Up @@ -24719,27 +24699,22 @@ twig@^1.15.2:
minimatch "3.0.x"
walk "2.3.x"

twing@^5.0.2:
version "5.1.2"
resolved "https://registry.yarnpkg.com/twing/-/twing-5.1.2.tgz#fc07e44e3d969a0d6e7b93cdb0d5ea5ef773c2d3"
integrity sha512-UtRQTHTy9VU6QcZO++NhJekpeMMXInNFafwJcrFE/oR9Hpo2QswHgc6qD/Wx1YXOBfUXPC56OQSuZECGfrkOlg==
twing@5.1.4:
version "5.1.4"
resolved "https://registry.yarnpkg.com/twing/-/twing-5.1.4.tgz#9f27e95a3ac06b7b3f8d90b90de4b0d1536ab4fc"
integrity sha512-NDHYP6/UFyW1bwl1lkKt/LzDXjJnJuXvyWfQU286jr9qd7fztPkoGzBbtQf4whe59z/DY76jWbUQIld34pyEqw==
dependencies:
"@types/luxon" "^1.4.0"
camelcase "^4.1.0"
capitalize "^1.0.0"
crypto-js "^3.1.9-1"
esrever "^0.2.0"
fs-extra "^5.0.0"
htmlspecialchars "^1.0.5"
iconv-lite "^0.4.19"
is-integer "^1.0.7"
is-number "^5.0.0"
is-plain-object "^2.0.4"
isobject "^3.0.1"
levenshtein "^1.0.5"
locutus "^2.0.11"
luxon "^1.19.3"
merge "^1.2.1"
object-hash "^1.2.0"
pad "^2.0.3"
regex-parser "^2.2.8"
Expand Down

0 comments on commit 09ef730

Please sign in to comment.