@ocap/util 1.29.27 → 1.30.0
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/esm/create-sorted-list.mjs +1 -4
- package/esm/get-list-field.mjs +2 -3
- package/esm/index.d.mts +3 -3
- package/esm/index.mjs +16 -9
- package/lib/create-sorted-list.cjs +1 -6
- package/lib/get-list-field.cjs +2 -4
- package/lib/index.cjs +24 -26
- package/lib/index.d.cts +3 -3
- package/package.json +2 -4
- package/esm/lodash.d.ts +0 -12
- package/lib/lodash.d.ts +0 -12
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import flatten from "lodash/flatten.js";
|
|
2
|
-
import uniq from "lodash/uniq.js";
|
|
3
|
-
|
|
4
1
|
//#region src/create-sorted-list.ts
|
|
5
|
-
const createSortedList = (list) =>
|
|
2
|
+
const createSortedList = (list) => [...new Set(list.flat())].filter(Boolean).sort();
|
|
6
3
|
|
|
7
4
|
//#endregion
|
|
8
5
|
export { createSortedList };
|
package/esm/get-list-field.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import get from "lodash/get.js";
|
|
2
|
-
|
|
3
1
|
//#region src/get-list-field.ts
|
|
4
|
-
const
|
|
2
|
+
const getByPath = (obj, path) => path.split(".").reduce((o, k) => o?.[k], obj);
|
|
3
|
+
const getListField = (obj, key) => getByPath(obj, `${key}List`) || getByPath(obj, key) || [];
|
|
5
4
|
|
|
6
5
|
//#endregion
|
|
7
6
|
export { getListField };
|
package/esm/index.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { BN } from "./bn.mjs";
|
|
2
2
|
import { scopeMatch, scopeMatchAny } from "./scope-match.mjs";
|
|
3
|
-
import rightPad from "lodash/padEnd.js";
|
|
4
|
-
import leftPad from "lodash/padStart.js";
|
|
5
3
|
import { LiteralUnion } from "type-fest";
|
|
6
4
|
|
|
7
5
|
//#region src/index.d.ts
|
|
6
|
+
declare const leftPad: (str: any, len: number, char?: string) => string;
|
|
7
|
+
declare const rightPad: (str: any, len: number, char?: string) => string;
|
|
8
8
|
declare const isBase58btc: (data: any) => boolean;
|
|
9
9
|
type BytesType = string | Buffer | Uint8Array;
|
|
10
10
|
type EncodingType = LiteralUnion<'hex' | 'base16' | 'base58' | 'base64' | 'Uint8Array' | 'buffer', string>;
|
|
@@ -226,6 +226,6 @@ declare function isSameDid(a: string, b: string): boolean;
|
|
|
226
226
|
* @returns The method string, or null if no prefix found
|
|
227
227
|
*/
|
|
228
228
|
declare function extractMethod(did: unknown): string | null;
|
|
229
|
-
declare function formatTxType(type: string):
|
|
229
|
+
declare function formatTxType(type: string): string;
|
|
230
230
|
//#endregion
|
|
231
231
|
export { BN, BytesType, EncodingType, KeyPairType, UUID, bytesToHex, extractMethod, formatTxType, fromBase58, fromBase64, fromTokenToUnit, fromUnitToToken, hexToBytes, hexToNumber, hexToUtf8, isBN, isBase58btc, isBigNumber, isHex, isHexPrefixed, isHexStrict, isSameDid, isUUID, isUint8Array, leftPad, numberToBN, numberToHex, numberToString, rightPad, scopeMatch, scopeMatchAny, stripHexPrefix, toAddress, toBN, toBase58, toBase64, toBuffer, toDid, toHex, toUint8Array, utf8ToHex };
|
package/esm/index.mjs
CHANGED
|
@@ -3,18 +3,25 @@ import { scopeMatch, scopeMatchAny } from "./scope-match.mjs";
|
|
|
3
3
|
import BaseBN from "bn.js";
|
|
4
4
|
import base64 from "base64-url";
|
|
5
5
|
import base58 from "bs58";
|
|
6
|
-
import camelCase from "lodash/camelCase.js";
|
|
7
|
-
import isBoolean from "lodash/isBoolean.js";
|
|
8
|
-
import isNull from "lodash/isNull.js";
|
|
9
|
-
import isNumber from "lodash/isNumber.js";
|
|
10
|
-
import isObject from "lodash/isObject.js";
|
|
11
|
-
import isString from "lodash/isString.js";
|
|
12
|
-
import rightPad from "lodash/padEnd.js";
|
|
13
|
-
import leftPad from "lodash/padStart.js";
|
|
14
|
-
import upperFirst from "lodash/upperFirst.js";
|
|
15
6
|
import utf8 from "utf8";
|
|
16
7
|
|
|
17
8
|
//#region src/index.ts
|
|
9
|
+
const isBoolean = (x) => typeof x === "boolean";
|
|
10
|
+
const isNull = (x) => x === null;
|
|
11
|
+
const isNumber = (x) => typeof x === "number";
|
|
12
|
+
const isString = (x) => typeof x === "string";
|
|
13
|
+
const isObject = (x) => x !== null && typeof x === "object";
|
|
14
|
+
const leftPad = (str, len, char) => String(str).padStart(len, char);
|
|
15
|
+
const rightPad = (str, len, char) => String(str).padEnd(len, char);
|
|
16
|
+
const upperFirst = (str) => str ? str[0].toUpperCase() + str.slice(1) : "";
|
|
17
|
+
const camelCase = (str) => {
|
|
18
|
+
const words = str.match(/[a-zA-Z0-9]+/g);
|
|
19
|
+
if (!words) return "";
|
|
20
|
+
return words.map((w, i) => {
|
|
21
|
+
const lower = w.toLowerCase();
|
|
22
|
+
return i === 0 ? lower : lower[0].toUpperCase() + lower.slice(1);
|
|
23
|
+
}).join("");
|
|
24
|
+
};
|
|
18
25
|
const zero = new BN(0);
|
|
19
26
|
const negative1 = new BN(-1);
|
|
20
27
|
const base58btc = {
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let lodash_flatten = require("lodash/flatten");
|
|
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
1
|
|
|
7
2
|
//#region src/create-sorted-list.ts
|
|
8
|
-
const createSortedList = (list) =>
|
|
3
|
+
const createSortedList = (list) => [...new Set(list.flat())].filter(Boolean).sort();
|
|
9
4
|
|
|
10
5
|
//#endregion
|
|
11
6
|
exports.createSortedList = createSortedList;
|
package/lib/get-list-field.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let lodash_get = require("lodash/get");
|
|
3
|
-
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
4
1
|
|
|
5
2
|
//#region src/get-list-field.ts
|
|
6
|
-
const
|
|
3
|
+
const getByPath = (obj, path) => path.split(".").reduce((o, k) => o?.[k], obj);
|
|
4
|
+
const getListField = (obj, key) => getByPath(obj, `${key}List`) || getByPath(obj, key) || [];
|
|
7
5
|
|
|
8
6
|
//#endregion
|
|
9
7
|
exports.getListField = getListField;
|
package/lib/index.cjs
CHANGED
|
@@ -7,28 +7,26 @@ let base64_url = require("base64-url");
|
|
|
7
7
|
base64_url = require_rolldown_runtime.__toESM(base64_url);
|
|
8
8
|
let bs58 = require("bs58");
|
|
9
9
|
bs58 = require_rolldown_runtime.__toESM(bs58);
|
|
10
|
-
let lodash_camelCase = require("lodash/camelCase");
|
|
11
|
-
lodash_camelCase = require_rolldown_runtime.__toESM(lodash_camelCase);
|
|
12
|
-
let lodash_isBoolean = require("lodash/isBoolean");
|
|
13
|
-
lodash_isBoolean = require_rolldown_runtime.__toESM(lodash_isBoolean);
|
|
14
|
-
let lodash_isNull = require("lodash/isNull");
|
|
15
|
-
lodash_isNull = require_rolldown_runtime.__toESM(lodash_isNull);
|
|
16
|
-
let lodash_isNumber = require("lodash/isNumber");
|
|
17
|
-
lodash_isNumber = require_rolldown_runtime.__toESM(lodash_isNumber);
|
|
18
|
-
let lodash_isObject = require("lodash/isObject");
|
|
19
|
-
lodash_isObject = require_rolldown_runtime.__toESM(lodash_isObject);
|
|
20
|
-
let lodash_isString = require("lodash/isString");
|
|
21
|
-
lodash_isString = require_rolldown_runtime.__toESM(lodash_isString);
|
|
22
|
-
let lodash_padEnd = require("lodash/padEnd");
|
|
23
|
-
lodash_padEnd = require_rolldown_runtime.__toESM(lodash_padEnd);
|
|
24
|
-
let lodash_padStart = require("lodash/padStart");
|
|
25
|
-
lodash_padStart = require_rolldown_runtime.__toESM(lodash_padStart);
|
|
26
|
-
let lodash_upperFirst = require("lodash/upperFirst");
|
|
27
|
-
lodash_upperFirst = require_rolldown_runtime.__toESM(lodash_upperFirst);
|
|
28
10
|
let utf8 = require("utf8");
|
|
29
11
|
utf8 = require_rolldown_runtime.__toESM(utf8);
|
|
30
12
|
|
|
31
13
|
//#region src/index.ts
|
|
14
|
+
const isBoolean = (x) => typeof x === "boolean";
|
|
15
|
+
const isNull = (x) => x === null;
|
|
16
|
+
const isNumber = (x) => typeof x === "number";
|
|
17
|
+
const isString = (x) => typeof x === "string";
|
|
18
|
+
const isObject = (x) => x !== null && typeof x === "object";
|
|
19
|
+
const leftPad = (str, len, char) => String(str).padStart(len, char);
|
|
20
|
+
const rightPad = (str, len, char) => String(str).padEnd(len, char);
|
|
21
|
+
const upperFirst = (str) => str ? str[0].toUpperCase() + str.slice(1) : "";
|
|
22
|
+
const camelCase = (str) => {
|
|
23
|
+
const words = str.match(/[a-zA-Z0-9]+/g);
|
|
24
|
+
if (!words) return "";
|
|
25
|
+
return words.map((w, i) => {
|
|
26
|
+
const lower = w.toLowerCase();
|
|
27
|
+
return i === 0 ? lower : lower[0].toUpperCase() + lower.slice(1);
|
|
28
|
+
}).join("");
|
|
29
|
+
};
|
|
32
30
|
const zero = new require_bn.BN(0);
|
|
33
31
|
const negative1 = new require_bn.BN(-1);
|
|
34
32
|
const base58btc = {
|
|
@@ -120,7 +118,7 @@ const isBigNumber = (object) => object?.constructor && object.constructor.name =
|
|
|
120
118
|
* @param {String} hex to be checked
|
|
121
119
|
* @returns {Boolean}
|
|
122
120
|
*/
|
|
123
|
-
const isHexStrict = (hex) => ((
|
|
121
|
+
const isHexStrict = (hex) => (isString(hex) || isNumber(hex)) && /^(-)?0x[0-9a-f]*$/i.test(hex);
|
|
124
122
|
/**
|
|
125
123
|
* Check if string is HEX
|
|
126
124
|
*
|
|
@@ -130,7 +128,7 @@ const isHexStrict = (hex) => ((0, lodash_isString.default)(hex) || (0, lodash_is
|
|
|
130
128
|
* @param {String} hex to be checked
|
|
131
129
|
* @returns {Boolean}
|
|
132
130
|
*/
|
|
133
|
-
const isHex = (hex) => ((
|
|
131
|
+
const isHex = (hex) => (isString(hex) || isNumber(hex)) && /^(-0x|0x|0X|-0X)?[0-9a-f]*$/i.test(hex);
|
|
134
132
|
/**
|
|
135
133
|
* Takes an input and transforms it into an BN
|
|
136
134
|
*
|
|
@@ -218,7 +216,7 @@ const hexToNumber = (value) => {
|
|
|
218
216
|
* @returns {String}
|
|
219
217
|
*/
|
|
220
218
|
const numberToHex = (value) => {
|
|
221
|
-
if ((
|
|
219
|
+
if (isNull(value) || typeof value === "undefined") return value;
|
|
222
220
|
const isNumericString = typeof value === "string" && !Number.isNaN(Number(value)) && Number.isFinite(Number(value));
|
|
223
221
|
if (!Number.isFinite(value) && !isHex(value) && !isNumericString && !isBN(value) && !isBigNumber(value)) throw new Error(`Given input "${value}" is not a number.`);
|
|
224
222
|
const num = toBN(value);
|
|
@@ -276,8 +274,8 @@ const hexToBytes = (hex) => {
|
|
|
276
274
|
const toHex = (value, returnType = false) => {
|
|
277
275
|
if (isUint8Array(value) || Buffer.isBuffer(value)) return returnType ? "bytes" : bytesToHex(value);
|
|
278
276
|
if (isBase58btc(value)) return returnType ? "bytes" : bytesToHex(base58btc.decode(value));
|
|
279
|
-
if ((
|
|
280
|
-
if ((
|
|
277
|
+
if (isBoolean(value)) return returnType ? "bool" : value ? "0x01" : "0x00";
|
|
278
|
+
if (isObject(value) && !isBigNumber(value) && !isBN(value)) return returnType ? "string" : utf8ToHex(JSON.stringify(value));
|
|
281
279
|
if (typeof value === "string") {
|
|
282
280
|
if (value.indexOf("-0x") === 0 || value.indexOf("-0X") === 0) return returnType ? "int256" : numberToHex(value);
|
|
283
281
|
if (value.indexOf("0x") === 0 || value.indexOf("0X") === 0) return returnType ? "bytes" : value;
|
|
@@ -450,7 +448,7 @@ function extractMethod(did) {
|
|
|
450
448
|
return null;
|
|
451
449
|
}
|
|
452
450
|
function formatTxType(type) {
|
|
453
|
-
return (
|
|
451
|
+
return upperFirst(camelCase(type));
|
|
454
452
|
}
|
|
455
453
|
|
|
456
454
|
//#endregion
|
|
@@ -475,11 +473,11 @@ exports.isHexStrict = isHexStrict;
|
|
|
475
473
|
exports.isSameDid = isSameDid;
|
|
476
474
|
exports.isUUID = isUUID;
|
|
477
475
|
exports.isUint8Array = isUint8Array;
|
|
478
|
-
exports.leftPad =
|
|
476
|
+
exports.leftPad = leftPad;
|
|
479
477
|
exports.numberToBN = numberToBN;
|
|
480
478
|
exports.numberToHex = numberToHex;
|
|
481
479
|
exports.numberToString = numberToString;
|
|
482
|
-
exports.rightPad =
|
|
480
|
+
exports.rightPad = rightPad;
|
|
483
481
|
exports.scopeMatch = require_scope_match.scopeMatch;
|
|
484
482
|
exports.scopeMatchAny = require_scope_match.scopeMatchAny;
|
|
485
483
|
exports.stripHexPrefix = stripHexPrefix;
|
package/lib/index.d.cts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { BN } from "./bn.cjs";
|
|
2
2
|
import { scopeMatch, scopeMatchAny } from "./scope-match.cjs";
|
|
3
|
-
import rightPad from "lodash/padEnd";
|
|
4
|
-
import leftPad from "lodash/padStart";
|
|
5
3
|
import { LiteralUnion } from "type-fest";
|
|
6
4
|
|
|
7
5
|
//#region src/index.d.ts
|
|
6
|
+
declare const leftPad: (str: any, len: number, char?: string) => string;
|
|
7
|
+
declare const rightPad: (str: any, len: number, char?: string) => string;
|
|
8
8
|
declare const isBase58btc: (data: any) => boolean;
|
|
9
9
|
type BytesType = string | Buffer | Uint8Array;
|
|
10
10
|
type EncodingType = LiteralUnion<'hex' | 'base16' | 'base58' | 'base64' | 'Uint8Array' | 'buffer', string>;
|
|
@@ -226,6 +226,6 @@ declare function isSameDid(a: string, b: string): boolean;
|
|
|
226
226
|
* @returns The method string, or null if no prefix found
|
|
227
227
|
*/
|
|
228
228
|
declare function extractMethod(did: unknown): string | null;
|
|
229
|
-
declare function formatTxType(type: string):
|
|
229
|
+
declare function formatTxType(type: string): string;
|
|
230
230
|
//#endregion
|
|
231
231
|
export { BN, BytesType, EncodingType, KeyPairType, UUID, bytesToHex, extractMethod, formatTxType, fromBase58, fromBase64, fromTokenToUnit, fromUnitToToken, hexToBytes, hexToNumber, hexToUtf8, isBN, isBase58btc, isBigNumber, isHex, isHexPrefixed, isHexStrict, isSameDid, isUUID, isUint8Array, leftPad, numberToBN, numberToHex, numberToString, rightPad, scopeMatch, scopeMatchAny, stripHexPrefix, toAddress, toBN, toBase58, toBase64, toBuffer, toDid, toHex, toUint8Array, utf8ToHex };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ocap/util",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.30.0",
|
|
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,13 +12,12 @@
|
|
|
12
12
|
"access": "public"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@ocap/types": "1.
|
|
15
|
+
"@ocap/types": "1.30.0",
|
|
16
16
|
"@types/bn.js": "^5.2.0",
|
|
17
17
|
"base64-url": "^2.3.3",
|
|
18
18
|
"bn.js": "5.2.3",
|
|
19
19
|
"bs58": "^5.0.0",
|
|
20
20
|
"ipaddr.js": "^2.1.0",
|
|
21
|
-
"lodash": "^4.17.23",
|
|
22
21
|
"utf8": "^3.0.0"
|
|
23
22
|
},
|
|
24
23
|
"resolutions": {
|
|
@@ -26,7 +25,6 @@
|
|
|
26
25
|
},
|
|
27
26
|
"devDependencies": {
|
|
28
27
|
"@types/base64-url": "^2.2.2",
|
|
29
|
-
"@types/lodash": "^4.17.10",
|
|
30
28
|
"@types/node": "^22.7.5",
|
|
31
29
|
"@types/utf8": "^3.0.3",
|
|
32
30
|
"tsdown": "^0.18.4",
|
package/esm/lodash.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
declare module 'lodash/camelCase';
|
|
2
|
-
declare module 'lodash/flatten';
|
|
3
|
-
declare module 'lodash/get';
|
|
4
|
-
declare module 'lodash/isBoolean';
|
|
5
|
-
declare module 'lodash/isNull';
|
|
6
|
-
declare module 'lodash/isNumber';
|
|
7
|
-
declare module 'lodash/isObject';
|
|
8
|
-
declare module 'lodash/isString';
|
|
9
|
-
declare module 'lodash/padEnd';
|
|
10
|
-
declare module 'lodash/padStart';
|
|
11
|
-
declare module 'lodash/uniq';
|
|
12
|
-
declare module 'lodash/upperFirst';
|
package/lib/lodash.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
declare module 'lodash/camelCase';
|
|
2
|
-
declare module 'lodash/flatten';
|
|
3
|
-
declare module 'lodash/get';
|
|
4
|
-
declare module 'lodash/isBoolean';
|
|
5
|
-
declare module 'lodash/isNull';
|
|
6
|
-
declare module 'lodash/isNumber';
|
|
7
|
-
declare module 'lodash/isObject';
|
|
8
|
-
declare module 'lodash/isString';
|
|
9
|
-
declare module 'lodash/padEnd';
|
|
10
|
-
declare module 'lodash/padStart';
|
|
11
|
-
declare module 'lodash/uniq';
|
|
12
|
-
declare module 'lodash/upperFirst';
|