@polkadot-api/utils 0.1.0 → 0.1.2
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/dist/esm/AbortError.mjs +9 -0
- package/dist/esm/AbortError.mjs.map +1 -0
- package/dist/esm/filterObject.mjs +8 -0
- package/dist/esm/filterObject.mjs.map +1 -0
- package/dist/esm/hex.mjs +51 -0
- package/dist/esm/hex.mjs.map +1 -0
- package/dist/esm/index.mjs +7 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/mapObject.mjs +13 -0
- package/dist/esm/mapObject.mjs.map +1 -0
- package/dist/esm/mergeUint8.mjs +13 -0
- package/dist/esm/mergeUint8.mjs.map +1 -0
- package/dist/esm/noop.mjs +4 -0
- package/dist/esm/noop.mjs.map +1 -0
- package/dist/index.js +19 -48
- package/dist/index.js.map +1 -1
- package/package.json +9 -8
- package/dist/index.d.mts +0 -22
- package/dist/index.mjs +0 -103
- package/dist/index.mjs.map +0 -1
- package/dist/min/index.d.ts +0 -22
- package/dist/min/index.js +0 -2
- package/dist/min/index.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbortError.mjs","sources":["../../src/AbortError.ts"],"sourcesContent":["export class AbortError extends Error {\n constructor() {\n super(\"Abort Error\")\n this.name = \"AbortError\"\n }\n}\n"],"names":[],"mappings":"AAAO,MAAM,mBAAmB,KAAM,CAAA;AAAA,EACpC,WAAc,GAAA;AACZ,IAAA,KAAA,CAAM,aAAa,CAAA,CAAA;AACnB,IAAA,IAAA,CAAK,IAAO,GAAA,YAAA,CAAA;AAAA,GACd;AACF;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filterObject.mjs","sources":["../../src/filterObject.ts"],"sourcesContent":["export function filterObject<K extends string | number | symbol, I>(\n input: Record<K, I>,\n filterFn: (i: I, k: K) => boolean,\n): Record<K, I> {\n return Object.fromEntries(\n Object.entries(input).filter(([key, value]: any) => filterFn(value, key)),\n ) as any\n}\n"],"names":[],"mappings":"AAAgB,SAAA,YAAA,CACd,OACA,QACc,EAAA;AACd,EAAA,OAAO,MAAO,CAAA,WAAA;AAAA,IACZ,MAAO,CAAA,OAAA,CAAQ,KAAK,CAAA,CAAE,MAAO,CAAA,CAAC,CAAC,GAAA,EAAK,KAAK,CAAA,KAAW,QAAS,CAAA,KAAA,EAAO,GAAG,CAAC,CAAA;AAAA,GAC1E,CAAA;AACF;;;;"}
|
package/dist/esm/hex.mjs
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const HEX_STR = "0123456789abcdef";
|
|
2
|
+
function toHex(bytes) {
|
|
3
|
+
const result = new Array(bytes.length + 1);
|
|
4
|
+
result[0] = "0x";
|
|
5
|
+
for (let i = 0; i < bytes.length; ) {
|
|
6
|
+
const b = bytes[i++];
|
|
7
|
+
result[i] = HEX_STR[b >> 4] + HEX_STR[b & 15];
|
|
8
|
+
}
|
|
9
|
+
return result.join("");
|
|
10
|
+
}
|
|
11
|
+
const HEX_MAP = {
|
|
12
|
+
0: 0,
|
|
13
|
+
1: 1,
|
|
14
|
+
2: 2,
|
|
15
|
+
3: 3,
|
|
16
|
+
4: 4,
|
|
17
|
+
5: 5,
|
|
18
|
+
6: 6,
|
|
19
|
+
7: 7,
|
|
20
|
+
8: 8,
|
|
21
|
+
9: 9,
|
|
22
|
+
a: 10,
|
|
23
|
+
b: 11,
|
|
24
|
+
c: 12,
|
|
25
|
+
d: 13,
|
|
26
|
+
e: 14,
|
|
27
|
+
f: 15,
|
|
28
|
+
A: 10,
|
|
29
|
+
B: 11,
|
|
30
|
+
C: 12,
|
|
31
|
+
D: 13,
|
|
32
|
+
E: 14,
|
|
33
|
+
F: 15
|
|
34
|
+
};
|
|
35
|
+
function fromHex(hexString) {
|
|
36
|
+
const isOdd = hexString.length % 2;
|
|
37
|
+
const base = (hexString[1] === "x" ? 2 : 0) + isOdd;
|
|
38
|
+
const nBytes = (hexString.length - base) / 2 + isOdd;
|
|
39
|
+
const bytes = new Uint8Array(nBytes);
|
|
40
|
+
if (isOdd) bytes[0] = 0 | HEX_MAP[hexString[2]];
|
|
41
|
+
for (let i = 0; i < nBytes; ) {
|
|
42
|
+
const idx = base + i * 2;
|
|
43
|
+
const a = HEX_MAP[hexString[idx]];
|
|
44
|
+
const b = HEX_MAP[hexString[idx + 1]];
|
|
45
|
+
bytes[isOdd + i++] = a << 4 | b;
|
|
46
|
+
}
|
|
47
|
+
return bytes;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { fromHex, toHex };
|
|
51
|
+
//# sourceMappingURL=hex.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hex.mjs","sources":["../../src/hex.ts"],"sourcesContent":["// https://jsben.ch/uWZw3\nconst HEX_STR = \"0123456789abcdef\"\nexport function toHex(bytes: Uint8Array): string {\n const result = new Array<string>(bytes.length + 1)\n\n result[0] = \"0x\"\n\n for (let i = 0; i < bytes.length; ) {\n const b = bytes[i++]\n result[i] = HEX_STR[b >> 4] + HEX_STR[b & 15]\n }\n\n return result.join(\"\")\n}\n\n// https://jsben.ch/URe1X\nconst HEX_MAP: Record<string, number> = {\n 0: 0,\n 1: 1,\n 2: 2,\n 3: 3,\n 4: 4,\n 5: 5,\n 6: 6,\n 7: 7,\n 8: 8,\n 9: 9,\n a: 10,\n b: 11,\n c: 12,\n d: 13,\n e: 14,\n f: 15,\n A: 10,\n B: 11,\n C: 12,\n D: 13,\n E: 14,\n F: 15,\n}\nexport function fromHex(hexString: string): Uint8Array {\n const isOdd = hexString.length % 2\n const base = (hexString[1] === \"x\" ? 2 : 0) + isOdd\n const nBytes = (hexString.length - base) / 2 + isOdd\n const bytes = new Uint8Array(nBytes)\n\n if (isOdd) bytes[0] = 0 | HEX_MAP[hexString[2]]\n\n for (let i = 0; i < nBytes; ) {\n const idx = base + i * 2\n const a = HEX_MAP[hexString[idx]]\n const b = HEX_MAP[hexString[idx + 1]]\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AAA,EAAA;AAAA,EACH,CAAG,EAAA,EAAA;AACL,CAAA,CAAA;AACO,SAAS,QAAQ,SAA+B,EAAA;AACrD,EAAM,MAAA,KAAA,GAAQ,UAAU,MAAS,GAAA,CAAA,CAAA;AACjC,EAAA,MAAM,QAAQ,SAAU,CAAA,CAAC,CAAM,KAAA,GAAA,GAAM,IAAI,CAAK,IAAA,KAAA,CAAA;AAC9C,EAAA,MAAM,MAAU,GAAA,CAAA,SAAA,CAAU,MAAS,GAAA,IAAA,IAAQ,CAAI,GAAA,KAAA,CAAA;AAC/C,EAAM,MAAA,KAAA,GAAQ,IAAI,UAAA,CAAW,MAAM,CAAA,CAAA;AAEnC,EAAI,IAAA,KAAA,QAAa,CAAC,CAAA,GAAI,IAAI,OAAQ,CAAA,SAAA,CAAU,CAAC,CAAC,CAAA,CAAA;AAE9C,EAAS,KAAA,IAAA,CAAA,GAAI,CAAG,EAAA,CAAA,GAAI,MAAU,IAAA;AAC5B,IAAM,MAAA,GAAA,GAAM,OAAO,CAAI,GAAA,CAAA,CAAA;AACvB,IAAA,MAAM,CAAI,GAAA,OAAA,CAAQ,SAAU,CAAA,GAAG,CAAC,CAAA,CAAA;AAChC,IAAA,MAAM,CAAI,GAAA,OAAA,CAAQ,SAAU,CAAA,GAAA,GAAM,CAAC,CAAC,CAAA,CAAA;AACpC,IAAA,KAAA,CAAM,KAAQ,GAAA,CAAA,EAAG,CAAK,GAAA,CAAA,IAAK,CAAK,GAAA,CAAA,CAAA;AAAA,GAClC;AAEA,EAAO,OAAA,KAAA,CAAA;AACT;;;;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { fromHex, toHex } from './hex.mjs';
|
|
2
|
+
export { mapObject, mapStringRecord } from './mapObject.mjs';
|
|
3
|
+
export { filterObject } from './filterObject.mjs';
|
|
4
|
+
export { mergeUint8 } from './mergeUint8.mjs';
|
|
5
|
+
export { noop } from './noop.mjs';
|
|
6
|
+
export { AbortError } from './AbortError.mjs';
|
|
7
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function mapObject(input, mapper) {
|
|
2
|
+
return Object.fromEntries(
|
|
3
|
+
Object.entries(input).map(
|
|
4
|
+
([key, value]) => [key, mapper(value, key)]
|
|
5
|
+
)
|
|
6
|
+
);
|
|
7
|
+
}
|
|
8
|
+
const mapStringRecord = (input, mapper) => Object.fromEntries(
|
|
9
|
+
Object.entries(input).map(([key, value]) => [key, mapper(value, key)])
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
export { mapObject, mapStringRecord };
|
|
13
|
+
//# sourceMappingURL=mapObject.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapObject.mjs","sources":["../../src/mapObject.ts"],"sourcesContent":["export function mapObject<K extends string | number | symbol, I, O>(\n input: Record<K, I>,\n mapper: (i: I, k: K) => O,\n): Record<K, O>\n\nexport function mapObject<K extends string | number | symbol, I, O>(\n input: Record<K, I>,\n mapper: (i: I, k?: K) => O,\n): Record<K, O> {\n return Object.fromEntries(\n Object.entries(input).map(\n ([key, value]: any) => [key, mapper(value, key)] as const,\n ),\n ) as any\n}\n\nexport type StringRecord<T> = {\n [Sym: symbol]: never\n [Num: number]: never\n [Str: string]: T\n}\n\nexport const mapStringRecord = <I, O>(\n input: StringRecord<I>,\n mapper: (value: I, key: string) => O,\n): StringRecord<O> =>\n Object.fromEntries(\n Object.entries(input).map(([key, value]) => [key, mapper(value, key)]),\n ) as StringRecord<O>\n"],"names":[],"mappings":"AAKgB,SAAA,SAAA,CACd,OACA,MACc,EAAA;AACd,EAAA,OAAO,MAAO,CAAA,WAAA;AAAA,IACZ,MAAA,CAAO,OAAQ,CAAA,KAAK,CAAE,CAAA,GAAA;AAAA,MACpB,CAAC,CAAC,GAAA,EAAK,KAAK,CAAA,KAAW,CAAC,GAAK,EAAA,MAAA,CAAO,KAAO,EAAA,GAAG,CAAC,CAAA;AAAA,KACjD;AAAA,GACF,CAAA;AACF,CAAA;AAQO,MAAM,eAAkB,GAAA,CAC7B,KACA,EAAA,MAAA,KAEA,MAAO,CAAA,WAAA;AAAA,EACL,OAAO,OAAQ,CAAA,KAAK,CAAE,CAAA,GAAA,CAAI,CAAC,CAAC,GAAA,EAAK,KAAK,CAAA,KAAM,CAAC,GAAK,EAAA,MAAA,CAAO,KAAO,EAAA,GAAG,CAAC,CAAC,CAAA;AACvE;;;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const mergeUint8 = (...inputs) => {
|
|
2
|
+
const totalLen = inputs.reduce((acc, a) => acc + a.byteLength, 0);
|
|
3
|
+
const result = new Uint8Array(totalLen);
|
|
4
|
+
for (let idx = 0, at = 0; idx < inputs.length; idx++) {
|
|
5
|
+
const current = inputs[idx];
|
|
6
|
+
result.set(current, at);
|
|
7
|
+
at += current.byteLength;
|
|
8
|
+
}
|
|
9
|
+
return result;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { mergeUint8 };
|
|
13
|
+
//# sourceMappingURL=mergeUint8.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mergeUint8.mjs","sources":["../../src/mergeUint8.ts"],"sourcesContent":["export const mergeUint8 = (...inputs: Array<Uint8Array>): Uint8Array => {\n const totalLen = inputs.reduce((acc, a) => acc + a.byteLength, 0)\n const result = new Uint8Array(totalLen)\n\n for (let idx = 0, at = 0; idx < inputs.length; idx++) {\n const current = inputs[idx]\n result.set(current, at)\n at += current.byteLength\n }\n\n return result\n}\n"],"names":[],"mappings":"AAAa,MAAA,UAAA,GAAa,IAAI,MAA0C,KAAA;AACtE,EAAM,MAAA,QAAA,GAAW,OAAO,MAAO,CAAA,CAAC,KAAK,CAAM,KAAA,GAAA,GAAM,CAAE,CAAA,UAAA,EAAY,CAAC,CAAA,CAAA;AAChE,EAAM,MAAA,MAAA,GAAS,IAAI,UAAA,CAAW,QAAQ,CAAA,CAAA;AAEtC,EAAA,KAAA,IAAS,MAAM,CAAG,EAAA,EAAA,GAAK,GAAG,GAAM,GAAA,MAAA,CAAO,QAAQ,GAAO,EAAA,EAAA;AACpD,IAAM,MAAA,OAAA,GAAU,OAAO,GAAG,CAAA,CAAA;AAC1B,IAAO,MAAA,CAAA,GAAA,CAAI,SAAS,EAAE,CAAA,CAAA;AACtB,IAAA,EAAA,IAAM,OAAQ,CAAA,UAAA,CAAA;AAAA,GAChB;AAEA,EAAO,OAAA,MAAA,CAAA;AACT;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noop.mjs","sources":["../../src/noop.ts"],"sourcesContent":["export const noop: () => void = Function.prototype as any\n"],"names":[],"mappings":"AAAO,MAAM,OAAmB,QAAS,CAAA;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -1,38 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
AbortError: () => AbortError,
|
|
24
|
-
filterObject: () => filterObject,
|
|
25
|
-
fromHex: () => fromHex,
|
|
26
|
-
mapObject: () => mapObject,
|
|
27
|
-
mapStringRecord: () => mapStringRecord,
|
|
28
|
-
mergeUint8: () => mergeUint8,
|
|
29
|
-
noop: () => noop,
|
|
30
|
-
toHex: () => toHex
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(src_exports);
|
|
1
|
+
'use strict';
|
|
33
2
|
|
|
34
|
-
|
|
35
|
-
var HEX_STR = "0123456789abcdef";
|
|
3
|
+
const HEX_STR = "0123456789abcdef";
|
|
36
4
|
function toHex(bytes) {
|
|
37
5
|
const result = new Array(bytes.length + 1);
|
|
38
6
|
result[0] = "0x";
|
|
@@ -42,7 +10,7 @@ function toHex(bytes) {
|
|
|
42
10
|
}
|
|
43
11
|
return result.join("");
|
|
44
12
|
}
|
|
45
|
-
|
|
13
|
+
const HEX_MAP = {
|
|
46
14
|
0: 0,
|
|
47
15
|
1: 1,
|
|
48
16
|
2: 2,
|
|
@@ -71,8 +39,7 @@ function fromHex(hexString) {
|
|
|
71
39
|
const base = (hexString[1] === "x" ? 2 : 0) + isOdd;
|
|
72
40
|
const nBytes = (hexString.length - base) / 2 + isOdd;
|
|
73
41
|
const bytes = new Uint8Array(nBytes);
|
|
74
|
-
if (isOdd)
|
|
75
|
-
bytes[0] = 0 | HEX_MAP[hexString[2]];
|
|
42
|
+
if (isOdd) bytes[0] = 0 | HEX_MAP[hexString[2]];
|
|
76
43
|
for (let i = 0; i < nBytes; ) {
|
|
77
44
|
const idx = base + i * 2;
|
|
78
45
|
const a = HEX_MAP[hexString[idx]];
|
|
@@ -82,7 +49,6 @@ function fromHex(hexString) {
|
|
|
82
49
|
return bytes;
|
|
83
50
|
}
|
|
84
51
|
|
|
85
|
-
// src/mapObject.ts
|
|
86
52
|
function mapObject(input, mapper) {
|
|
87
53
|
return Object.fromEntries(
|
|
88
54
|
Object.entries(input).map(
|
|
@@ -90,19 +56,17 @@ function mapObject(input, mapper) {
|
|
|
90
56
|
)
|
|
91
57
|
);
|
|
92
58
|
}
|
|
93
|
-
|
|
59
|
+
const mapStringRecord = (input, mapper) => Object.fromEntries(
|
|
94
60
|
Object.entries(input).map(([key, value]) => [key, mapper(value, key)])
|
|
95
61
|
);
|
|
96
62
|
|
|
97
|
-
// src/filterObject.ts
|
|
98
63
|
function filterObject(input, filterFn) {
|
|
99
64
|
return Object.fromEntries(
|
|
100
65
|
Object.entries(input).filter(([key, value]) => filterFn(value, key))
|
|
101
66
|
);
|
|
102
67
|
}
|
|
103
68
|
|
|
104
|
-
|
|
105
|
-
var mergeUint8 = (...inputs) => {
|
|
69
|
+
const mergeUint8 = (...inputs) => {
|
|
106
70
|
const totalLen = inputs.reduce((acc, a) => acc + a.byteLength, 0);
|
|
107
71
|
const result = new Uint8Array(totalLen);
|
|
108
72
|
for (let idx = 0, at = 0; idx < inputs.length; idx++) {
|
|
@@ -113,14 +77,21 @@ var mergeUint8 = (...inputs) => {
|
|
|
113
77
|
return result;
|
|
114
78
|
};
|
|
115
79
|
|
|
116
|
-
|
|
117
|
-
var noop = Function.prototype;
|
|
80
|
+
const noop = Function.prototype;
|
|
118
81
|
|
|
119
|
-
|
|
120
|
-
var AbortError = class extends Error {
|
|
82
|
+
class AbortError extends Error {
|
|
121
83
|
constructor() {
|
|
122
84
|
super("Abort Error");
|
|
123
85
|
this.name = "AbortError";
|
|
124
86
|
}
|
|
125
|
-
}
|
|
126
|
-
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
exports.AbortError = AbortError;
|
|
90
|
+
exports.filterObject = filterObject;
|
|
91
|
+
exports.fromHex = fromHex;
|
|
92
|
+
exports.mapObject = mapObject;
|
|
93
|
+
exports.mapStringRecord = mapStringRecord;
|
|
94
|
+
exports.mergeUint8 = mergeUint8;
|
|
95
|
+
exports.noop = noop;
|
|
96
|
+
exports.toHex = toHex;
|
|
97
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/hex.ts","../src/mapObject.ts","../src/filterObject.ts","../src/mergeUint8.ts","../src/noop.ts","../src/AbortError.ts"],"sourcesContent":["// https://jsben.ch/uWZw3\nconst HEX_STR = \"0123456789abcdef\"\nexport function toHex(bytes: Uint8Array): string {\n const result = new Array<string>(bytes.length + 1)\n\n result[0] = \"0x\"\n\n for (let i = 0; i < bytes.length; ) {\n const b = bytes[i++]\n result[i] = HEX_STR[b >> 4] + HEX_STR[b & 15]\n }\n\n return result.join(\"\")\n}\n\n// https://jsben.ch/URe1X\nconst HEX_MAP: Record<string, number> = {\n 0: 0,\n 1: 1,\n 2: 2,\n 3: 3,\n 4: 4,\n 5: 5,\n 6: 6,\n 7: 7,\n 8: 8,\n 9: 9,\n a: 10,\n b: 11,\n c: 12,\n d: 13,\n e: 14,\n f: 15,\n A: 10,\n B: 11,\n C: 12,\n D: 13,\n E: 14,\n F: 15,\n}\nexport function fromHex(hexString: string): Uint8Array {\n const isOdd = hexString.length % 2\n const base = (hexString[1] === \"x\" ? 2 : 0) + isOdd\n const nBytes = (hexString.length - base) / 2 + isOdd\n const bytes = new Uint8Array(nBytes)\n\n if (isOdd) bytes[0] = 0 | HEX_MAP[hexString[2]]\n\n for (let i = 0; i < nBytes; ) {\n const idx = base + i * 2\n const a = HEX_MAP[hexString[idx]]\n const b = HEX_MAP[hexString[idx + 1]]\n bytes[isOdd + i++] = (a << 4) | b\n }\n\n return bytes\n}\n","export function mapObject<K extends string | number | symbol, I, O>(\n input: Record<K, I>,\n mapper: (i: I, k: K) => O,\n): Record<K, O>\n\nexport function mapObject<K extends string | number | symbol, I, O>(\n input: Record<K, I>,\n mapper: (i: I, k?: K) => O,\n): Record<K, O> {\n return Object.fromEntries(\n Object.entries(input).map(\n ([key, value]: any) => [key, mapper(value, key)] as const,\n ),\n ) as any\n}\n\nexport type StringRecord<T> = {\n [Sym: symbol]: never\n [Num: number]: never\n [Str: string]: T\n}\n\nexport const mapStringRecord = <I, O>(\n input: StringRecord<I>,\n mapper: (value: I, key: string) => O,\n): StringRecord<O> =>\n Object.fromEntries(\n Object.entries(input).map(([key, value]) => [key, mapper(value, key)]),\n ) as StringRecord<O>\n","export function filterObject<K extends string | number | symbol, I>(\n input: Record<K, I>,\n filterFn: (i: I, k: K) => boolean,\n): Record<K, I> {\n return Object.fromEntries(\n Object.entries(input).filter(([key, value]: any) => filterFn(value, key)),\n ) as any\n}\n","export const mergeUint8 = (...inputs: Array<Uint8Array>): Uint8Array => {\n const totalLen = inputs.reduce((acc, a) => acc + a.byteLength, 0)\n const result = new Uint8Array(totalLen)\n\n for (let idx = 0, at = 0; idx < inputs.length; idx++) {\n const current = inputs[idx]\n result.set(current, at)\n at += current.byteLength\n }\n\n return result\n}\n","export const noop: () => void = Function.prototype as any\n","export class AbortError extends Error {\n constructor() {\n super(\"Abort Error\")\n this.name = \"AbortError\"\n }\n}\n"],"names":[],"mappings":";;AACA,MAAM,OAAU,GAAA,kBAAA,CAAA;AACT,SAAS,MAAM,KAA2B,EAAA;AAC/C,EAAA,MAAM,MAAS,GAAA,IAAI,KAAc,CAAA,KAAA,CAAM,SAAS,CAAC,CAAA,CAAA;AAEjD,EAAA,MAAA,CAAO,CAAC,CAAI,GAAA,IAAA,CAAA;AAEZ,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,KAAA,CAAM,MAAU,IAAA;AAClC,IAAM,MAAA,CAAA,GAAI,MAAM,CAAG,EAAA,CAAA,CAAA;AACnB,IAAO,MAAA,CAAA,CAAC,IAAI,OAAQ,CAAA,CAAA,IAAK,CAAC,CAAI,GAAA,OAAA,CAAQ,IAAI,EAAE,CAAA,CAAA;AAAA,GAC9C;AAEA,EAAO,OAAA,MAAA,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KAAA;AACtE,EAAM,MAAA,QAAA,GAAW,OAAO,MAAO,CAAA,CAAC,KAAK,CAAM,KAAA,GAAA,GAAM,CAAE,CAAA,UAAA,EAAY,CAAC,CAAA,CAAA;AAChE,EAAM,MAAA,MAAA,GAAS,IAAI,UAAA,CAAW,QAAQ,CAAA,CAAA;AAEtC,EAAA,KAAA,IAAS,MAAM,CAAG,EAAA,EAAA,GAAK,GAAG,GAAM,GAAA,MAAA,CAAO,QAAQ,GAAO,EAAA,EAAA;AACpD,IAAM,MAAA,OAAA,GAAU,OAAO,GAAG,CAAA,CAAA;AAC1B,IAAO,MAAA,CAAA,GAAA,CAAI,SAAS,EAAE,CAAA,CAAA;AACtB,IAAA,EAAA,IAAM,OAAQ,CAAA,UAAA,CAAA;AAAA,GAChB;AAEA,EAAO,OAAA,MAAA,CAAA;AACT;;ACXO,MAAM,OAAmB,QAAS,CAAA;;ACAlC,MAAM,mBAAmB,KAAM,CAAA;AAAA,EACpC,WAAc,GAAA;AACZ,IAAA,KAAA,CAAM,aAAa,CAAA,CAAA;AACnB,IAAA,IAAA,CAAK,IAAO,GAAA,YAAA,CAAA;AAAA,GACd;AACF;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polkadot-api/utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"author": "Josep M Sobrepere (https://github.com/josepot)",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,30 +12,31 @@
|
|
|
12
12
|
".": {
|
|
13
13
|
"node": {
|
|
14
14
|
"production": {
|
|
15
|
-
"import": "./dist/index.mjs",
|
|
15
|
+
"import": "./dist/esm/index.mjs",
|
|
16
16
|
"require": "./dist/min/index.js",
|
|
17
17
|
"default": "./dist/index.js"
|
|
18
18
|
},
|
|
19
|
-
"import": "./dist/index.mjs",
|
|
19
|
+
"import": "./dist/esm/index.mjs",
|
|
20
20
|
"require": "./dist/index.js",
|
|
21
21
|
"default": "./dist/index.js"
|
|
22
22
|
},
|
|
23
|
-
"module": "./dist/index.mjs",
|
|
24
|
-
"import": "./dist/index.mjs",
|
|
23
|
+
"module": "./dist/esm/index.mjs",
|
|
24
|
+
"import": "./dist/esm/index.mjs",
|
|
25
25
|
"require": "./dist/index.js",
|
|
26
26
|
"default": "./dist/index.js"
|
|
27
27
|
},
|
|
28
28
|
"./package.json": "./package.json"
|
|
29
29
|
},
|
|
30
30
|
"main": "./dist/index.js",
|
|
31
|
-
"module": "./dist/index.mjs",
|
|
32
|
-
"browser": "./dist/index.mjs",
|
|
31
|
+
"module": "./dist/esm/index.mjs",
|
|
32
|
+
"browser": "./dist/esm/index.mjs",
|
|
33
33
|
"types": "./dist/index.d.ts",
|
|
34
34
|
"files": [
|
|
35
35
|
"dist"
|
|
36
36
|
],
|
|
37
37
|
"scripts": {
|
|
38
|
-
"build": "tsc --noEmit &&
|
|
38
|
+
"build-core": "tsc --noEmit && rollup -c ../../rollup.config.js",
|
|
39
|
+
"build": "pnpm build-core",
|
|
39
40
|
"test": "echo 'no tests'",
|
|
40
41
|
"lint": "prettier --check README.md \"src/**/*.{js,jsx,ts,tsx,json,md}\"",
|
|
41
42
|
"format": "prettier --write README.md \"src/**/*.{js,jsx,ts,tsx,json,md}\""
|
package/dist/index.d.mts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
declare function toHex(bytes: Uint8Array): string;
|
|
2
|
-
declare function fromHex(hexString: string): Uint8Array;
|
|
3
|
-
|
|
4
|
-
declare function mapObject<K extends string | number | symbol, I, O>(input: Record<K, I>, mapper: (i: I, k: K) => O): Record<K, O>;
|
|
5
|
-
type StringRecord<T> = {
|
|
6
|
-
[Sym: symbol]: never;
|
|
7
|
-
[Num: number]: never;
|
|
8
|
-
[Str: string]: T;
|
|
9
|
-
};
|
|
10
|
-
declare const mapStringRecord: <I, O>(input: StringRecord<I>, mapper: (value: I, key: string) => O) => StringRecord<O>;
|
|
11
|
-
|
|
12
|
-
declare function filterObject<K extends string | number | symbol, I>(input: Record<K, I>, filterFn: (i: I, k: K) => boolean): Record<K, I>;
|
|
13
|
-
|
|
14
|
-
declare const mergeUint8: (...inputs: Array<Uint8Array>) => Uint8Array;
|
|
15
|
-
|
|
16
|
-
declare const noop: () => void;
|
|
17
|
-
|
|
18
|
-
declare class AbortError extends Error {
|
|
19
|
-
constructor();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export { AbortError, filterObject, fromHex, mapObject, mapStringRecord, mergeUint8, noop, toHex };
|
package/dist/index.mjs
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
// src/hex.ts
|
|
2
|
-
var HEX_STR = "0123456789abcdef";
|
|
3
|
-
function toHex(bytes) {
|
|
4
|
-
const result = new Array(bytes.length + 1);
|
|
5
|
-
result[0] = "0x";
|
|
6
|
-
for (let i = 0; i < bytes.length; ) {
|
|
7
|
-
const b = bytes[i++];
|
|
8
|
-
result[i] = HEX_STR[b >> 4] + HEX_STR[b & 15];
|
|
9
|
-
}
|
|
10
|
-
return result.join("");
|
|
11
|
-
}
|
|
12
|
-
var HEX_MAP = {
|
|
13
|
-
0: 0,
|
|
14
|
-
1: 1,
|
|
15
|
-
2: 2,
|
|
16
|
-
3: 3,
|
|
17
|
-
4: 4,
|
|
18
|
-
5: 5,
|
|
19
|
-
6: 6,
|
|
20
|
-
7: 7,
|
|
21
|
-
8: 8,
|
|
22
|
-
9: 9,
|
|
23
|
-
a: 10,
|
|
24
|
-
b: 11,
|
|
25
|
-
c: 12,
|
|
26
|
-
d: 13,
|
|
27
|
-
e: 14,
|
|
28
|
-
f: 15,
|
|
29
|
-
A: 10,
|
|
30
|
-
B: 11,
|
|
31
|
-
C: 12,
|
|
32
|
-
D: 13,
|
|
33
|
-
E: 14,
|
|
34
|
-
F: 15
|
|
35
|
-
};
|
|
36
|
-
function fromHex(hexString) {
|
|
37
|
-
const isOdd = hexString.length % 2;
|
|
38
|
-
const base = (hexString[1] === "x" ? 2 : 0) + isOdd;
|
|
39
|
-
const nBytes = (hexString.length - base) / 2 + isOdd;
|
|
40
|
-
const bytes = new Uint8Array(nBytes);
|
|
41
|
-
if (isOdd)
|
|
42
|
-
bytes[0] = 0 | HEX_MAP[hexString[2]];
|
|
43
|
-
for (let i = 0; i < nBytes; ) {
|
|
44
|
-
const idx = base + i * 2;
|
|
45
|
-
const a = HEX_MAP[hexString[idx]];
|
|
46
|
-
const b = HEX_MAP[hexString[idx + 1]];
|
|
47
|
-
bytes[isOdd + i++] = a << 4 | b;
|
|
48
|
-
}
|
|
49
|
-
return bytes;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// src/mapObject.ts
|
|
53
|
-
function mapObject(input, mapper) {
|
|
54
|
-
return Object.fromEntries(
|
|
55
|
-
Object.entries(input).map(
|
|
56
|
-
([key, value]) => [key, mapper(value, key)]
|
|
57
|
-
)
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
var mapStringRecord = (input, mapper) => Object.fromEntries(
|
|
61
|
-
Object.entries(input).map(([key, value]) => [key, mapper(value, key)])
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
// src/filterObject.ts
|
|
65
|
-
function filterObject(input, filterFn) {
|
|
66
|
-
return Object.fromEntries(
|
|
67
|
-
Object.entries(input).filter(([key, value]) => filterFn(value, key))
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// src/mergeUint8.ts
|
|
72
|
-
var mergeUint8 = (...inputs) => {
|
|
73
|
-
const totalLen = inputs.reduce((acc, a) => acc + a.byteLength, 0);
|
|
74
|
-
const result = new Uint8Array(totalLen);
|
|
75
|
-
for (let idx = 0, at = 0; idx < inputs.length; idx++) {
|
|
76
|
-
const current = inputs[idx];
|
|
77
|
-
result.set(current, at);
|
|
78
|
-
at += current.byteLength;
|
|
79
|
-
}
|
|
80
|
-
return result;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
// src/noop.ts
|
|
84
|
-
var noop = Function.prototype;
|
|
85
|
-
|
|
86
|
-
// src/AbortError.ts
|
|
87
|
-
var AbortError = class extends Error {
|
|
88
|
-
constructor() {
|
|
89
|
-
super("Abort Error");
|
|
90
|
-
this.name = "AbortError";
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
export {
|
|
94
|
-
AbortError,
|
|
95
|
-
filterObject,
|
|
96
|
-
fromHex,
|
|
97
|
-
mapObject,
|
|
98
|
-
mapStringRecord,
|
|
99
|
-
mergeUint8,
|
|
100
|
-
noop,
|
|
101
|
-
toHex
|
|
102
|
-
};
|
|
103
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hex.ts","../src/mapObject.ts","../src/filterObject.ts","../src/mergeUint8.ts","../src/noop.ts","../src/AbortError.ts"],"sourcesContent":["// https://jsben.ch/uWZw3\nconst HEX_STR = \"0123456789abcdef\"\nexport function toHex(bytes: Uint8Array): string {\n const result = new Array<string>(bytes.length + 1)\n\n result[0] = \"0x\"\n\n for (let i = 0; i < bytes.length; ) {\n const b = bytes[i++]\n result[i] = HEX_STR[b >> 4] + HEX_STR[b & 15]\n }\n\n return result.join(\"\")\n}\n\n// https://jsben.ch/URe1X\nconst HEX_MAP: Record<string, number> = {\n 0: 0,\n 1: 1,\n 2: 2,\n 3: 3,\n 4: 4,\n 5: 5,\n 6: 6,\n 7: 7,\n 8: 8,\n 9: 9,\n a: 10,\n b: 11,\n c: 12,\n d: 13,\n e: 14,\n f: 15,\n A: 10,\n B: 11,\n C: 12,\n D: 13,\n E: 14,\n F: 15,\n}\nexport function fromHex(hexString: string): Uint8Array {\n const isOdd = hexString.length % 2\n const base = (hexString[1] === \"x\" ? 2 : 0) + isOdd\n const nBytes = (hexString.length - base) / 2 + isOdd\n const bytes = new Uint8Array(nBytes)\n\n if (isOdd) bytes[0] = 0 | HEX_MAP[hexString[2]]\n\n for (let i = 0; i < nBytes; ) {\n const idx = base + i * 2\n const a = HEX_MAP[hexString[idx]]\n const b = HEX_MAP[hexString[idx + 1]]\n bytes[isOdd + i++] = (a << 4) | b\n }\n\n return bytes\n}\n","export function mapObject<K extends string | number | symbol, I, O>(\n input: Record<K, I>,\n mapper: (i: I, k: K) => O,\n): Record<K, O>\n\nexport function mapObject<K extends string | number | symbol, I, O>(\n input: Record<K, I>,\n mapper: (i: I, k?: K) => O,\n): Record<K, O> {\n return Object.fromEntries(\n Object.entries(input).map(\n ([key, value]: any) => [key, mapper(value, key)] as const,\n ),\n ) as any\n}\n\nexport type StringRecord<T> = {\n [Sym: symbol]: never\n [Num: number]: never\n [Str: string]: T\n}\n\nexport const mapStringRecord = <I, O>(\n input: StringRecord<I>,\n mapper: (value: I, key: string) => O,\n): StringRecord<O> =>\n Object.fromEntries(\n Object.entries(input).map(([key, value]) => [key, mapper(value, key)]),\n ) as StringRecord<O>\n","export function filterObject<K extends string | number | symbol, I>(\n input: Record<K, I>,\n filterFn: (i: I, k: K) => boolean,\n): Record<K, I> {\n return Object.fromEntries(\n Object.entries(input).filter(([key, value]: any) => filterFn(value, key)),\n ) as any\n}\n","export const mergeUint8 = (...inputs: Array<Uint8Array>): Uint8Array => {\n const totalLen = inputs.reduce((acc, a) => acc + a.byteLength, 0)\n const result = new Uint8Array(totalLen)\n\n for (let idx = 0, at = 0; idx < inputs.length; idx++) {\n const current = inputs[idx]\n result.set(current, at)\n at += current.byteLength\n }\n\n return result\n}\n","export const noop: () => void = Function.prototype as any\n","export class AbortError extends Error {\n constructor() {\n super(\"Abort Error\")\n this.name = \"AbortError\"\n }\n}\n"],"mappings":";AACA,IAAM,UAAU;AACT,SAAS,MAAM,OAA2B;AAC/C,QAAM,SAAS,IAAI,MAAc,MAAM,SAAS,CAAC;AAEjD,SAAO,CAAC,IAAI;AAEZ,WAAS,IAAI,GAAG,IAAI,MAAM,UAAU;AAClC,UAAM,IAAI,MAAM,GAAG;AACnB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A,OAAO;AAAA,EACL,OAAO,QAAQ,KAAK,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,KAAK,OAAO,OAAO,GAAG,CAAC,CAAC;AACvE;;;AC5BK,SAAS,aACd,OACA,UACc;AACd,SAAO,OAAO;AAAA,IACZ,OAAO,QAAQ,KAAK,EAAE,OAAO,CAAC,CAAC,KAAK,KAAK,MAAW,SAAS,OAAO,GAAG,CAAC;AAAA,EAC1E;AACF;;;ACPO,IAAM,aAAa,IAAI,WAA0C;AACtE,QAAM,WAAW,OAAO,OAAO,CAAC,KAAK,MAAM,MAAM,EAAE,YAAY,CAAC;AAChE,QAAM,SAAS,IAAI,WAAW,QAAQ;AAEtC,WAAS,MAAM,GAAG,KAAK,GAAG,MAAM,OAAO,QAAQ,OAAO;AACpD,UAAM,UAAU,OAAO,GAAG;AAC1B,WAAO,IAAI,SAAS,EAAE;AACtB,UAAM,QAAQ;AAAA,EAChB;AAEA,SAAO;AACT;;;ACXO,IAAM,OAAmB,SAAS;;;ACAlC,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,cAAc;AACZ,UAAM,aAAa;AACnB,SAAK,OAAO;AAAA,EACd;AACF;","names":[]}
|
package/dist/min/index.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
declare function toHex(bytes: Uint8Array): string;
|
|
2
|
-
declare function fromHex(hexString: string): Uint8Array;
|
|
3
|
-
|
|
4
|
-
declare function mapObject<K extends string | number | symbol, I, O>(input: Record<K, I>, mapper: (i: I, k: K) => O): Record<K, O>;
|
|
5
|
-
type StringRecord<T> = {
|
|
6
|
-
[Sym: symbol]: never;
|
|
7
|
-
[Num: number]: never;
|
|
8
|
-
[Str: string]: T;
|
|
9
|
-
};
|
|
10
|
-
declare const mapStringRecord: <I, O>(input: StringRecord<I>, mapper: (value: I, key: string) => O) => StringRecord<O>;
|
|
11
|
-
|
|
12
|
-
declare function filterObject<K extends string | number | symbol, I>(input: Record<K, I>, filterFn: (i: I, k: K) => boolean): Record<K, I>;
|
|
13
|
-
|
|
14
|
-
declare const mergeUint8: (...inputs: Array<Uint8Array>) => Uint8Array;
|
|
15
|
-
|
|
16
|
-
declare const noop: () => void;
|
|
17
|
-
|
|
18
|
-
declare class AbortError extends Error {
|
|
19
|
-
constructor();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export { AbortError, filterObject, fromHex, mapObject, mapStringRecord, mergeUint8, noop, toHex };
|
package/dist/min/index.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var i=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var j=Object.prototype.hasOwnProperty;var A=(r,t)=>{for(var e in t)i(r,e,{get:t[e],enumerable:!0})},K=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of I(t))!j.call(r,o)&&o!==e&&i(r,o,{get:()=>t[o],enumerable:!(n=R(t,o))||n.enumerable});return r};var E=r=>K(i({},"__esModule",{value:!0}),r);var U={};A(U,{AbortError:()=>s,filterObject:()=>x,fromHex:()=>d,mapObject:()=>f,mapStringRecord:()=>u,mergeUint8:()=>O,noop:()=>l,toHex:()=>b});module.exports=E(U);var p="0123456789abcdef";function b(r){let t=new Array(r.length+1);t[0]="0x";for(let e=0;e<r.length;){let n=r[e++];t[e]=p[n>>4]+p[n&15]}return t.join("")}var a={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,a:10,b:11,c:12,d:13,e:14,f:15,A:10,B:11,C:12,D:13,E:14,F:15};function d(r){let t=r.length%2,e=(r[1]==="x"?2:0)+t,n=(r.length-e)/2+t,o=new Uint8Array(n);t&&(o[0]=0|a[r[2]]);for(let c=0;c<n;){let m=e+c*2,y=a[r[m]],g=a[r[m+1]];o[t+c++]=y<<4|g}return o}function f(r,t){return Object.fromEntries(Object.entries(r).map(([e,n])=>[e,t(n,e)]))}var u=(r,t)=>Object.fromEntries(Object.entries(r).map(([e,n])=>[e,t(n,e)]));function x(r,t){return Object.fromEntries(Object.entries(r).filter(([e,n])=>t(n,e)))}var O=(...r)=>{let t=r.reduce((n,o)=>n+o.byteLength,0),e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let c=r[n];e.set(c,o),o+=c.byteLength}return e};var l=Function.prototype;var s=class extends Error{constructor(){super("Abort Error"),this.name="AbortError"}};
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
package/dist/min/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/hex.ts","../../src/mapObject.ts","../../src/filterObject.ts","../../src/mergeUint8.ts","../../src/noop.ts","../../src/AbortError.ts"],"sourcesContent":["export { fromHex, toHex } from \"./hex\"\nexport { mapObject, mapStringRecord } from \"./mapObject\"\nexport { filterObject } from \"./filterObject\"\nexport { mergeUint8 } from \"./mergeUint8\"\nexport { noop } from \"./noop\"\nexport { AbortError } from \"./AbortError\"\n","// https://jsben.ch/uWZw3\nconst HEX_STR = \"0123456789abcdef\"\nexport function toHex(bytes: Uint8Array): string {\n const result = new Array<string>(bytes.length + 1)\n\n result[0] = \"0x\"\n\n for (let i = 0; i < bytes.length; ) {\n const b = bytes[i++]\n result[i] = HEX_STR[b >> 4] + HEX_STR[b & 15]\n }\n\n return result.join(\"\")\n}\n\n// https://jsben.ch/URe1X\nconst HEX_MAP: Record<string, number> = {\n 0: 0,\n 1: 1,\n 2: 2,\n 3: 3,\n 4: 4,\n 5: 5,\n 6: 6,\n 7: 7,\n 8: 8,\n 9: 9,\n a: 10,\n b: 11,\n c: 12,\n d: 13,\n e: 14,\n f: 15,\n A: 10,\n B: 11,\n C: 12,\n D: 13,\n E: 14,\n F: 15,\n}\nexport function fromHex(hexString: string): Uint8Array {\n const isOdd = hexString.length % 2\n const base = (hexString[1] === \"x\" ? 2 : 0) + isOdd\n const nBytes = (hexString.length - base) / 2 + isOdd\n const bytes = new Uint8Array(nBytes)\n\n if (isOdd) bytes[0] = 0 | HEX_MAP[hexString[2]]\n\n for (let i = 0; i < nBytes; ) {\n const idx = base + i * 2\n const a = HEX_MAP[hexString[idx]]\n const b = HEX_MAP[hexString[idx + 1]]\n bytes[isOdd + i++] = (a << 4) | b\n }\n\n return bytes\n}\n","export function mapObject<K extends string | number | symbol, I, O>(\n input: Record<K, I>,\n mapper: (i: I, k: K) => O,\n): Record<K, O>\n\nexport function mapObject<K extends string | number | symbol, I, O>(\n input: Record<K, I>,\n mapper: (i: I, k?: K) => O,\n): Record<K, O> {\n return Object.fromEntries(\n Object.entries(input).map(\n ([key, value]: any) => [key, mapper(value, key)] as const,\n ),\n ) as any\n}\n\nexport type StringRecord<T> = {\n [Sym: symbol]: never\n [Num: number]: never\n [Str: string]: T\n}\n\nexport const mapStringRecord = <I, O>(\n input: StringRecord<I>,\n mapper: (value: I, key: string) => O,\n): StringRecord<O> =>\n Object.fromEntries(\n Object.entries(input).map(([key, value]) => [key, mapper(value, key)]),\n ) as StringRecord<O>\n","export function filterObject<K extends string | number | symbol, I>(\n input: Record<K, I>,\n filterFn: (i: I, k: K) => boolean,\n): Record<K, I> {\n return Object.fromEntries(\n Object.entries(input).filter(([key, value]: any) => filterFn(value, key)),\n ) as any\n}\n","export const mergeUint8 = (...inputs: Array<Uint8Array>): Uint8Array => {\n const totalLen = inputs.reduce((acc, a) => acc + a.byteLength, 0)\n const result = new Uint8Array(totalLen)\n\n for (let idx = 0, at = 0; idx < inputs.length; idx++) {\n const current = inputs[idx]\n result.set(current, at)\n at += current.byteLength\n }\n\n return result\n}\n","export const noop: () => void = Function.prototype as any\n","export class AbortError extends Error {\n constructor() {\n super(\"Abort Error\")\n this.name = \"AbortError\"\n }\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gBAAAE,EAAA,iBAAAC,EAAA,YAAAC,EAAA,cAAAC,EAAA,oBAAAC,EAAA,eAAAC,EAAA,SAAAC,EAAA,UAAAC,IAAA,eAAAC,EAAAV,GCCA,IA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,CAQO,IAAME,EAAkB,CAC7BJ,EACAC,IAEA,OAAO,YACL,OAAO,QAAQD,CAAK,EAAE,IAAI,CAAC,CAACE,EAAKC,CAAK,IAAM,CAACD,EAAKD,EAAOE,EAAOD,CAAG,CAAC,CAAC,CACvE,EC5BK,SAASG,EACdC,EACAC,EACc,CACd,OAAO,OAAO,YACZ,OAAO,QAAQD,CAAK,EAAE,OAAO,CAAC,CAACE,EAAKC,CAAK,IAAWF,EAASE,EAAOD,CAAG,CAAC,CAC1E,CACF,CCPO,IAAME,EAAa,IAAIC,IAA0C,CACtE,IAAMC,EAAWD,EAAO,OAAO,CAACE,EAAKC,IAAMD,EAAMC,EAAE,WAAY,CAAC,EAC1DC,EAAS,IAAI,WAAWH,CAAQ,EAEtC,QAASI,EAAM,EAAGC,EAAK,EAAGD,EAAML,EAAO,OAAQK,IAAO,CACpD,IAAME,EAAUP,EAAOK,CAAG,EAC1BD,EAAO,IAAIG,EAASD,CAAE,EACtBA,GAAMC,EAAQ,UAChB,CAEA,OAAOH,CACT,ECXO,IAAMI,EAAmB,SAAS,UCAlC,IAAMC,EAAN,cAAyB,KAAM,CACpC,aAAc,CACZ,MAAM,aAAa,EACnB,KAAK,KAAO,YACd,CACF","names":["src_exports","__export","AbortError","filterObject","fromHex","mapObject","mapStringRecord","mergeUint8","noop","toHex","__toCommonJS","HEX_STR","toHex","bytes","result","i","b","HEX_MAP","fromHex","hexString","isOdd","base","nBytes","idx","a","mapObject","input","mapper","key","value","mapStringRecord","filterObject","input","filterFn","key","value","mergeUint8","inputs","totalLen","acc","a","result","idx","at","current","noop","AbortError"]}
|