@talismn/util 0.0.11 → 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/CHANGELOG.md +19 -0
- package/README.md +3 -1
- package/dist/BigMath.d.ts +10 -0
- package/dist/BigMath.js +31 -0
- package/dist/FunctionPropertyNames.d.ts +8 -0
- package/dist/FunctionPropertyNames.js +3 -0
- package/dist/blake2Concat.d.ts +1 -0
- package/dist/blake2Concat.js +6 -0
- package/dist/decodeAnyAddress.js +14 -43
- package/dist/encodeAnyAddress.js +13 -42
- package/dist/formatDecimals.d.ts +11 -0
- package/dist/formatDecimals.js +44 -0
- package/dist/getBase64ImageUrl.d.ts +1 -0
- package/dist/getBase64ImageUrl.js +8 -0
- package/dist/hasOwnProperty.d.ts +1 -0
- package/dist/hasOwnProperty.js +3 -0
- package/dist/index.d.ts +12 -9
- package/dist/index.js +12 -28
- package/dist/isArrayOf.d.ts +1 -0
- package/dist/isArrayOf.js +5 -0
- package/dist/planckToTokens.js +8 -38
- package/dist/tokensToPlanck.js +8 -38
- package/dist/twox64Concat.d.ts +2 -0
- package/dist/twox64Concat.js +6 -0
- package/package.json +41 -61
- package/LICENCE +0 -674
- package/dist/bigNumbers.d.ts +0 -6
- package/dist/bigNumbers.js +0 -51
- package/dist/chains.d.ts +0 -2
- package/dist/chains.js +0 -37
- package/dist/deferred.d.ts +0 -8
- package/dist/deferred.js +0 -41
- package/dist/hexToBytes.d.ts +0 -1
- package/dist/hexToBytes.js +0 -21
- package/dist/useFuncMemo.d.ts +0 -1
- package/dist/useFuncMemo.js +0 -34
- package/src/index.ts +0 -9
package/CHANGELOG.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# @talismn/util
|
2
|
+
|
3
|
+
## 0.1.2
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 2ccd51b: feat: implemented @talismn/balances-substrate-native
|
8
|
+
|
9
|
+
## 0.1.1
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- Fixed publish config
|
14
|
+
|
15
|
+
## 0.1.0
|
16
|
+
|
17
|
+
### Minor Changes
|
18
|
+
|
19
|
+
- 43c1a3a: Initial release
|
package/README.md
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
/**
|
2
|
+
* Javascript's `Math` library for `BigInt`.
|
3
|
+
* Taken from https://stackoverflow.com/questions/51867270/is-there-a-library-similar-to-math-that-supports-javascript-bigint/64953280#64953280
|
4
|
+
*/
|
5
|
+
export declare const BigMath: {
|
6
|
+
abs(x: bigint): bigint;
|
7
|
+
sign(x: bigint): bigint;
|
8
|
+
min(value: bigint, ...values: bigint[]): bigint;
|
9
|
+
max(value: bigint, ...values: bigint[]): bigint;
|
10
|
+
};
|
package/dist/BigMath.js
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
/**
|
2
|
+
* Javascript's `Math` library for `BigInt`.
|
3
|
+
* Taken from https://stackoverflow.com/questions/51867270/is-there-a-library-similar-to-math-that-supports-javascript-bigint/64953280#64953280
|
4
|
+
*/
|
5
|
+
export const BigMath = {
|
6
|
+
abs(x) {
|
7
|
+
return x < BigInt("0") ? -x : x;
|
8
|
+
},
|
9
|
+
sign(x) {
|
10
|
+
if (x === BigInt("0"))
|
11
|
+
return BigInt("0");
|
12
|
+
return x < BigInt("0") ? BigInt("-1") : BigInt("1");
|
13
|
+
},
|
14
|
+
// TODO: Improve our babel/tsc config to let us use the `**` operator on bigint values.
|
15
|
+
// Error thrown: Exponentiation cannot be performed on 'bigint' values unless the 'target' option is set to 'es2016' or later. ts(2791)
|
16
|
+
// pow(base: bigint, exponent: bigint) {
|
17
|
+
// return base ** exponent
|
18
|
+
// },
|
19
|
+
min(value, ...values) {
|
20
|
+
for (const v of values)
|
21
|
+
if (v < value)
|
22
|
+
value = v;
|
23
|
+
return value;
|
24
|
+
},
|
25
|
+
max(value, ...values) {
|
26
|
+
for (const v of values)
|
27
|
+
if (v > value)
|
28
|
+
value = v;
|
29
|
+
return value;
|
30
|
+
},
|
31
|
+
};
|
@@ -0,0 +1,8 @@
|
|
1
|
+
export declare type FunctionPropertyNames<T> = {
|
2
|
+
[K in keyof T]: T[K] extends Function ? K : never;
|
3
|
+
}[keyof T];
|
4
|
+
export declare type FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>>;
|
5
|
+
export declare type NonFunctionPropertyNames<T> = {
|
6
|
+
[K in keyof T]: T[K] extends Function ? never : K;
|
7
|
+
}[keyof T];
|
8
|
+
export declare type NonFunctionProperties<T> = Pick<T, NonFunctionPropertyNames<T>>;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function blake2Concat(input: Uint8Array): `0x${string}`;
|
package/dist/decodeAnyAddress.js
CHANGED
@@ -1,44 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
for (let key of __getOwnPropNames(module2))
|
16
|
-
if (!__hasOwnProp.call(target, key) && key !== "default")
|
17
|
-
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
18
|
-
}
|
19
|
-
return target;
|
20
|
-
};
|
21
|
-
var __toModule = (module2) => {
|
22
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
23
|
-
};
|
24
|
-
__export(exports, {
|
25
|
-
decodeAnyAddress: () => decodeAnyAddress
|
26
|
-
});
|
27
|
-
var import_keyring = __toModule(require("@polkadot/keyring"));
|
28
|
-
var import_util_crypto = __toModule(require("@polkadot/util-crypto"));
|
29
|
-
var import_hexToBytes = __toModule(require("./hexToBytes"));
|
30
|
-
function decodeAnyAddress(encoded, ignoreChecksum, ss58Format) {
|
31
|
-
try {
|
32
|
-
return (0, import_keyring.decodeAddress)(encoded, ignoreChecksum, ss58Format);
|
33
|
-
} catch (error) {
|
34
|
-
if (typeof encoded !== "string")
|
35
|
-
throw error;
|
36
|
-
if (!(0, import_util_crypto.isEthereumAddress)(encoded))
|
37
|
-
throw error;
|
38
|
-
return (0, import_hexToBytes.hexToBytes)(encoded.slice("0x".length));
|
39
|
-
}
|
1
|
+
import { decodeAddress } from "@polkadot/keyring";
|
2
|
+
import { hexToU8a } from "@polkadot/util";
|
3
|
+
import { isEthereumAddress } from "@polkadot/util-crypto";
|
4
|
+
export function decodeAnyAddress(encoded, ignoreChecksum, ss58Format) {
|
5
|
+
try {
|
6
|
+
return decodeAddress(encoded, ignoreChecksum, ss58Format);
|
7
|
+
}
|
8
|
+
catch (error) {
|
9
|
+
if (typeof encoded !== "string")
|
10
|
+
throw error;
|
11
|
+
if (!isEthereumAddress(encoded))
|
12
|
+
throw error;
|
13
|
+
return hexToU8a(encoded.slice("0x".length));
|
14
|
+
}
|
40
15
|
}
|
41
|
-
// Annotate the CommonJS export names for ESM import in node:
|
42
|
-
0 && (module.exports = {
|
43
|
-
decodeAnyAddress
|
44
|
-
});
|
package/dist/encodeAnyAddress.js
CHANGED
@@ -1,43 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
15
|
-
for (let key of __getOwnPropNames(module2))
|
16
|
-
if (!__hasOwnProp.call(target, key) && key !== "default")
|
17
|
-
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
18
|
-
}
|
19
|
-
return target;
|
20
|
-
};
|
21
|
-
var __toModule = (module2) => {
|
22
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
23
|
-
};
|
24
|
-
__export(exports, {
|
25
|
-
encodeAnyAddress: () => encodeAnyAddress
|
26
|
-
});
|
27
|
-
var import_keyring = __toModule(require("@polkadot/keyring"));
|
28
|
-
var import_util_crypto = __toModule(require("@polkadot/util-crypto"));
|
29
|
-
function encodeAnyAddress(key, ss58Format) {
|
30
|
-
try {
|
31
|
-
return (0, import_keyring.encodeAddress)(key, ss58Format);
|
32
|
-
} catch (error) {
|
33
|
-
if (typeof key !== "string")
|
34
|
-
throw error;
|
35
|
-
if (!(0, import_util_crypto.isEthereumAddress)(key))
|
36
|
-
throw error;
|
37
|
-
return (0, import_util_crypto.ethereumEncode)(key);
|
38
|
-
}
|
1
|
+
import { encodeAddress } from "@polkadot/keyring";
|
2
|
+
import { ethereumEncode, isEthereumAddress } from "@polkadot/util-crypto";
|
3
|
+
export function encodeAnyAddress(key, ss58Format) {
|
4
|
+
try {
|
5
|
+
return encodeAddress(key, ss58Format);
|
6
|
+
}
|
7
|
+
catch (error) {
|
8
|
+
if (typeof key !== "string")
|
9
|
+
throw error;
|
10
|
+
if (!isEthereumAddress(key))
|
11
|
+
throw error;
|
12
|
+
return ethereumEncode(key);
|
13
|
+
}
|
39
14
|
}
|
40
|
-
// Annotate the CommonJS export names for ESM import in node:
|
41
|
-
0 && (module.exports = {
|
42
|
-
encodeAnyAddress
|
43
|
-
});
|
@@ -0,0 +1,11 @@
|
|
1
|
+
export declare const MAX_DECIMALS_FORMAT = 12;
|
2
|
+
/**
|
3
|
+
* Custom decimal number formatting for Talisman
|
4
|
+
* note that the NumberFormat().format() call is the ressource heavy part, it's not worth trying to optimize other parts
|
5
|
+
* @param num input number
|
6
|
+
* @param digits number of significant digits to display
|
7
|
+
* @param locale locale used to format the number
|
8
|
+
* @param options formatting options
|
9
|
+
* @returns the formatted value
|
10
|
+
*/
|
11
|
+
export declare const formatDecimals: (num?: string | number | null, digits?: number, options?: Partial<Intl.NumberFormatOptions>, locale?: string) => string;
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import BigNumber from "bignumber.js";
|
2
|
+
export const MAX_DECIMALS_FORMAT = 12;
|
3
|
+
/**
|
4
|
+
* Custom decimal number formatting for Talisman
|
5
|
+
* note that the NumberFormat().format() call is the ressource heavy part, it's not worth trying to optimize other parts
|
6
|
+
* @param num input number
|
7
|
+
* @param digits number of significant digits to display
|
8
|
+
* @param locale locale used to format the number
|
9
|
+
* @param options formatting options
|
10
|
+
* @returns the formatted value
|
11
|
+
*/
|
12
|
+
export const formatDecimals = (num, digits = 4, options = {}, locale = "en-US") => {
|
13
|
+
if (num === null || num === undefined)
|
14
|
+
return "";
|
15
|
+
const value = new BigNumber(num);
|
16
|
+
// very small numbers should display "< 0.0001"
|
17
|
+
const minDisplayVal = 1 / Math.pow(10, digits);
|
18
|
+
if (value.gt(0) && value.lt(minDisplayVal))
|
19
|
+
return `< ${formatDecimals(minDisplayVal)}`;
|
20
|
+
// count digits
|
21
|
+
const flooredValue = value.integerValue();
|
22
|
+
const intDigits = flooredValue.isEqualTo(0) ? 0 : flooredValue.toString().length;
|
23
|
+
// we never want to display a rounded up value
|
24
|
+
// to prevent JS default rounding, we will remove/truncate insignificant digits ourselves before formatting
|
25
|
+
let truncatedValue = value;
|
26
|
+
//remove insignificant fraction digits
|
27
|
+
const excessFractionDigitsPow10 = new BigNumber(10).pow(digits > intDigits ? digits - intDigits : 0);
|
28
|
+
truncatedValue = truncatedValue
|
29
|
+
.multipliedBy(excessFractionDigitsPow10)
|
30
|
+
.integerValue()
|
31
|
+
.dividedBy(excessFractionDigitsPow10);
|
32
|
+
//remove insignificant integer digits
|
33
|
+
const excessIntegerDigits = new BigNumber(intDigits > digits ? intDigits - digits : 0);
|
34
|
+
const excessIntegerDigitsPow10 = new BigNumber(10).pow(excessIntegerDigits);
|
35
|
+
if (excessIntegerDigits.gt(0))
|
36
|
+
truncatedValue = truncatedValue
|
37
|
+
.dividedBy(excessIntegerDigitsPow10)
|
38
|
+
.integerValue()
|
39
|
+
.multipliedBy(excessIntegerDigitsPow10);
|
40
|
+
// format
|
41
|
+
return Intl.NumberFormat(locale, Object.assign({
|
42
|
+
//compact notation (K, M, B) if above 9999
|
43
|
+
notation: truncatedValue.gt(9999) ? "compact" : "standard", maximumSignificantDigits: digits + (truncatedValue.lt(1) ? 1 : 0) }, options)).format(truncatedValue.toNumber());
|
44
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const getBase64ImageUrl: (base64: string) => string | null;
|
@@ -0,0 +1,8 @@
|
|
1
|
+
export const getBase64ImageUrl = (base64) => {
|
2
|
+
const match = /^data:([^;]*?);base64,(.*?)$/.exec(base64);
|
3
|
+
if (!match)
|
4
|
+
return null;
|
5
|
+
const buffer = Buffer.from(match[2], "base64");
|
6
|
+
const blob = new Blob([new Uint8Array(buffer, 0, buffer.length)], { type: match[1] });
|
7
|
+
return URL.createObjectURL(blob);
|
8
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function hasOwnProperty<X, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, unknown>;
|
package/dist/index.d.ts
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
-
export * from
|
2
|
-
export * from
|
3
|
-
export * from
|
4
|
-
export * from
|
5
|
-
export * from
|
6
|
-
export * from
|
7
|
-
export * from
|
8
|
-
export * from
|
9
|
-
export * from
|
1
|
+
export * from "./BigMath";
|
2
|
+
export * from "./FunctionPropertyNames";
|
3
|
+
export * from "./blake2Concat";
|
4
|
+
export * from "./decodeAnyAddress";
|
5
|
+
export * from "./encodeAnyAddress";
|
6
|
+
export * from "./formatDecimals";
|
7
|
+
export * from "./getBase64ImageUrl";
|
8
|
+
export * from "./hasOwnProperty";
|
9
|
+
export * from "./isArrayOf";
|
10
|
+
export * from "./planckToTokens";
|
11
|
+
export * from "./tokensToPlanck";
|
12
|
+
export * from "./twox64Concat";
|
package/dist/index.js
CHANGED
@@ -1,28 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
}
|
14
|
-
return target;
|
15
|
-
};
|
16
|
-
var __toModule = (module2) => {
|
17
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
18
|
-
};
|
19
|
-
__markAsModule(exports);
|
20
|
-
__reExport(exports, __toModule(require("./bigNumbers")));
|
21
|
-
__reExport(exports, __toModule(require("./chains")));
|
22
|
-
__reExport(exports, __toModule(require("./decodeAnyAddress")));
|
23
|
-
__reExport(exports, __toModule(require("./deferred")));
|
24
|
-
__reExport(exports, __toModule(require("./encodeAnyAddress")));
|
25
|
-
__reExport(exports, __toModule(require("./hexToBytes")));
|
26
|
-
__reExport(exports, __toModule(require("./planckToTokens")));
|
27
|
-
__reExport(exports, __toModule(require("./tokensToPlanck")));
|
28
|
-
__reExport(exports, __toModule(require("./useFuncMemo")));
|
1
|
+
export * from "./BigMath";
|
2
|
+
export * from "./FunctionPropertyNames";
|
3
|
+
export * from "./blake2Concat";
|
4
|
+
export * from "./decodeAnyAddress";
|
5
|
+
export * from "./encodeAnyAddress";
|
6
|
+
export * from "./formatDecimals";
|
7
|
+
export * from "./getBase64ImageUrl";
|
8
|
+
export * from "./hasOwnProperty";
|
9
|
+
export * from "./isArrayOf";
|
10
|
+
export * from "./planckToTokens";
|
11
|
+
export * from "./tokensToPlanck";
|
12
|
+
export * from "./twox64Concat";
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function isArrayOf<T, P extends Array<unknown>>(array: unknown[], func: new (...args: P) => T): array is T[];
|
package/dist/planckToTokens.js
CHANGED
@@ -1,39 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
__markAsModule(target);
|
10
|
-
for (var name in all)
|
11
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
12
|
-
};
|
13
|
-
var __reExport = (target, module2, desc) => {
|
14
|
-
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
15
|
-
for (let key of __getOwnPropNames(module2))
|
16
|
-
if (!__hasOwnProp.call(target, key) && key !== "default")
|
17
|
-
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
18
|
-
}
|
19
|
-
return target;
|
20
|
-
};
|
21
|
-
var __toModule = (module2) => {
|
22
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
23
|
-
};
|
24
|
-
__export(exports, {
|
25
|
-
planckToTokens: () => planckToTokens
|
26
|
-
});
|
27
|
-
var import_bignumber = __toModule(require("bignumber.js"));
|
28
|
-
function planckToTokens(planck, tokenDecimals) {
|
29
|
-
if (typeof planck !== "string" || typeof tokenDecimals !== "number")
|
30
|
-
return;
|
31
|
-
const base = new import_bignumber.default(10);
|
32
|
-
const exponent = new import_bignumber.default(tokenDecimals).negated();
|
33
|
-
const multiplier = base.pow(exponent);
|
34
|
-
return new import_bignumber.default(planck).multipliedBy(multiplier).toString();
|
1
|
+
import BigNumber from "bignumber.js";
|
2
|
+
export function planckToTokens(planck, tokenDecimals) {
|
3
|
+
if (typeof planck !== "string" || typeof tokenDecimals !== "number")
|
4
|
+
return;
|
5
|
+
const base = new BigNumber(10);
|
6
|
+
const exponent = new BigNumber(tokenDecimals).negated();
|
7
|
+
const multiplier = base.pow(exponent);
|
8
|
+
return new BigNumber(planck).multipliedBy(multiplier).toString(10);
|
35
9
|
}
|
36
|
-
// Annotate the CommonJS export names for ESM import in node:
|
37
|
-
0 && (module.exports = {
|
38
|
-
planckToTokens
|
39
|
-
});
|
package/dist/tokensToPlanck.js
CHANGED
@@ -1,39 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
__markAsModule(target);
|
10
|
-
for (var name in all)
|
11
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
12
|
-
};
|
13
|
-
var __reExport = (target, module2, desc) => {
|
14
|
-
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
15
|
-
for (let key of __getOwnPropNames(module2))
|
16
|
-
if (!__hasOwnProp.call(target, key) && key !== "default")
|
17
|
-
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
18
|
-
}
|
19
|
-
return target;
|
20
|
-
};
|
21
|
-
var __toModule = (module2) => {
|
22
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
23
|
-
};
|
24
|
-
__export(exports, {
|
25
|
-
tokensToPlanck: () => tokensToPlanck
|
26
|
-
});
|
27
|
-
var import_bignumber = __toModule(require("bignumber.js"));
|
28
|
-
function tokensToPlanck(tokens, tokenDecimals) {
|
29
|
-
if (typeof tokens !== "string" || typeof tokenDecimals !== "number")
|
30
|
-
return;
|
31
|
-
const base = new import_bignumber.default(10);
|
32
|
-
const exponent = new import_bignumber.default(tokenDecimals);
|
33
|
-
const multiplier = base.pow(exponent);
|
34
|
-
return new import_bignumber.default(tokens).multipliedBy(multiplier).toString();
|
1
|
+
import BigNumber from "bignumber.js";
|
2
|
+
export function tokensToPlanck(tokens, tokenDecimals) {
|
3
|
+
if (typeof tokens !== "string" || typeof tokenDecimals !== "number")
|
4
|
+
return;
|
5
|
+
const base = new BigNumber(10);
|
6
|
+
const exponent = new BigNumber(tokenDecimals);
|
7
|
+
const multiplier = base.pow(exponent);
|
8
|
+
return new BigNumber(tokens).multipliedBy(multiplier).toString(10);
|
35
9
|
}
|
36
|
-
// Annotate the CommonJS export names for ESM import in node:
|
37
|
-
0 && (module.exports = {
|
38
|
-
tokensToPlanck
|
39
|
-
});
|
package/package.json
CHANGED
@@ -1,73 +1,53 @@
|
|
1
1
|
{
|
2
2
|
"name": "@talismn/util",
|
3
|
-
"version": "0.
|
4
|
-
"description": "A set of util functions for working with polkadot & talisman data.",
|
5
|
-
"main": "./src/index.ts",
|
6
|
-
"types": "./dist/index.d.ts",
|
7
|
-
"browser": "./dist/index.js",
|
8
|
-
"exports": "./dist/index.js",
|
9
|
-
"scripts": {
|
10
|
-
"prepare": "husky install",
|
11
|
-
"pre-commit": "lint-staged",
|
12
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
13
|
-
"watch": "nodemon --watch src --ext js,ts --exec yarn prepack",
|
14
|
-
"build": "esbuild-node-tsc",
|
15
|
-
"build:types": "tsc --emitDeclarationOnly",
|
16
|
-
"prepack": "yarn build && yarn build:types"
|
17
|
-
},
|
3
|
+
"version": "0.1.2",
|
18
4
|
"author": "Talisman",
|
19
|
-
"
|
20
|
-
"
|
21
|
-
|
22
|
-
"
|
23
|
-
"@polkadot/util-crypto": "*",
|
24
|
-
"react": ">=17"
|
25
|
-
},
|
26
|
-
"dependencies": {
|
27
|
-
"@polkadot/extension-inject": "^0.39.3",
|
28
|
-
"@polkadot/networks": "^7.3.1",
|
29
|
-
"bignumber.js": "^9.0.1"
|
5
|
+
"homepage": "https://talisman.xyz",
|
6
|
+
"license": "UNLICENSED",
|
7
|
+
"publishConfig": {
|
8
|
+
"access": "public"
|
30
9
|
},
|
31
|
-
"devDependencies": {
|
32
|
-
"@polkadot/api": "^5.9.1",
|
33
|
-
"@polkadot/keyring": "^7.4.1",
|
34
|
-
"@polkadot/util-crypto": "^7.4.1",
|
35
|
-
"@types/react": "^17.0.2",
|
36
|
-
"esbuild-node-tsc": "^1.6.1",
|
37
|
-
"husky": "^6.0.0",
|
38
|
-
"import-sort-style-module": "^6.0.0",
|
39
|
-
"lint-staged": "^11.1.2",
|
40
|
-
"prettier": "^2.3.2",
|
41
|
-
"prettier-plugin-import-sort": "^0.0.7",
|
42
|
-
"react": "^17.0.2",
|
43
|
-
"typescript": "^4.3.5"
|
44
|
-
},
|
45
|
-
"files": [
|
46
|
-
"dist/**/*"
|
47
|
-
],
|
48
10
|
"repository": {
|
11
|
+
"directory": "packages/util",
|
49
12
|
"type": "git",
|
50
|
-
"url": "
|
13
|
+
"url": "https://github.com/talismansociety/talisman.git"
|
51
14
|
},
|
52
|
-
"
|
53
|
-
|
15
|
+
"main": "dist/index.js",
|
16
|
+
"types": "dist/index.d.ts",
|
17
|
+
"files": [
|
18
|
+
"/dist"
|
19
|
+
],
|
20
|
+
"engines": {
|
21
|
+
"node": ">=14"
|
54
22
|
},
|
55
|
-
"
|
56
|
-
|
57
|
-
|
58
|
-
"
|
23
|
+
"scripts": {
|
24
|
+
"dev": "tsc --watch --declarationMap",
|
25
|
+
"build": "tsc --declarationMap",
|
26
|
+
"build:packages:prod": "rm -rf dist && tsc",
|
27
|
+
"prepack": "yarn build:packages:prod",
|
28
|
+
"test": "jest",
|
29
|
+
"lint": "eslint . --max-warnings 0",
|
30
|
+
"clean": "rm -rf dist && rm -rf .turbo rm -rf node_modules"
|
59
31
|
},
|
60
|
-
"
|
61
|
-
"
|
62
|
-
"
|
63
|
-
"
|
64
|
-
"
|
65
|
-
"singleQuote": true
|
32
|
+
"dependencies": {
|
33
|
+
"@polkadot/keyring": "^10.1.7",
|
34
|
+
"@polkadot/util": "^10.1.7",
|
35
|
+
"@polkadot/util-crypto": "^10.1.7",
|
36
|
+
"bignumber.js": "^9.1.0"
|
66
37
|
},
|
67
|
-
"
|
68
|
-
"
|
69
|
-
|
70
|
-
|
71
|
-
|
38
|
+
"devDependencies": {
|
39
|
+
"@talismn/eslint-config": "^0.0.0",
|
40
|
+
"@talismn/tsconfig": "^0.0.0",
|
41
|
+
"@types/jest": "^27.5.1",
|
42
|
+
"eslint": "^8.4.0",
|
43
|
+
"jest": "^28.1.0",
|
44
|
+
"ts-jest": "^28.0.2",
|
45
|
+
"typescript": "^4.6.4"
|
46
|
+
},
|
47
|
+
"eslintConfig": {
|
48
|
+
"root": true,
|
49
|
+
"extends": [
|
50
|
+
"@talismn/eslint-config"
|
51
|
+
]
|
72
52
|
}
|
73
53
|
}
|