Skip to content

Commit f45adff

Browse files
authored
feat: use byte@2 and remove debug, utility deps (#140)
1 parent 22b1c55 commit f45adff

File tree

8 files changed

+41
-16
lines changed

8 files changed

+41
-16
lines changed

.github/workflows/nodejs.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ jobs:
1313
with:
1414
os: 'ubuntu-latest'
1515
version: '8, 10, 12, 14, 16, 18, 20, 22'
16-
16+
secrets:
17+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
18+
1719
build-with-zig:
1820
strategy:
1921
fail-fast: false

lib/object.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
'use strict';
1212

1313
var util = require('util');
14-
var has = require('utility').has;
1514

1615
exports.DEFAULT_CLASSNAME = {
1716
boolean: 'boolean',
@@ -167,6 +166,10 @@ function JavaExceptionError(obj, withType) {
167166

168167
util.inherits(JavaExceptionError, Error);
169168

169+
function has(obj, prop) {
170+
return Object.prototype.hasOwnProperty.call(obj, prop);
171+
}
172+
170173
exports.isJavaException = function (obj) {
171174
if (has(obj, 'detailMessage') && has(obj, 'stackTrace')) {
172175
return true;

lib/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
'use strict';
1111

12-
var debug = require('debug')('hessian.js:utils');
12+
var debug = require('util').debuglog('hessian.js:utils');
1313
var object = require('./object');
1414

1515
var MAX_INT_8 = exports.MAX_INT_8 = Math.pow(2, 7);

lib/v1/decoder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
'use strict';
1212

13-
var debug = require('debug')('hessian:v1:decoder');
13+
var debug = require('util').debuglog('hessian:v1:decoder');
1414
var ByteBuffer = require('byte');
1515
var is = require('is-type-of');
1616
var utils = require('../utils');

lib/v1/encoder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
'use strict';
1212

1313
var ByteBuffer = require('byte');
14-
var debug = require('debug')('hessian:v1:encoder');
14+
var debug = require('util').debuglog('hessian:v1:encoder');
1515
var utils = require('../utils');
1616
var javaObject = require('../object');
1717
var is = require('is-type-of');

lib/v2/decoder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
var util = require('util');
1818
var is = require('is-type-of');
19-
var debug = require('debug')('hessian:v2:decoder');
19+
var debug = require('util').debuglog('hessian:v2:decoder');
2020
var DecoderV1 = require('../v1/decoder');
2121
var utils = require('../utils');
2222
var isJavaException = require('../object').isJavaException;

lib/v2/encoder.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
'use strict';
22

3-
var debug = require('debug')('hessian:v2:encoder');
4-
var is = require('is-type-of');
3+
var debug = require('util').debuglog('hessian:v2:encoder');
54
var util = require('util');
65
var EncoderV1 = require('../v1/encoder');
7-
var javaObject = require('../object');
8-
var utility = require('utility');
96
var Long = require('long');
107
var float32Test = require('../utils').float32Test;
118

@@ -82,6 +79,31 @@ proto.writeInt = function (val) {
8279
return this;
8380
};
8481

82+
// fork from https://github.com/node-modules/utility/blob/master/src/number.ts#L13
83+
// http://www.2ality.com/2013/10/safe-integers.html
84+
// http://es6.ruanyifeng.com/#docs/number
85+
const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1;
86+
// const MIN_SAFE_INTEGER = -MAX_SAFE_INTEGER;
87+
const MAX_SAFE_INTEGER_STR = String(MAX_SAFE_INTEGER);
88+
const MAX_SAFE_INTEGER_STR_LENGTH = MAX_SAFE_INTEGER_STR.length;
89+
90+
/**
91+
* Detect a number string can safe convert to Javascript Number.
92+
*
93+
* @param {String} s number format string, like `"123"`, `"-1000123123123123123123"`
94+
* @return {Boolean}
95+
*/
96+
function isSafeNumberString(s) {
97+
if (s[0] === '-') {
98+
s = s.substring(1);
99+
}
100+
if (s.length < MAX_SAFE_INTEGER_STR_LENGTH ||
101+
(s.length === MAX_SAFE_INTEGER_STR_LENGTH && s <= MAX_SAFE_INTEGER_STR)) {
102+
return true;
103+
}
104+
return false;
105+
}
106+
85107
/**
86108
* encode long
87109
*
@@ -129,7 +151,7 @@ proto.writeInt = function (val) {
129151
*/
130152
proto.writeLong = function (val) {
131153
if (typeof val === 'string') {
132-
if (!utility.isSafeNumberString(val)) {
154+
if (!isSafeNumberString(val)) {
133155
val = Long.fromString(val);
134156
} else {
135157
val = Number(val);

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"scripts": {
1111
"lint": "make jshint",
1212
"test": "make test",
13-
"ci": "npm run lint && npm run test",
13+
"ci": "npm run lint && make cov",
1414
"build::platform": "napi build --cargo-cwd ./lib/v2rust --platform --release ./lib/v2rust/harness/dist"
1515
},
1616
"repository": {
@@ -33,11 +33,9 @@
3333
"homepage": "https://github.com/node-modules/hessian.js",
3434
"dependencies": {
3535
"@protobufjs/codegen": "^2.0.4",
36-
"byte": "^1.4.1",
37-
"debug": "^3.2.6",
36+
"byte": "^2.0.0",
3837
"is-type-of": "^1.2.1",
39-
"long": "^4.0.0",
40-
"utility": "^1.15.0"
38+
"long": "^4.0.0"
4139
},
4240
"devDependencies": {
4341
"beautify-benchmark": "^0.2.4",

0 commit comments

Comments
 (0)