mirror of
https://github.com/pezkuwichain/pezkuwi-api.git
synced 2026-04-22 05:37:58 +00:00
feat: add PAPI rebrand packages
- @pezkuwi/papi-utils (rebrand of @polkadot-api/utils) - @pezkuwi/bizinikiwi-bindings (rebrand of @polkadot-api/substrate-bindings) - @pezkuwi/metadata-builders (rebrand of @polkadot-api/metadata-builders) - @pezkuwi/merkleize-metadata (rebrand of @polkadot-api/merkleize-metadata) All @polkadot-api references replaced with @pezkuwi equivalents.
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 Josep M Sobrepere
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1 @@
|
||||
# @polkadot-api/utils
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
class AbortError extends Error {
|
||||
constructor() {
|
||||
super("Abort Error");
|
||||
this.name = "AbortError";
|
||||
}
|
||||
}
|
||||
|
||||
export { AbortError };
|
||||
//# sourceMappingURL=AbortError.mjs.map
|
||||
@@ -0,0 +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;AACnB,IAAA,IAAA,CAAK,IAAO,GAAA,YAAA;AAAA;AAEhB;;;;"}
|
||||
@@ -0,0 +1,8 @@
|
||||
function filterObject(input, filterFn) {
|
||||
return Object.fromEntries(
|
||||
Object.entries(input).filter(([key, value]) => filterFn(value, key))
|
||||
);
|
||||
}
|
||||
|
||||
export { filterObject };
|
||||
//# sourceMappingURL=filterObject.mjs.map
|
||||
@@ -0,0 +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;AAAA,GAC1E;AACF;;;;"}
|
||||
Vendored
+51
@@ -0,0 +1,51 @@
|
||||
const HEX_STR = "0123456789abcdef";
|
||||
function toHex(bytes) {
|
||||
const result = new Array(bytes.length + 1);
|
||||
result[0] = "0x";
|
||||
for (let i = 0; i < bytes.length; ) {
|
||||
const b = bytes[i++];
|
||||
result[i] = HEX_STR[b >> 4] + HEX_STR[b & 15];
|
||||
}
|
||||
return result.join("");
|
||||
}
|
||||
const HEX_MAP = {
|
||||
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 fromHex(hexString) {
|
||||
const isOdd = hexString.length % 2;
|
||||
const base = (hexString[1] === "x" ? 2 : 0) + isOdd;
|
||||
const nBytes = (hexString.length - base) / 2 + isOdd;
|
||||
const bytes = new Uint8Array(nBytes);
|
||||
if (isOdd) bytes[0] = 0 | HEX_MAP[hexString[2]];
|
||||
for (let i = 0; i < nBytes; ) {
|
||||
const idx = base + i * 2;
|
||||
const a = HEX_MAP[hexString[idx]];
|
||||
const b = HEX_MAP[hexString[idx + 1]];
|
||||
bytes[isOdd + i++] = a << 4 | b;
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
export { fromHex, toHex };
|
||||
//# sourceMappingURL=hex.mjs.map
|
||||
+1
@@ -0,0 +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]]\n bytes[isOdd + i++] = (a << 4) | b\n }\n\n return bytes\n}\n"],"names":[],"mappings":"AACA,MAAM,OAAU,GAAA,kBAAA;AACT,SAAS,MAAM,KAA2B,EAAA;AAC/C,EAAA,MAAM,MAAS,GAAA,IAAI,KAAc,CAAA,KAAA,CAAM,SAAS,CAAC,CAAA;AAEjD,EAAA,MAAA,CAAO,CAAC,CAAI,GAAA,IAAA;AAEZ,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,KAAA,CAAM,MAAU,IAAA;AAClC,IAAM,MAAA,CAAA,GAAI,MAAM,CAAG,EAAA,CAAA;AACnB,IAAO,MAAA,CAAA,CAAC,IAAI,OAAQ,CAAA,CAAA,IAAK,CAAC,CAAI,GAAA,OAAA,CAAQ,IAAI,EAAE,CAAA;AAAA;AAG9C,EAAO,OAAA,MAAA,CAAO,KAAK,EAAE,CAAA;AACvB;AAGA,MAAM,OAAkC,GAAA;AAAA,EACtC,CAAG,EAAA,CAAA;AAAA,EACH,CAAG,EAAA,CAAA;AAAA,EACH,CAAG,EAAA,CAAA;AAAA,EACH,CAAG,EAAA,CAAA;AAAA,EACH,CAAG,EAAA,CAAA;AAAA,EACH,CAAG,EAAA,CAAA;AAAA,EACH,CAAG,EAAA,CAAA;AAAA,EACH,CAAG,EAAA,CAAA;AAAA,EACH,CAAG,EAAA,CAAA;AAAA,EACH,CAAG,EAAA,CAAA;AAAA,EACH,CAAG,EAAA,EAAA;AAAA,EACH,CAAG,EAAA,EAAA;AAAA,EACH,CAAG,EAAA,EAAA;AAAA,EACH,CAAG,EAAA,EAAA;AAAA,EACH,CAAG,EAAA,EAAA;AAAA,EACH,CAAG,EAAA,EAAA;AAAA,EACH,CAAG,EAAA,EAAA;AAAA,EACH,CAAG,EAAA,EAAA;AAAA,EACH,CAAG,EAAA,EAAA;AAAA,EACH,CAAG,EAAA,EAAA;AAAA,EACH,CAAG,EAAA,EAAA;AAAA,EACH,CAAG,EAAA;AACL,CAAA;AACO,SAAS,QAAQ,SAA+B,EAAA;AACrD,EAAM,MAAA,KAAA,GAAQ,UAAU,MAAS,GAAA,CAAA;AACjC,EAAA,MAAM,QAAQ,SAAU,CAAA,CAAC,CAAM,KAAA,GAAA,GAAM,IAAI,CAAK,IAAA,KAAA;AAC9C,EAAA,MAAM,MAAU,GAAA,CAAA,SAAA,CAAU,MAAS,GAAA,IAAA,IAAQ,CAAI,GAAA,KAAA;AAC/C,EAAM,MAAA,KAAA,GAAQ,IAAI,UAAA,CAAW,MAAM,CAAA;AAEnC,EAAI,IAAA,KAAA,QAAa,CAAC,CAAA,GAAI,IAAI,OAAQ,CAAA,SAAA,CAAU,CAAC,CAAC,CAAA;AAE9C,EAAS,KAAA,IAAA,CAAA,GAAI,CAAG,EAAA,CAAA,GAAI,MAAU,IAAA;AAC5B,IAAM,MAAA,GAAA,GAAM,OAAO,CAAI,GAAA,CAAA;AACvB,IAAA,MAAM,CAAI,GAAA,OAAA,CAAQ,SAAU,CAAA,GAAG,CAAC,CAAA;AAChC,IAAA,MAAM,CAAI,GAAA,OAAA,CAAQ,SAAU,CAAA,GAAA,GAAM,CAAC,CAAC,CAAA;AACpC,IAAA,KAAA,CAAM,KAAQ,GAAA,CAAA,EAAG,CAAK,GAAA,CAAA,IAAK,CAAK,GAAA,CAAA;AAAA;AAGlC,EAAO,OAAA,KAAA;AACT;;;;"}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
export { fromHex, toHex } from './hex.mjs';
|
||||
export { mapObject, mapStringRecord } from './mapObject.mjs';
|
||||
export { filterObject } from './filterObject.mjs';
|
||||
export { mergeUint8 } from './mergeUint8.mjs';
|
||||
export { noop } from './noop.mjs';
|
||||
export { AbortError } from './AbortError.mjs';
|
||||
export { jsonPrint } from './jsonPrint.mjs';
|
||||
//# sourceMappingURL=index.mjs.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
const jsonPrint = (value, indent = 2) => JSON.stringify(
|
||||
value,
|
||||
(_, v) => typeof v === "bigint" ? `${v}n` : typeof v === "object" && typeof v?.asHex === "function" ? v.asHex() : v,
|
||||
indent
|
||||
);
|
||||
|
||||
export { jsonPrint };
|
||||
//# sourceMappingURL=jsonPrint.mjs.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"jsonPrint.mjs","sources":["../../src/jsonPrint.ts"],"sourcesContent":["export const jsonPrint = (value: any, indent = 2) =>\n JSON.stringify(\n value,\n (_, v) =>\n typeof v === \"bigint\"\n ? `${v}n`\n : typeof v === \"object\" && typeof v?.asHex === \"function\"\n ? v.asHex()\n : v,\n indent,\n )\n"],"names":[],"mappings":"AAAO,MAAM,SAAY,GAAA,CAAC,KAAY,EAAA,MAAA,GAAS,MAC7C,IAAK,CAAA,SAAA;AAAA,EACH,KAAA;AAAA,EACA,CAAC,CAAG,EAAA,CAAA,KACF,OAAO,CAAM,KAAA,QAAA,GACT,GAAG,CAAC,CAAA,CAAA,CAAA,GACJ,OAAO,CAAA,KAAM,YAAY,OAAO,CAAA,EAAG,UAAU,UAC3C,GAAA,CAAA,CAAE,OACF,GAAA,CAAA;AAAA,EACR;AACF;;;;"}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
function mapObject(input, mapper) {
|
||||
return Object.fromEntries(
|
||||
Object.entries(input).map(
|
||||
([key, value]) => [key, mapper(value, key)]
|
||||
)
|
||||
);
|
||||
}
|
||||
const mapStringRecord = (input, mapper) => Object.fromEntries(
|
||||
Object.entries(input).map(([key, value]) => [key, mapper(value, key)])
|
||||
);
|
||||
|
||||
export { mapObject, mapStringRecord };
|
||||
//# sourceMappingURL=mapObject.mjs.map
|
||||
@@ -0,0 +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;AAAA;AACjD,GACF;AACF;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;AACvE;;;;"}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
const mergeUint8 = (...i) => {
|
||||
const inputs = Array.isArray(i[0]) ? i[0] : i;
|
||||
const totalLen = inputs.reduce((acc, a) => acc + a.byteLength, 0);
|
||||
const result = new Uint8Array(totalLen);
|
||||
for (let idx = 0, at = 0; idx < inputs.length; idx++) {
|
||||
const current = inputs[idx];
|
||||
result.set(current, at);
|
||||
at += current.byteLength;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
export { mergeUint8 };
|
||||
//# sourceMappingURL=mergeUint8.mjs.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"mergeUint8.mjs","sources":["../../src/mergeUint8.ts"],"sourcesContent":["// TODO: deprecate spread overload in papi v2\n\ninterface MergeUint8 {\n /**\n * @deprecated This overload will be removed in PAPI v2. Migrate as\n * follows:\n * mergeUint8(arr1, arr2) => mergeUint8([arr1, arr2])\n */\n (...inputs: Array<Uint8Array>): Uint8Array\n (inputs: Array<Uint8Array>): Uint8Array\n}\n\nexport const mergeUint8: MergeUint8 = (...i) => {\n const inputs = (Array.isArray(i[0]) ? i[0] : i) as 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":"AAYa,MAAA,UAAA,GAAyB,IAAI,CAAM,KAAA;AAC9C,EAAM,MAAA,MAAA,GAAU,MAAM,OAAQ,CAAA,CAAA,CAAE,CAAC,CAAC,CAAA,GAAI,CAAE,CAAA,CAAC,CAAI,GAAA,CAAA;AAC7C,EAAM,MAAA,QAAA,GAAW,OAAO,MAAO,CAAA,CAAC,KAAK,CAAM,KAAA,GAAA,GAAM,CAAE,CAAA,UAAA,EAAY,CAAC,CAAA;AAChE,EAAM,MAAA,MAAA,GAAS,IAAI,UAAA,CAAW,QAAQ,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;AAC1B,IAAO,MAAA,CAAA,GAAA,CAAI,SAAS,EAAE,CAAA;AACtB,IAAA,EAAA,IAAM,OAAQ,CAAA,UAAA;AAAA;AAGhB,EAAO,OAAA,MAAA;AACT;;;;"}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
const noop = Function.prototype;
|
||||
|
||||
export { noop };
|
||||
//# sourceMappingURL=noop.mjs.map
|
||||
+1
@@ -0,0 +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;;;;"}
|
||||
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
declare function toHex(bytes: Uint8Array): string;
|
||||
declare function fromHex(hexString: string): Uint8Array;
|
||||
|
||||
declare function mapObject<K extends string | number | symbol, I, O>(input: Record<K, I>, mapper: (i: I, k: K) => O): Record<K, O>;
|
||||
type StringRecord<T> = {
|
||||
[Sym: symbol]: never;
|
||||
[Num: number]: never;
|
||||
[Str: string]: T;
|
||||
};
|
||||
declare const mapStringRecord: <I, O>(input: StringRecord<I>, mapper: (value: I, key: string) => O) => StringRecord<O>;
|
||||
|
||||
declare function filterObject<K extends string | number | symbol, I>(input: Record<K, I>, filterFn: (i: I, k: K) => boolean): Record<K, I>;
|
||||
|
||||
interface MergeUint8 {
|
||||
/**
|
||||
* @deprecated This overload will be removed in PAPI v2. Migrate as
|
||||
* follows:
|
||||
* mergeUint8(arr1, arr2) => mergeUint8([arr1, arr2])
|
||||
*/
|
||||
(...inputs: Array<Uint8Array>): Uint8Array;
|
||||
(inputs: Array<Uint8Array>): Uint8Array;
|
||||
}
|
||||
declare const mergeUint8: MergeUint8;
|
||||
|
||||
declare const noop: () => void;
|
||||
|
||||
declare class AbortError extends Error {
|
||||
constructor();
|
||||
}
|
||||
|
||||
declare const jsonPrint: (value: any, indent?: number) => string;
|
||||
|
||||
export { AbortError, filterObject, fromHex, jsonPrint, mapObject, mapStringRecord, mergeUint8, noop, toHex };
|
||||
Vendored
+105
@@ -0,0 +1,105 @@
|
||||
'use strict';
|
||||
|
||||
const HEX_STR = "0123456789abcdef";
|
||||
function toHex(bytes) {
|
||||
const result = new Array(bytes.length + 1);
|
||||
result[0] = "0x";
|
||||
for (let i = 0; i < bytes.length; ) {
|
||||
const b = bytes[i++];
|
||||
result[i] = HEX_STR[b >> 4] + HEX_STR[b & 15];
|
||||
}
|
||||
return result.join("");
|
||||
}
|
||||
const HEX_MAP = {
|
||||
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 fromHex(hexString) {
|
||||
const isOdd = hexString.length % 2;
|
||||
const base = (hexString[1] === "x" ? 2 : 0) + isOdd;
|
||||
const nBytes = (hexString.length - base) / 2 + isOdd;
|
||||
const bytes = new Uint8Array(nBytes);
|
||||
if (isOdd) bytes[0] = 0 | HEX_MAP[hexString[2]];
|
||||
for (let i = 0; i < nBytes; ) {
|
||||
const idx = base + i * 2;
|
||||
const a = HEX_MAP[hexString[idx]];
|
||||
const b = HEX_MAP[hexString[idx + 1]];
|
||||
bytes[isOdd + i++] = a << 4 | b;
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
function mapObject(input, mapper) {
|
||||
return Object.fromEntries(
|
||||
Object.entries(input).map(
|
||||
([key, value]) => [key, mapper(value, key)]
|
||||
)
|
||||
);
|
||||
}
|
||||
const mapStringRecord = (input, mapper) => Object.fromEntries(
|
||||
Object.entries(input).map(([key, value]) => [key, mapper(value, key)])
|
||||
);
|
||||
|
||||
function filterObject(input, filterFn) {
|
||||
return Object.fromEntries(
|
||||
Object.entries(input).filter(([key, value]) => filterFn(value, key))
|
||||
);
|
||||
}
|
||||
|
||||
const mergeUint8 = (...i) => {
|
||||
const inputs = Array.isArray(i[0]) ? i[0] : i;
|
||||
const totalLen = inputs.reduce((acc, a) => acc + a.byteLength, 0);
|
||||
const result = new Uint8Array(totalLen);
|
||||
for (let idx = 0, at = 0; idx < inputs.length; idx++) {
|
||||
const current = inputs[idx];
|
||||
result.set(current, at);
|
||||
at += current.byteLength;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const noop = Function.prototype;
|
||||
|
||||
class AbortError extends Error {
|
||||
constructor() {
|
||||
super("Abort Error");
|
||||
this.name = "AbortError";
|
||||
}
|
||||
}
|
||||
|
||||
const jsonPrint = (value, indent = 2) => JSON.stringify(
|
||||
value,
|
||||
(_, v) => typeof v === "bigint" ? `${v}n` : typeof v === "object" && typeof v?.asHex === "function" ? v.asHex() : v,
|
||||
indent
|
||||
);
|
||||
|
||||
exports.AbortError = AbortError;
|
||||
exports.filterObject = filterObject;
|
||||
exports.fromHex = fromHex;
|
||||
exports.jsonPrint = jsonPrint;
|
||||
exports.mapObject = mapObject;
|
||||
exports.mapStringRecord = mapStringRecord;
|
||||
exports.mergeUint8 = mergeUint8;
|
||||
exports.noop = noop;
|
||||
exports.toHex = toHex;
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"name": "@pezkuwi/papi-utils",
|
||||
"version": "1.0.0",
|
||||
"author": "Dijital Kurdistan Tech Institute <info@pezkuwichain.io>",
|
||||
"bugs": "https://github.com/pezkuwichain/pezkuwi-api/issues",
|
||||
"homepage": "https://github.com/pezkuwichain/pezkuwi-api/tree/master/packages/papi-utils#readme",
|
||||
"repository": {
|
||||
"directory": "packages/papi-utils",
|
||||
"type": "git",
|
||||
"url": "https://github.com/pezkuwichain/pezkuwi-api.git"
|
||||
},
|
||||
"license": "MIT",
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"node": {
|
||||
"production": {
|
||||
"import": "./dist/esm/index.mjs",
|
||||
"require": "./dist/index.js",
|
||||
"default": "./dist/index.js"
|
||||
},
|
||||
"import": "./dist/esm/index.mjs",
|
||||
"require": "./dist/index.js",
|
||||
"default": "./dist/index.js"
|
||||
},
|
||||
"module": "./dist/esm/index.mjs",
|
||||
"import": "./dist/esm/index.mjs",
|
||||
"require": "./dist/index.js",
|
||||
"default": "./dist/index.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/esm/index.mjs",
|
||||
"browser": "./dist/esm/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user