Skip to content

Commit 0a71309

Browse files
committed
Remove buffer dependency in favour of Buffer.compare shim
1 parent 548c2a9 commit 0a71309

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

internal/util/comparisons.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ const hasOwnProperty = uncurryThis(Object.prototype.hasOwnProperty);
3131
const propertyIsEnumerable = uncurryThis(Object.prototype.propertyIsEnumerable);
3232
const objectToString = uncurryThis(Object.prototype.toString);
3333

34-
const { compare } = require('buffer/').Buffer;
3534
const {
3635
isAnyArrayBuffer,
3736
isArrayBufferView,
@@ -71,6 +70,39 @@ function getOwnNonIndexProperties(value) {
7170
);
7271
}
7372

73+
// Taken from https://github.com/feross/buffer/blob/680e9e5e488f22aac27599a57dc844a6315928dd/index.js
74+
// original notice:
75+
/*!
76+
* The buffer module from node.js, for the browser.
77+
*
78+
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
79+
* @license MIT
80+
*/
81+
function compare(a, b) {
82+
if (a === b) {
83+
return 0;
84+
}
85+
86+
var x = a.length;
87+
var y = b.length;
88+
89+
for (var i = 0, len = Math.min(x, y); i < len; ++i) {
90+
if (a[i] !== b[i]) {
91+
x = a[i];
92+
y = b[i];
93+
break;
94+
}
95+
}
96+
97+
if (x < y) {
98+
return -1;
99+
}
100+
if (y < x) {
101+
return 1;
102+
}
103+
return 0;
104+
}
105+
74106
const ONLY_ENUMERABLE = undefined;
75107

76108
const kStrict = true;

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"tape": "^4.10.1"
3333
},
3434
"dependencies": {
35-
"buffer": "^5.2.1",
3635
"es6-object-assign": "^1.1.0",
3736
"is-nan": "^1.2.1",
3837
"object-is": "^1.0.1",

0 commit comments

Comments
 (0)