@chainflip/utils 0.7.1 → 0.7.2-assethub.1
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/assertion.js +2 -2
- package/dist/async.cjs +1 -1
- package/dist/async.d.cts +1 -1
- package/dist/async.d.ts +1 -1
- package/dist/async.js +1 -1
- package/dist/base58.cjs +9 -21
- package/dist/base58.d.cts +2 -6
- package/dist/base58.d.ts +2 -6
- package/dist/base58.js +4 -6
- package/dist/bytes.cjs +3 -15
- package/dist/bytes.d.cts +3 -6
- package/dist/bytes.d.ts +3 -6
- package/dist/bytes.js +5 -7
- package/dist/{chunk-W23CNAUU.js → chunk-4RHM5374.js} +3 -14
- package/dist/{chunk-HBIFE4XN.js → chunk-CZNX6EUV.js} +1 -7
- package/dist/{chunk-ZHIKNZLU.js → chunk-MYP3UYWE.js} +1 -1
- package/dist/chunk-O4WBUIAN.js +14 -0
- package/dist/guard.cjs +0 -9
- package/dist/guard.d.cts +8 -11
- package/dist/guard.d.ts +8 -11
- package/dist/guard.js +1 -7
- package/dist/number.cjs +0 -59
- package/dist/number.d.cts +1 -7
- package/dist/number.d.ts +1 -7
- package/dist/number.js +0 -34
- package/dist/ss58.cjs +66 -143
- package/dist/ss58.d.cts +3 -5
- package/dist/ss58.d.ts +3 -5
- package/dist/ss58.js +37 -109
- package/dist/string.cjs +0 -21
- package/dist/string.d.cts +2 -8
- package/dist/string.d.ts +2 -8
- package/dist/string.js +0 -18
- package/dist/types.d.cts +1 -36
- package/dist/types.d.ts +1 -36
- package/package.json +15 -15
- package/dist/chainflip.cjs +0 -192
- package/dist/chainflip.d.cts +0 -122
- package/dist/chainflip.d.ts +0 -122
- package/dist/chainflip.js +0 -30
- package/dist/chunk-HOUVS5DD.js +0 -15
- package/dist/chunk-YOAHWTE7.js +0 -156
- package/dist/consts.cjs +0 -209
- package/dist/consts.d.cts +0 -29
- package/dist/consts.d.ts +0 -29
- package/dist/consts.js +0 -175
- package/dist/date.cjs +0 -137
- package/dist/date.d.cts +0 -26
- package/dist/date.d.ts +0 -26
- package/dist/date.js +0 -101
- package/dist/math.cjs +0 -33
- package/dist/math.d.cts +0 -4
- package/dist/math.d.ts +0 -4
- package/dist/math.js +0 -7
- package/dist/tickMath.cjs +0 -165
- package/dist/tickMath.d.cts +0 -15
- package/dist/tickMath.d.ts +0 -15
- package/dist/tickMath.js +0 -33
- package/dist/url.cjs +0 -39
- package/dist/url.d.cts +0 -6
- package/dist/url.d.ts +0 -6
- package/dist/url.js +0 -14
package/dist/assertion.js
CHANGED
package/dist/async.cjs
CHANGED
|
@@ -94,7 +94,7 @@ var once = async (target, event, opts) => {
|
|
|
94
94
|
target.addEventListener(event, onSuccess, { once: true, signal: opts?.signal });
|
|
95
95
|
target.addEventListener("error", onError, { once: true, signal: opts?.signal });
|
|
96
96
|
if (opts?.signal) {
|
|
97
|
-
const
|
|
97
|
+
const signal = opts.signal;
|
|
98
98
|
const abort = () => {
|
|
99
99
|
deferred.reject(new Error("aborted"));
|
|
100
100
|
};
|
package/dist/async.d.cts
CHANGED
|
@@ -25,7 +25,7 @@ declare class RateLimiter<T, Args extends unknown[]> {
|
|
|
25
25
|
});
|
|
26
26
|
request(...args: Args): Promise<T>;
|
|
27
27
|
}
|
|
28
|
-
declare const once: (target:
|
|
28
|
+
declare const once: <T extends EventTarget, K extends string>(target: T, event: K, opts?: {
|
|
29
29
|
signal?: AbortSignal;
|
|
30
30
|
timeout?: number;
|
|
31
31
|
}) => Promise<void>;
|
package/dist/async.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ declare class RateLimiter<T, Args extends unknown[]> {
|
|
|
25
25
|
});
|
|
26
26
|
request(...args: Args): Promise<T>;
|
|
27
27
|
}
|
|
28
|
-
declare const once: (target:
|
|
28
|
+
declare const once: <T extends EventTarget, K extends string>(target: T, event: K, opts?: {
|
|
29
29
|
signal?: AbortSignal;
|
|
30
30
|
timeout?: number;
|
|
31
31
|
}) => Promise<void>;
|
package/dist/async.js
CHANGED
|
@@ -66,7 +66,7 @@ var once = async (target, event, opts) => {
|
|
|
66
66
|
target.addEventListener(event, onSuccess, { once: true, signal: opts?.signal });
|
|
67
67
|
target.addEventListener("error", onError, { once: true, signal: opts?.signal });
|
|
68
68
|
if (opts?.signal) {
|
|
69
|
-
const
|
|
69
|
+
const signal = opts.signal;
|
|
70
70
|
const abort = () => {
|
|
71
71
|
deferred.reject(new Error("aborted"));
|
|
72
72
|
};
|
package/dist/base58.cjs
CHANGED
|
@@ -20,7 +20,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/base58.ts
|
|
21
21
|
var base58_exports = {};
|
|
22
22
|
__export(base58_exports, {
|
|
23
|
-
CHARSET: () => CHARSET,
|
|
24
23
|
decode: () => decode,
|
|
25
24
|
encode: () => encode
|
|
26
25
|
});
|
|
@@ -44,17 +43,7 @@ function assert(condition, message = "assertion failed", Constructor = Error) {
|
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
// src/bytes.ts
|
|
47
|
-
var
|
|
48
|
-
assert(/^0x[\da-f]*$/i.test(input) && input.length % 2 === 0, "Invalid hex string");
|
|
49
|
-
const hex = input.slice(2);
|
|
50
|
-
const bytes = new Uint8Array(hex.length / 2);
|
|
51
|
-
for (let i = 0; i < hex.length; i += 2) {
|
|
52
|
-
bytes[i / 2] = Number.parseInt(hex.slice(i, i + 2), 16);
|
|
53
|
-
}
|
|
54
|
-
return bytes;
|
|
55
|
-
};
|
|
56
|
-
var convertBase = (inputBytes, fromBase, toBase) => {
|
|
57
|
-
const bytes = typeof inputBytes === "string" ? hexToBytes(inputBytes) : new Uint8Array(inputBytes);
|
|
46
|
+
var convertBase = (bytes, fromBase, toBase) => {
|
|
58
47
|
const result = [];
|
|
59
48
|
for (const byte of bytes) {
|
|
60
49
|
let carry = byte;
|
|
@@ -75,21 +64,20 @@ var convertBase = (inputBytes, fromBase, toBase) => {
|
|
|
75
64
|
}
|
|
76
65
|
return result.reverse();
|
|
77
66
|
};
|
|
78
|
-
var encodeBytesWithCharset = (bytes,
|
|
79
|
-
var decodeBytesWithCharset = (input,
|
|
80
|
-
assert(new RegExp(`^[${
|
|
81
|
-
const charMap = Object.fromEntries([...
|
|
67
|
+
var encodeBytesWithCharset = (bytes, charset2) => convertBase(bytes, 256, charset2.length).map((charCode) => charset2.charAt(charCode)).join("");
|
|
68
|
+
var decodeBytesWithCharset = (input, charset2) => {
|
|
69
|
+
assert(new RegExp(`^[${charset2}]*$`).test(input), "Invalid input");
|
|
70
|
+
const charMap = Object.fromEntries([...charset2].map((char, index) => [char, index]));
|
|
82
71
|
const bytes = input.split("").map((char) => charMap[char]);
|
|
83
|
-
return new Uint8Array(convertBase(bytes,
|
|
72
|
+
return new Uint8Array(convertBase(bytes, charset2.length, 256));
|
|
84
73
|
};
|
|
85
74
|
|
|
86
75
|
// src/base58.ts
|
|
87
|
-
var
|
|
88
|
-
var encode = (bytes) => encodeBytesWithCharset(bytes,
|
|
89
|
-
var decode = (input) => decodeBytesWithCharset(input,
|
|
76
|
+
var charset = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
77
|
+
var encode = (bytes) => encodeBytesWithCharset(bytes, charset);
|
|
78
|
+
var decode = (input) => decodeBytesWithCharset(input, charset);
|
|
90
79
|
// Annotate the CommonJS export names for ESM import in node:
|
|
91
80
|
0 && (module.exports = {
|
|
92
|
-
CHARSET,
|
|
93
81
|
decode,
|
|
94
82
|
encode
|
|
95
83
|
});
|
package/dist/base58.d.cts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import './chainflip.cjs';
|
|
3
|
-
|
|
4
|
-
declare const CHARSET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
5
|
-
declare const encode: (bytes: Bytelike) => string;
|
|
1
|
+
declare const encode: (bytes: Uint8Array | number[]) => string;
|
|
6
2
|
declare const decode: (input: string) => Uint8Array;
|
|
7
3
|
|
|
8
|
-
export {
|
|
4
|
+
export { decode, encode };
|
package/dist/base58.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import './chainflip.js';
|
|
3
|
-
|
|
4
|
-
declare const CHARSET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
5
|
-
declare const encode: (bytes: Bytelike) => string;
|
|
1
|
+
declare const encode: (bytes: Uint8Array | number[]) => string;
|
|
6
2
|
declare const decode: (input: string) => Uint8Array;
|
|
7
3
|
|
|
8
|
-
export {
|
|
4
|
+
export { decode, encode };
|
package/dist/base58.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
-
CHARSET,
|
|
3
2
|
decode,
|
|
4
3
|
encode
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-O4WBUIAN.js";
|
|
5
|
+
import "./chunk-4RHM5374.js";
|
|
6
|
+
import "./chunk-MYP3UYWE.js";
|
|
7
|
+
import "./chunk-CZNX6EUV.js";
|
|
9
8
|
export {
|
|
10
|
-
CHARSET,
|
|
11
9
|
decode,
|
|
12
10
|
encode
|
|
13
11
|
};
|
package/dist/bytes.cjs
CHANGED
|
@@ -23,8 +23,7 @@ __export(bytes_exports, {
|
|
|
23
23
|
bytesToHex: () => bytesToHex,
|
|
24
24
|
decodeBytesWithCharset: () => decodeBytesWithCharset,
|
|
25
25
|
encodeBytesWithCharset: () => encodeBytesWithCharset,
|
|
26
|
-
hexToBytes: () => hexToBytes
|
|
27
|
-
reverseBytes: () => reverseBytes
|
|
26
|
+
hexToBytes: () => hexToBytes
|
|
28
27
|
});
|
|
29
28
|
module.exports = __toCommonJS(bytes_exports);
|
|
30
29
|
|
|
@@ -59,8 +58,7 @@ var hexToBytes = (input) => {
|
|
|
59
58
|
}
|
|
60
59
|
return bytes;
|
|
61
60
|
};
|
|
62
|
-
var convertBase = (
|
|
63
|
-
const bytes = typeof inputBytes === "string" ? hexToBytes(inputBytes) : new Uint8Array(inputBytes);
|
|
61
|
+
var convertBase = (bytes, fromBase, toBase) => {
|
|
64
62
|
const result = [];
|
|
65
63
|
for (const byte of bytes) {
|
|
66
64
|
let carry = byte;
|
|
@@ -88,20 +86,10 @@ var decodeBytesWithCharset = (input, charset) => {
|
|
|
88
86
|
const bytes = input.split("").map((char) => charMap[char]);
|
|
89
87
|
return new Uint8Array(convertBase(bytes, charset.length, 256));
|
|
90
88
|
};
|
|
91
|
-
var addPrefix = (input) => {
|
|
92
|
-
const [, bytes] = /^(?:0x)?([a-f\d]*)$/i.exec(input) || [];
|
|
93
|
-
assert(bytes, "Invalid hex string");
|
|
94
|
-
return `0x${bytes}`;
|
|
95
|
-
};
|
|
96
|
-
function reverseBytes(input) {
|
|
97
|
-
const reversed = bytesToHex(hexToBytes(addPrefix(input)).reverse());
|
|
98
|
-
return input.startsWith("0x") ? reversed : reversed.slice(2);
|
|
99
|
-
}
|
|
100
89
|
// Annotate the CommonJS export names for ESM import in node:
|
|
101
90
|
0 && (module.exports = {
|
|
102
91
|
bytesToHex,
|
|
103
92
|
decodeBytesWithCharset,
|
|
104
93
|
encodeBytesWithCharset,
|
|
105
|
-
hexToBytes
|
|
106
|
-
reverseBytes
|
|
94
|
+
hexToBytes
|
|
107
95
|
});
|
package/dist/bytes.d.cts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { HexString
|
|
2
|
-
import './chainflip.cjs';
|
|
1
|
+
import { HexString } from './types.cjs';
|
|
3
2
|
|
|
4
3
|
declare const bytesToHex: (input: Uint8Array | number[]) => `0x${string}`;
|
|
5
4
|
declare const hexToBytes: (input: HexString) => Uint8Array;
|
|
6
|
-
declare const encodeBytesWithCharset: (bytes:
|
|
5
|
+
declare const encodeBytesWithCharset: (bytes: Uint8Array | number[], charset: string) => string;
|
|
7
6
|
declare const decodeBytesWithCharset: (input: string, charset: string) => Uint8Array;
|
|
8
|
-
declare function reverseBytes(input: HexString): HexString;
|
|
9
|
-
declare function reverseBytes(input: string): string;
|
|
10
7
|
|
|
11
|
-
export { bytesToHex, decodeBytesWithCharset, encodeBytesWithCharset, hexToBytes
|
|
8
|
+
export { bytesToHex, decodeBytesWithCharset, encodeBytesWithCharset, hexToBytes };
|
package/dist/bytes.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { HexString
|
|
2
|
-
import './chainflip.js';
|
|
1
|
+
import { HexString } from './types.js';
|
|
3
2
|
|
|
4
3
|
declare const bytesToHex: (input: Uint8Array | number[]) => `0x${string}`;
|
|
5
4
|
declare const hexToBytes: (input: HexString) => Uint8Array;
|
|
6
|
-
declare const encodeBytesWithCharset: (bytes:
|
|
5
|
+
declare const encodeBytesWithCharset: (bytes: Uint8Array | number[], charset: string) => string;
|
|
7
6
|
declare const decodeBytesWithCharset: (input: string, charset: string) => Uint8Array;
|
|
8
|
-
declare function reverseBytes(input: HexString): HexString;
|
|
9
|
-
declare function reverseBytes(input: string): string;
|
|
10
7
|
|
|
11
|
-
export { bytesToHex, decodeBytesWithCharset, encodeBytesWithCharset, hexToBytes
|
|
8
|
+
export { bytesToHex, decodeBytesWithCharset, encodeBytesWithCharset, hexToBytes };
|
package/dist/bytes.js
CHANGED
|
@@ -2,15 +2,13 @@ import {
|
|
|
2
2
|
bytesToHex,
|
|
3
3
|
decodeBytesWithCharset,
|
|
4
4
|
encodeBytesWithCharset,
|
|
5
|
-
hexToBytes
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-HBIFE4XN.js";
|
|
5
|
+
hexToBytes
|
|
6
|
+
} from "./chunk-4RHM5374.js";
|
|
7
|
+
import "./chunk-MYP3UYWE.js";
|
|
8
|
+
import "./chunk-CZNX6EUV.js";
|
|
10
9
|
export {
|
|
11
10
|
bytesToHex,
|
|
12
11
|
decodeBytesWithCharset,
|
|
13
12
|
encodeBytesWithCharset,
|
|
14
|
-
hexToBytes
|
|
15
|
-
reverseBytes
|
|
13
|
+
hexToBytes
|
|
16
14
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
assert
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-MYP3UYWE.js";
|
|
4
4
|
|
|
5
5
|
// src/bytes.ts
|
|
6
6
|
var bytesToHex = (input) => {
|
|
@@ -16,8 +16,7 @@ var hexToBytes = (input) => {
|
|
|
16
16
|
}
|
|
17
17
|
return bytes;
|
|
18
18
|
};
|
|
19
|
-
var convertBase = (
|
|
20
|
-
const bytes = typeof inputBytes === "string" ? hexToBytes(inputBytes) : new Uint8Array(inputBytes);
|
|
19
|
+
var convertBase = (bytes, fromBase, toBase) => {
|
|
21
20
|
const result = [];
|
|
22
21
|
for (const byte of bytes) {
|
|
23
22
|
let carry = byte;
|
|
@@ -45,20 +44,10 @@ var decodeBytesWithCharset = (input, charset) => {
|
|
|
45
44
|
const bytes = input.split("").map((char) => charMap[char]);
|
|
46
45
|
return new Uint8Array(convertBase(bytes, charset.length, 256));
|
|
47
46
|
};
|
|
48
|
-
var addPrefix = (input) => {
|
|
49
|
-
const [, bytes] = /^(?:0x)?([a-f\d]*)$/i.exec(input) || [];
|
|
50
|
-
assert(bytes, "Invalid hex string");
|
|
51
|
-
return `0x${bytes}`;
|
|
52
|
-
};
|
|
53
|
-
function reverseBytes(input) {
|
|
54
|
-
const reversed = bytesToHex(hexToBytes(addPrefix(input)).reverse());
|
|
55
|
-
return input.startsWith("0x") ? reversed : reversed.slice(2);
|
|
56
|
-
}
|
|
57
47
|
|
|
58
48
|
export {
|
|
59
49
|
bytesToHex,
|
|
60
50
|
hexToBytes,
|
|
61
51
|
encodeBytesWithCharset,
|
|
62
|
-
decodeBytesWithCharset
|
|
63
|
-
reverseBytes
|
|
52
|
+
decodeBytesWithCharset
|
|
64
53
|
};
|
|
@@ -9,9 +9,6 @@ var isObject = createIsGuard("object");
|
|
|
9
9
|
var isUndefined = createIsGuard("undefined");
|
|
10
10
|
var isNotNullish = (value) => value != null;
|
|
11
11
|
var isNullish = (value) => value == null;
|
|
12
|
-
var isTruthy = (value) => Boolean(value);
|
|
13
|
-
var isFullfilled = (value) => value.status === "fulfilled";
|
|
14
|
-
var isRejected = (value) => value.status === "rejected";
|
|
15
12
|
|
|
16
13
|
export {
|
|
17
14
|
isString,
|
|
@@ -22,8 +19,5 @@ export {
|
|
|
22
19
|
isObject,
|
|
23
20
|
isUndefined,
|
|
24
21
|
isNotNullish,
|
|
25
|
-
isNullish
|
|
26
|
-
isTruthy,
|
|
27
|
-
isFullfilled,
|
|
28
|
-
isRejected
|
|
22
|
+
isNullish
|
|
29
23
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decodeBytesWithCharset,
|
|
3
|
+
encodeBytesWithCharset
|
|
4
|
+
} from "./chunk-4RHM5374.js";
|
|
5
|
+
|
|
6
|
+
// src/base58.ts
|
|
7
|
+
var charset = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
8
|
+
var encode = (bytes) => encodeBytesWithCharset(bytes, charset);
|
|
9
|
+
var decode = (input) => decodeBytesWithCharset(input, charset);
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
encode,
|
|
13
|
+
decode
|
|
14
|
+
};
|
package/dist/guard.cjs
CHANGED
|
@@ -22,15 +22,12 @@ var guard_exports = {};
|
|
|
22
22
|
__export(guard_exports, {
|
|
23
23
|
isBigInt: () => isBigInt,
|
|
24
24
|
isBoolean: () => isBoolean,
|
|
25
|
-
isFullfilled: () => isFullfilled,
|
|
26
25
|
isNotNullish: () => isNotNullish,
|
|
27
26
|
isNullish: () => isNullish,
|
|
28
27
|
isNumber: () => isNumber,
|
|
29
28
|
isObject: () => isObject,
|
|
30
|
-
isRejected: () => isRejected,
|
|
31
29
|
isString: () => isString,
|
|
32
30
|
isSymbol: () => isSymbol,
|
|
33
|
-
isTruthy: () => isTruthy,
|
|
34
31
|
isUndefined: () => isUndefined
|
|
35
32
|
});
|
|
36
33
|
module.exports = __toCommonJS(guard_exports);
|
|
@@ -44,21 +41,15 @@ var isObject = createIsGuard("object");
|
|
|
44
41
|
var isUndefined = createIsGuard("undefined");
|
|
45
42
|
var isNotNullish = (value) => value != null;
|
|
46
43
|
var isNullish = (value) => value == null;
|
|
47
|
-
var isTruthy = (value) => Boolean(value);
|
|
48
|
-
var isFullfilled = (value) => value.status === "fulfilled";
|
|
49
|
-
var isRejected = (value) => value.status === "rejected";
|
|
50
44
|
// Annotate the CommonJS export names for ESM import in node:
|
|
51
45
|
0 && (module.exports = {
|
|
52
46
|
isBigInt,
|
|
53
47
|
isBoolean,
|
|
54
|
-
isFullfilled,
|
|
55
48
|
isNotNullish,
|
|
56
49
|
isNullish,
|
|
57
50
|
isNumber,
|
|
58
51
|
isObject,
|
|
59
|
-
isRejected,
|
|
60
52
|
isString,
|
|
61
53
|
isSymbol,
|
|
62
|
-
isTruthy,
|
|
63
54
|
isUndefined
|
|
64
55
|
});
|
package/dist/guard.d.cts
CHANGED
|
@@ -7,17 +7,14 @@ type TypeMap = {
|
|
|
7
7
|
object: object;
|
|
8
8
|
undefined: undefined;
|
|
9
9
|
};
|
|
10
|
-
declare const isString: (value: unknown) => value is
|
|
11
|
-
declare const isNumber: (value: unknown) => value is
|
|
12
|
-
declare const isBigInt: (value: unknown) => value is
|
|
13
|
-
declare const isBoolean: (value: unknown) => value is
|
|
14
|
-
declare const isSymbol: (value: unknown) => value is
|
|
15
|
-
declare const isObject: (value: unknown) => value is
|
|
16
|
-
declare const isUndefined: (value: unknown) => value is
|
|
10
|
+
declare const isString: (value: unknown) => value is string;
|
|
11
|
+
declare const isNumber: (value: unknown) => value is number;
|
|
12
|
+
declare const isBigInt: (value: unknown) => value is bigint;
|
|
13
|
+
declare const isBoolean: (value: unknown) => value is boolean;
|
|
14
|
+
declare const isSymbol: (value: unknown) => value is symbol;
|
|
15
|
+
declare const isObject: (value: unknown) => value is object;
|
|
16
|
+
declare const isUndefined: (value: unknown) => value is undefined;
|
|
17
17
|
declare const isNotNullish: <T>(value: T) => value is NonNullable<T>;
|
|
18
18
|
declare const isNullish: (value: unknown) => value is null | undefined;
|
|
19
|
-
declare const isTruthy: <T>(value: T | null | undefined) => value is T;
|
|
20
|
-
declare const isFullfilled: <T>(value: PromiseSettledResult<T>) => value is PromiseFulfilledResult<T>;
|
|
21
|
-
declare const isRejected: <T>(value: PromiseSettledResult<T>) => value is PromiseRejectedResult;
|
|
22
19
|
|
|
23
|
-
export { type TypeMap, isBigInt, isBoolean,
|
|
20
|
+
export { type TypeMap, isBigInt, isBoolean, isNotNullish, isNullish, isNumber, isObject, isString, isSymbol, isUndefined };
|
package/dist/guard.d.ts
CHANGED
|
@@ -7,17 +7,14 @@ type TypeMap = {
|
|
|
7
7
|
object: object;
|
|
8
8
|
undefined: undefined;
|
|
9
9
|
};
|
|
10
|
-
declare const isString: (value: unknown) => value is
|
|
11
|
-
declare const isNumber: (value: unknown) => value is
|
|
12
|
-
declare const isBigInt: (value: unknown) => value is
|
|
13
|
-
declare const isBoolean: (value: unknown) => value is
|
|
14
|
-
declare const isSymbol: (value: unknown) => value is
|
|
15
|
-
declare const isObject: (value: unknown) => value is
|
|
16
|
-
declare const isUndefined: (value: unknown) => value is
|
|
10
|
+
declare const isString: (value: unknown) => value is string;
|
|
11
|
+
declare const isNumber: (value: unknown) => value is number;
|
|
12
|
+
declare const isBigInt: (value: unknown) => value is bigint;
|
|
13
|
+
declare const isBoolean: (value: unknown) => value is boolean;
|
|
14
|
+
declare const isSymbol: (value: unknown) => value is symbol;
|
|
15
|
+
declare const isObject: (value: unknown) => value is object;
|
|
16
|
+
declare const isUndefined: (value: unknown) => value is undefined;
|
|
17
17
|
declare const isNotNullish: <T>(value: T) => value is NonNullable<T>;
|
|
18
18
|
declare const isNullish: (value: unknown) => value is null | undefined;
|
|
19
|
-
declare const isTruthy: <T>(value: T | null | undefined) => value is T;
|
|
20
|
-
declare const isFullfilled: <T>(value: PromiseSettledResult<T>) => value is PromiseFulfilledResult<T>;
|
|
21
|
-
declare const isRejected: <T>(value: PromiseSettledResult<T>) => value is PromiseRejectedResult;
|
|
22
19
|
|
|
23
|
-
export { type TypeMap, isBigInt, isBoolean,
|
|
20
|
+
export { type TypeMap, isBigInt, isBoolean, isNotNullish, isNullish, isNumber, isObject, isString, isSymbol, isUndefined };
|
package/dist/guard.js
CHANGED
|
@@ -1,28 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isBigInt,
|
|
3
3
|
isBoolean,
|
|
4
|
-
isFullfilled,
|
|
5
4
|
isNotNullish,
|
|
6
5
|
isNullish,
|
|
7
6
|
isNumber,
|
|
8
7
|
isObject,
|
|
9
|
-
isRejected,
|
|
10
8
|
isString,
|
|
11
9
|
isSymbol,
|
|
12
|
-
isTruthy,
|
|
13
10
|
isUndefined
|
|
14
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-CZNX6EUV.js";
|
|
15
12
|
export {
|
|
16
13
|
isBigInt,
|
|
17
14
|
isBoolean,
|
|
18
|
-
isFullfilled,
|
|
19
15
|
isNotNullish,
|
|
20
16
|
isNullish,
|
|
21
17
|
isNumber,
|
|
22
18
|
isObject,
|
|
23
|
-
isRejected,
|
|
24
19
|
isString,
|
|
25
20
|
isSymbol,
|
|
26
|
-
isTruthy,
|
|
27
21
|
isUndefined
|
|
28
22
|
};
|
package/dist/number.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,73 +15,16 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/number.ts
|
|
31
21
|
var number_exports = {};
|
|
32
22
|
__export(number_exports, {
|
|
33
|
-
formatUsdValue: () => formatUsdValue,
|
|
34
23
|
hexEncodeNumber: () => hexEncodeNumber
|
|
35
24
|
});
|
|
36
25
|
module.exports = __toCommonJS(number_exports);
|
|
37
|
-
var import_bignumber = __toESM(require("bignumber.js"), 1);
|
|
38
|
-
|
|
39
|
-
// src/guard.ts
|
|
40
|
-
var createIsGuard = (type) => (value) => typeof value === type;
|
|
41
|
-
var isString = createIsGuard("string");
|
|
42
|
-
var isNumber = createIsGuard("number");
|
|
43
|
-
var isBigInt = createIsGuard("bigint");
|
|
44
|
-
var isBoolean = createIsGuard("boolean");
|
|
45
|
-
var isSymbol = createIsGuard("symbol");
|
|
46
|
-
var isObject = createIsGuard("object");
|
|
47
|
-
var isUndefined = createIsGuard("undefined");
|
|
48
|
-
|
|
49
|
-
// src/assertion.ts
|
|
50
|
-
function assert(condition, message = "assertion failed", Constructor = Error) {
|
|
51
|
-
if (!condition) {
|
|
52
|
-
throw new Constructor(message);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// src/number.ts
|
|
57
26
|
var hexEncodeNumber = (num) => `0x${num.toString(16)}`;
|
|
58
|
-
function formatUsdValue(value, precise = true) {
|
|
59
|
-
if (value == null) return value;
|
|
60
|
-
let usdAmount = new import_bignumber.default(value);
|
|
61
|
-
assert(usdAmount.gte(0), "negative amounts not supported");
|
|
62
|
-
if (!usdAmount.eq(0) && usdAmount.lt(0.01)) return `<$0.01`;
|
|
63
|
-
let suffix = "";
|
|
64
|
-
let decimals = 2;
|
|
65
|
-
if (!precise) {
|
|
66
|
-
if (usdAmount.gte(1e12)) {
|
|
67
|
-
usdAmount = usdAmount.shiftedBy(-12);
|
|
68
|
-
suffix = "T";
|
|
69
|
-
} else if (usdAmount.gte(1e9)) {
|
|
70
|
-
usdAmount = usdAmount.shiftedBy(-9);
|
|
71
|
-
suffix = "B";
|
|
72
|
-
} else if (usdAmount.gte(1e6)) {
|
|
73
|
-
usdAmount = usdAmount.shiftedBy(-6);
|
|
74
|
-
suffix = "M";
|
|
75
|
-
}
|
|
76
|
-
if (suffix === "" && usdAmount.gte(1e4)) {
|
|
77
|
-
decimals = 0;
|
|
78
|
-
} else if (suffix !== "") {
|
|
79
|
-
decimals = void 0;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
usdAmount = usdAmount.decimalPlaces(2);
|
|
83
|
-
return `$${usdAmount.toFormat(decimals)}${suffix}`;
|
|
84
|
-
}
|
|
85
27
|
// Annotate the CommonJS export names for ESM import in node:
|
|
86
28
|
0 && (module.exports = {
|
|
87
|
-
formatUsdValue,
|
|
88
29
|
hexEncodeNumber
|
|
89
30
|
});
|
package/dist/number.d.cts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import BigNumber from 'bignumber.js';
|
|
2
1
|
import { HexString } from './types.cjs';
|
|
3
|
-
import './chainflip.cjs';
|
|
4
2
|
|
|
5
3
|
declare const hexEncodeNumber: (num: number | bigint) => HexString;
|
|
6
|
-
declare function formatUsdValue(value: BigNumber.Value, precise?: boolean): string;
|
|
7
|
-
declare function formatUsdValue(value: null, precise?: boolean): null;
|
|
8
|
-
declare function formatUsdValue(value: undefined, precise?: boolean): undefined;
|
|
9
|
-
declare function formatUsdValue(value: BigNumber.Value | null | undefined, precise?: boolean): string | null | undefined;
|
|
10
4
|
|
|
11
|
-
export {
|
|
5
|
+
export { hexEncodeNumber };
|
package/dist/number.d.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import BigNumber from 'bignumber.js';
|
|
2
1
|
import { HexString } from './types.js';
|
|
3
|
-
import './chainflip.js';
|
|
4
2
|
|
|
5
3
|
declare const hexEncodeNumber: (num: number | bigint) => HexString;
|
|
6
|
-
declare function formatUsdValue(value: BigNumber.Value, precise?: boolean): string;
|
|
7
|
-
declare function formatUsdValue(value: null, precise?: boolean): null;
|
|
8
|
-
declare function formatUsdValue(value: undefined, precise?: boolean): undefined;
|
|
9
|
-
declare function formatUsdValue(value: BigNumber.Value | null | undefined, precise?: boolean): string | null | undefined;
|
|
10
4
|
|
|
11
|
-
export {
|
|
5
|
+
export { hexEncodeNumber };
|
package/dist/number.js
CHANGED
|
@@ -1,39 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
assert
|
|
3
|
-
} from "./chunk-ZHIKNZLU.js";
|
|
4
|
-
import "./chunk-HBIFE4XN.js";
|
|
5
|
-
|
|
6
1
|
// src/number.ts
|
|
7
|
-
import BigNumber from "bignumber.js";
|
|
8
2
|
var hexEncodeNumber = (num) => `0x${num.toString(16)}`;
|
|
9
|
-
function formatUsdValue(value, precise = true) {
|
|
10
|
-
if (value == null) return value;
|
|
11
|
-
let usdAmount = new BigNumber(value);
|
|
12
|
-
assert(usdAmount.gte(0), "negative amounts not supported");
|
|
13
|
-
if (!usdAmount.eq(0) && usdAmount.lt(0.01)) return `<$0.01`;
|
|
14
|
-
let suffix = "";
|
|
15
|
-
let decimals = 2;
|
|
16
|
-
if (!precise) {
|
|
17
|
-
if (usdAmount.gte(1e12)) {
|
|
18
|
-
usdAmount = usdAmount.shiftedBy(-12);
|
|
19
|
-
suffix = "T";
|
|
20
|
-
} else if (usdAmount.gte(1e9)) {
|
|
21
|
-
usdAmount = usdAmount.shiftedBy(-9);
|
|
22
|
-
suffix = "B";
|
|
23
|
-
} else if (usdAmount.gte(1e6)) {
|
|
24
|
-
usdAmount = usdAmount.shiftedBy(-6);
|
|
25
|
-
suffix = "M";
|
|
26
|
-
}
|
|
27
|
-
if (suffix === "" && usdAmount.gte(1e4)) {
|
|
28
|
-
decimals = 0;
|
|
29
|
-
} else if (suffix !== "") {
|
|
30
|
-
decimals = void 0;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
usdAmount = usdAmount.decimalPlaces(2);
|
|
34
|
-
return `$${usdAmount.toFormat(decimals)}${suffix}`;
|
|
35
|
-
}
|
|
36
3
|
export {
|
|
37
|
-
formatUsdValue,
|
|
38
4
|
hexEncodeNumber
|
|
39
5
|
};
|