@ocap/util 1.28.5 → 1.28.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  ## Usage
4
4
 
5
5
  ```shell
6
- pnpm install @ocap/util
6
+ bun install @ocap/util
7
7
  ```
8
8
 
9
9
  Then:
@@ -1,5 +1,5 @@
1
- import uniq from "lodash/uniq.js";
2
1
  import flatten from "lodash/flatten.js";
2
+ import uniq from "lodash/uniq.js";
3
3
 
4
4
  //#region src/create-sorted-list.ts
5
5
  const createSortedList = (list) => uniq(flatten(list)).filter(Boolean).sort();
package/esm/index.mjs CHANGED
@@ -1,17 +1,17 @@
1
1
  import { BN } from "./bn.mjs";
2
2
  import BaseBN from "bn.js";
3
+ import base64 from "base64-url";
4
+ import base58 from "bs58";
5
+ import camelCase from "lodash/camelCase.js";
3
6
  import isBoolean from "lodash/isBoolean.js";
4
- import isString from "lodash/isString.js";
7
+ import isNull from "lodash/isNull.js";
5
8
  import isNumber from "lodash/isNumber.js";
6
9
  import isObject from "lodash/isObject.js";
7
- import upperFirst from "lodash/upperFirst.js";
8
- import camelCase from "lodash/camelCase.js";
9
- import isNull from "lodash/isNull.js";
10
+ import isString from "lodash/isString.js";
10
11
  import rightPad from "lodash/padEnd.js";
11
12
  import leftPad from "lodash/padStart.js";
12
- import base58 from "bs58";
13
- import base64 from "base64-url";
14
- import * as utf8 from "utf8";
13
+ import upperFirst from "lodash/upperFirst.js";
14
+ import utf8 from "utf8";
15
15
 
16
16
  //#region src/index.ts
17
17
  const DID_PREFIX = "did:abt:";
@@ -26,7 +26,7 @@ const isBase58btc = (data) => {
26
26
  if (data[0] === "z") try {
27
27
  base58btc.decode(data);
28
28
  return true;
29
- } catch (err) {
29
+ } catch (_err) {
30
30
  return false;
31
31
  }
32
32
  return false;
@@ -86,7 +86,7 @@ const stripHexPrefix = (str) => {
86
86
  * @param {Object} object
87
87
  * @returns {Boolean}
88
88
  */
89
- const isBN = (object) => object instanceof BN || object instanceof BaseBN || object && object.constructor && object.constructor.name === "BN";
89
+ const isBN = (object) => object instanceof BN || object instanceof BaseBN || object?.constructor && object.constructor.name === "BN";
90
90
  /**
91
91
  * Returns true if object is BigNumber, otherwise false
92
92
  *
@@ -96,7 +96,7 @@ const isBN = (object) => object instanceof BN || object instanceof BaseBN || obj
96
96
  * @param {Object} object
97
97
  * @returns {Boolean}
98
98
  */
99
- const isBigNumber = (object) => object && object.constructor && object.constructor.name === "BigNumber";
99
+ const isBigNumber = (object) => object?.constructor && object.constructor.name === "BigNumber";
100
100
  /**
101
101
  * Check if string is HEX, requires a 0x in front
102
102
  *
@@ -176,7 +176,7 @@ const hexToUtf8 = (hex) => {
176
176
  hex = hex.split("").reverse().join("");
177
177
  const l = hex.length;
178
178
  for (let i = 0; i < l; i += 2) {
179
- code = parseInt(hex.substr(i, 2), 16);
179
+ code = Number.parseInt(hex.substr(i, 2), 16);
180
180
  str += String.fromCharCode(code);
181
181
  }
182
182
  return utf8.decode(str);
@@ -205,7 +205,8 @@ const hexToNumber = (value) => {
205
205
  */
206
206
  const numberToHex = (value) => {
207
207
  if (isNull(value) || typeof value === "undefined") return value;
208
- if (!isFinite(value) && !isHex(value)) throw new Error(`Given input "${value}" is not a number.`);
208
+ const isNumericString = typeof value === "string" && !Number.isNaN(Number(value)) && Number.isFinite(Number(value));
209
+ if (!Number.isFinite(value) && !isHex(value) && !isNumericString && !isBN(value) && !isBigNumber(value)) throw new Error(`Given input "${value}" is not a number.`);
209
210
  const num = toBN(value);
210
211
  const result = num.toString(16);
211
212
  return num.lt(new BN(0)) ? `-0x${result.substr(1)}` : `0x${result}`;
@@ -244,7 +245,7 @@ const hexToBytes = (hex) => {
244
245
  hex = hex.replace(/^0x/i, "");
245
246
  hex = hex.length % 2 ? `0${hex}` : hex;
246
247
  const bytes = [];
247
- for (let c = 0; c < hex.length; c += 2) bytes.push(parseInt(hex.substr(c, 2), 16));
248
+ for (let c = 0; c < hex.length; c += 2) bytes.push(Number.parseInt(hex.substr(c, 2), 16));
248
249
  return bytes;
249
250
  };
250
251
  /**
package/esm/md5.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import crypto from "crypto";
1
+ import crypto from "node:crypto";
2
2
 
3
3
  //#region src/md5.ts
4
4
  const md5 = (x) => crypto.createHash("md5").update(x).digest("hex");
package/esm/ready.d.mts CHANGED
@@ -1,8 +1,7 @@
1
- import EventEmitter from "events";
1
+ import EventEmitter from "node:events";
2
2
 
3
3
  //#region src/ready.d.ts
4
4
  declare class Ready extends EventEmitter {
5
- emit: $TSFixMe;
6
5
  ready: $TSFixMe;
7
6
  readyCallbacks: $TSFixMe;
8
7
  readyMarks: $TSFixMe;
package/esm/ready.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import EventEmitter from "events";
1
+ import EventEmitter from "node:events";
2
2
 
3
3
  //#region src/ready.ts
4
4
  var Ready = class extends EventEmitter {
package/esm/tsfixme.d.ts CHANGED
@@ -1,3 +1,2 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
1
  type $TSFixMe = any;
3
2
  type $TSFixMeFunction = (...args: any[]) => any;
package/esm/url.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import * as ipaddr from "ipaddr.js";
1
+ import ipaddr from "ipaddr.js";
2
2
 
3
3
  //#region src/url.d.ts
4
4
  declare function parseIp(host: string): ipaddr.IPv4 | ipaddr.IPv6 | null;
package/esm/url.mjs CHANGED
@@ -1,6 +1,6 @@
1
+ import { Resolver } from "node:dns/promises";
1
2
  import { URL } from "url";
2
- import * as ipaddr from "ipaddr.js";
3
- import { Resolver } from "dns/promises.js";
3
+ import ipaddr from "ipaddr.js";
4
4
 
5
5
  //#region src/url.ts
6
6
  const MAX_URL_LENGTH = 256;
@@ -1,8 +1,8 @@
1
1
  const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
- let lodash_uniq = require("lodash/uniq");
3
- lodash_uniq = require_rolldown_runtime.__toESM(lodash_uniq);
4
2
  let lodash_flatten = require("lodash/flatten");
5
3
  lodash_flatten = require_rolldown_runtime.__toESM(lodash_flatten);
4
+ let lodash_uniq = require("lodash/uniq");
5
+ lodash_uniq = require_rolldown_runtime.__toESM(lodash_uniq);
6
6
 
7
7
  //#region src/create-sorted-list.ts
8
8
  const createSortedList = (list) => (0, lodash_uniq.default)((0, lodash_flatten.default)(list)).filter(Boolean).sort();
package/lib/index.cjs CHANGED
@@ -2,28 +2,28 @@ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
2
  const require_bn = require('./bn.cjs');
3
3
  let bn_js = require("bn.js");
4
4
  bn_js = require_rolldown_runtime.__toESM(bn_js);
5
+ let base64_url = require("base64-url");
6
+ base64_url = require_rolldown_runtime.__toESM(base64_url);
7
+ let bs58 = require("bs58");
8
+ bs58 = require_rolldown_runtime.__toESM(bs58);
9
+ let lodash_camelCase = require("lodash/camelCase");
10
+ lodash_camelCase = require_rolldown_runtime.__toESM(lodash_camelCase);
5
11
  let lodash_isBoolean = require("lodash/isBoolean");
6
12
  lodash_isBoolean = require_rolldown_runtime.__toESM(lodash_isBoolean);
7
- let lodash_isString = require("lodash/isString");
8
- lodash_isString = require_rolldown_runtime.__toESM(lodash_isString);
13
+ let lodash_isNull = require("lodash/isNull");
14
+ lodash_isNull = require_rolldown_runtime.__toESM(lodash_isNull);
9
15
  let lodash_isNumber = require("lodash/isNumber");
10
16
  lodash_isNumber = require_rolldown_runtime.__toESM(lodash_isNumber);
11
17
  let lodash_isObject = require("lodash/isObject");
12
18
  lodash_isObject = require_rolldown_runtime.__toESM(lodash_isObject);
13
- let lodash_upperFirst = require("lodash/upperFirst");
14
- lodash_upperFirst = require_rolldown_runtime.__toESM(lodash_upperFirst);
15
- let lodash_camelCase = require("lodash/camelCase");
16
- lodash_camelCase = require_rolldown_runtime.__toESM(lodash_camelCase);
17
- let lodash_isNull = require("lodash/isNull");
18
- lodash_isNull = require_rolldown_runtime.__toESM(lodash_isNull);
19
+ let lodash_isString = require("lodash/isString");
20
+ lodash_isString = require_rolldown_runtime.__toESM(lodash_isString);
19
21
  let lodash_padEnd = require("lodash/padEnd");
20
22
  lodash_padEnd = require_rolldown_runtime.__toESM(lodash_padEnd);
21
23
  let lodash_padStart = require("lodash/padStart");
22
24
  lodash_padStart = require_rolldown_runtime.__toESM(lodash_padStart);
23
- let bs58 = require("bs58");
24
- bs58 = require_rolldown_runtime.__toESM(bs58);
25
- let base64_url = require("base64-url");
26
- base64_url = require_rolldown_runtime.__toESM(base64_url);
25
+ let lodash_upperFirst = require("lodash/upperFirst");
26
+ lodash_upperFirst = require_rolldown_runtime.__toESM(lodash_upperFirst);
27
27
  let utf8 = require("utf8");
28
28
  utf8 = require_rolldown_runtime.__toESM(utf8);
29
29
 
@@ -40,7 +40,7 @@ const isBase58btc = (data) => {
40
40
  if (data[0] === "z") try {
41
41
  base58btc.decode(data);
42
42
  return true;
43
- } catch (err) {
43
+ } catch (_err) {
44
44
  return false;
45
45
  }
46
46
  return false;
@@ -100,7 +100,7 @@ const stripHexPrefix = (str) => {
100
100
  * @param {Object} object
101
101
  * @returns {Boolean}
102
102
  */
103
- const isBN = (object) => object instanceof require_bn.BN || object instanceof bn_js.default || object && object.constructor && object.constructor.name === "BN";
103
+ const isBN = (object) => object instanceof require_bn.BN || object instanceof bn_js.default || object?.constructor && object.constructor.name === "BN";
104
104
  /**
105
105
  * Returns true if object is BigNumber, otherwise false
106
106
  *
@@ -110,7 +110,7 @@ const isBN = (object) => object instanceof require_bn.BN || object instanceof bn
110
110
  * @param {Object} object
111
111
  * @returns {Boolean}
112
112
  */
113
- const isBigNumber = (object) => object && object.constructor && object.constructor.name === "BigNumber";
113
+ const isBigNumber = (object) => object?.constructor && object.constructor.name === "BigNumber";
114
114
  /**
115
115
  * Check if string is HEX, requires a 0x in front
116
116
  *
@@ -158,7 +158,7 @@ const toBN = (num, base = 10) => {
158
158
  * @returns {String} hex representation of input string
159
159
  */
160
160
  const utf8ToHex = (str) => {
161
- str = utf8.encode(str);
161
+ str = utf8.default.encode(str);
162
162
  let hex = "";
163
163
  str = str.replace(/^(?:\u0000)*/, "");
164
164
  str = str.split("").reverse().join("");
@@ -190,10 +190,10 @@ const hexToUtf8 = (hex) => {
190
190
  hex = hex.split("").reverse().join("");
191
191
  const l = hex.length;
192
192
  for (let i = 0; i < l; i += 2) {
193
- code = parseInt(hex.substr(i, 2), 16);
193
+ code = Number.parseInt(hex.substr(i, 2), 16);
194
194
  str += String.fromCharCode(code);
195
195
  }
196
- return utf8.decode(str);
196
+ return utf8.default.decode(str);
197
197
  };
198
198
  /**
199
199
  * Converts value to number representation
@@ -219,7 +219,8 @@ const hexToNumber = (value) => {
219
219
  */
220
220
  const numberToHex = (value) => {
221
221
  if ((0, lodash_isNull.default)(value) || typeof value === "undefined") return value;
222
- if (!isFinite(value) && !isHex(value)) throw new Error(`Given input "${value}" is not a number.`);
222
+ const isNumericString = typeof value === "string" && !Number.isNaN(Number(value)) && Number.isFinite(Number(value));
223
+ if (!Number.isFinite(value) && !isHex(value) && !isNumericString && !isBN(value) && !isBigNumber(value)) throw new Error(`Given input "${value}" is not a number.`);
223
224
  const num = toBN(value);
224
225
  const result = num.toString(16);
225
226
  return num.lt(new require_bn.BN(0)) ? `-0x${result.substr(1)}` : `0x${result}`;
@@ -258,7 +259,7 @@ const hexToBytes = (hex) => {
258
259
  hex = hex.replace(/^0x/i, "");
259
260
  hex = hex.length % 2 ? `0${hex}` : hex;
260
261
  const bytes = [];
261
- for (let c = 0; c < hex.length; c += 2) bytes.push(parseInt(hex.substr(c, 2), 16));
262
+ for (let c = 0; c < hex.length; c += 2) bytes.push(Number.parseInt(hex.substr(c, 2), 16));
262
263
  return bytes;
263
264
  };
264
265
  /**
package/lib/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { BN } from "./bn.cjs";
2
- import { LiteralUnion } from "type-fest";
3
2
  import rightPad from "lodash/padEnd";
4
3
  import leftPad from "lodash/padStart";
4
+ import { LiteralUnion } from "type-fest";
5
5
 
6
6
  //#region src/index.d.ts
7
7
  declare const isBase58btc: (data: any) => boolean;
package/lib/md5.cjs CHANGED
@@ -1,9 +1,9 @@
1
1
  const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
- let crypto = require("crypto");
3
- crypto = require_rolldown_runtime.__toESM(crypto);
2
+ let node_crypto = require("node:crypto");
3
+ node_crypto = require_rolldown_runtime.__toESM(node_crypto);
4
4
 
5
5
  //#region src/md5.ts
6
- const md5 = (x) => crypto.default.createHash("md5").update(x).digest("hex");
6
+ const md5 = (x) => node_crypto.default.createHash("md5").update(x).digest("hex");
7
7
 
8
8
  //#endregion
9
9
  exports.md5 = md5;
package/lib/ready.cjs CHANGED
@@ -1,9 +1,9 @@
1
1
  const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
- let events = require("events");
3
- events = require_rolldown_runtime.__toESM(events);
2
+ let node_events = require("node:events");
3
+ node_events = require_rolldown_runtime.__toESM(node_events);
4
4
 
5
5
  //#region src/ready.ts
6
- var Ready = class extends events.default {
6
+ var Ready = class extends node_events.default {
7
7
  constructor() {
8
8
  super();
9
9
  this.ready = false;
package/lib/ready.d.cts CHANGED
@@ -1,8 +1,7 @@
1
- import EventEmitter from "events";
1
+ import EventEmitter from "node:events";
2
2
 
3
3
  //#region src/ready.d.ts
4
4
  declare class Ready extends EventEmitter {
5
- emit: $TSFixMe;
6
5
  ready: $TSFixMe;
7
6
  readyCallbacks: $TSFixMe;
8
7
  readyMarks: $TSFixMe;
package/lib/tsfixme.d.ts CHANGED
@@ -1,3 +1,2 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
1
  type $TSFixMe = any;
3
2
  type $TSFixMeFunction = (...args: any[]) => any;
package/lib/url.cjs CHANGED
@@ -1,15 +1,15 @@
1
1
  const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ let node_dns_promises = require("node:dns/promises");
2
3
  let url = require("url");
3
4
  let ipaddr_js = require("ipaddr.js");
4
5
  ipaddr_js = require_rolldown_runtime.__toESM(ipaddr_js);
5
- let dns_promises = require("dns/promises");
6
6
 
7
7
  //#region src/url.ts
8
8
  const MAX_URL_LENGTH = 256;
9
9
  function parseIp(host) {
10
- if (!ipaddr_js.isValid(host)) return null;
10
+ if (!ipaddr_js.default.isValid(host)) return null;
11
11
  try {
12
- return ipaddr_js.parse(host);
12
+ return ipaddr_js.default.parse(host);
13
13
  } catch {
14
14
  return null;
15
15
  }
@@ -32,7 +32,7 @@ function isUnicastAddress(host) {
32
32
  }
33
33
  async function resolveHostAddresses(host) {
34
34
  try {
35
- const resolver = new dns_promises.Resolver();
35
+ const resolver = new node_dns_promises.Resolver();
36
36
  resolver.setServers(["8.8.8.8", "1.1.1.1"]);
37
37
  const addresses = [];
38
38
  try {
package/lib/url.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import * as ipaddr from "ipaddr.js";
1
+ import ipaddr from "ipaddr.js";
2
2
 
3
3
  //#region src/url.d.ts
4
4
  declare function parseIp(host: string): ipaddr.IPv4 | ipaddr.IPv6 | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ocap/util",
3
- "version": "1.28.5",
3
+ "version": "1.28.7",
4
4
  "type": "module",
5
5
  "description": "utils shared across multiple forge js libs, works in both node.js and browser",
6
6
  "keywords": [
@@ -12,28 +12,23 @@
12
12
  "access": "public"
13
13
  },
14
14
  "dependencies": {
15
+ "@ocap/types": "workspace:^",
15
16
  "@types/bn.js": "^5.2.0",
16
17
  "base64-url": "^2.3.3",
17
18
  "bn.js": "5.2.2",
18
19
  "bs58": "^5.0.0",
19
20
  "ipaddr.js": "^2.1.0",
20
21
  "lodash": "^4.17.21",
21
- "utf8": "^3.0.0",
22
- "@ocap/types": "^1.28.5"
22
+ "utf8": "^3.0.0"
23
23
  },
24
24
  "resolutions": {
25
25
  "elliptic": "6.5.3"
26
26
  },
27
27
  "devDependencies": {
28
- "@arcblock/eslint-config-ts": "0.3.3",
29
28
  "@types/base64-url": "^2.2.2",
30
- "@types/jest": "^29.5.13",
31
29
  "@types/lodash": "^4.17.10",
32
30
  "@types/node": "^22.7.5",
33
31
  "@types/utf8": "^3.0.3",
34
- "eslint": "^8.57.0",
35
- "jest": "^29.7.0",
36
- "ts-jest": "^29.2.5",
37
32
  "tsdown": "^0.18.4",
38
33
  "type-fest": "^3.1.0",
39
34
  "typescript": "^5.6.2"
@@ -77,15 +72,15 @@
77
72
  "type": "git",
78
73
  "url": "git+https://github.com/ArcBlock/blockchain.git"
79
74
  },
80
- "bugs": {
81
- "url": "https://github.com/ArcBlock/blockchain/issues"
82
- },
83
75
  "scripts": {
84
- "lint": "eslint src tests",
85
- "lint:fix": "npm run lint -- --fix",
86
- "test": "jest --forceExit --detectOpenHandles",
76
+ "lint": "biome check",
77
+ "lint:fix": "biome check --write",
78
+ "test": "bun test",
87
79
  "coverage": "npm run test -- --coverage",
88
80
  "build": "tsdown",
89
81
  "build:watch": "tsdown -w"
82
+ },
83
+ "bugs": {
84
+ "url": "https://github.com/ArcBlock/blockchain/issues"
90
85
  }
91
- }
86
+ }
package/LICENSE DELETED
@@ -1,13 +0,0 @@
1
- Copyright 2018-2025 ArcBlock
2
-
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
-
7
- http://www.apache.org/licenses/LICENSE-2.0
8
-
9
- Unless required by applicable law or agreed to in writing, software
10
- distributed under the License is distributed on an "AS IS" BASIS,
11
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- See the License for the specific language governing permissions and
13
- limitations under the License.