@w3ux/utils 1.1.1-beta.8 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/base.cjs +3 -0
- package/base.d.cts +6 -1
- package/base.d.ts +6 -1
- package/base.js +2 -0
- package/index.cjs +4 -16
- package/index.d.cts +2 -2
- package/index.d.ts +2 -2
- package/index.js +3 -15
- package/package.json +2 -3
- package/unit.cjs +2 -42
- package/unit.d.cts +1 -6
- package/unit.d.ts +1 -6
- package/unit.js +2 -43
package/base.cjs
CHANGED
|
@@ -32,6 +32,7 @@ __export(base_exports, {
|
|
|
32
32
|
pageFromUri: () => pageFromUri,
|
|
33
33
|
removeHexPrefix: () => removeHexPrefix,
|
|
34
34
|
rmCommas: () => rmCommas,
|
|
35
|
+
rmDecimals: () => rmDecimals,
|
|
35
36
|
shuffle: () => shuffle,
|
|
36
37
|
withTimeout: () => withTimeout
|
|
37
38
|
});
|
|
@@ -110,6 +111,7 @@ var pageFromUri = (pathname, fallback) => {
|
|
|
110
111
|
return page.trim();
|
|
111
112
|
};
|
|
112
113
|
var rmCommas = (val) => val.replace(/,/g, "");
|
|
114
|
+
var rmDecimals = (str) => str.split(".")[0];
|
|
113
115
|
var shuffle = (array) => {
|
|
114
116
|
let currentIndex = array.length;
|
|
115
117
|
let randomIndex;
|
|
@@ -171,6 +173,7 @@ var minBigInt = (...values) => values.reduce((min, current) => current < min ? c
|
|
|
171
173
|
pageFromUri,
|
|
172
174
|
removeHexPrefix,
|
|
173
175
|
rmCommas,
|
|
176
|
+
rmDecimals,
|
|
174
177
|
shuffle,
|
|
175
178
|
withTimeout
|
|
176
179
|
});
|
package/base.d.cts
CHANGED
|
@@ -43,6 +43,11 @@ declare const pageFromUri: (pathname: string, fallback: string) => string;
|
|
|
43
43
|
* @summary Removes the commas from a string.
|
|
44
44
|
*/
|
|
45
45
|
declare const rmCommas: (val: string) => string;
|
|
46
|
+
/**
|
|
47
|
+
* @name rmDecimals
|
|
48
|
+
* @summary Removes the decimal point and decimals from a string.
|
|
49
|
+
*/
|
|
50
|
+
declare const rmDecimals: (str: any) => any;
|
|
46
51
|
/**
|
|
47
52
|
* @name shuffle
|
|
48
53
|
* @summary Shuffle a set of objects.
|
|
@@ -101,4 +106,4 @@ declare const maxBigInt: (...values: bigint[]) => bigint;
|
|
|
101
106
|
*/
|
|
102
107
|
declare const minBigInt: (...values: bigint[]) => bigint;
|
|
103
108
|
|
|
104
|
-
export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, maxBigInt, minBigInt, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout };
|
|
109
|
+
export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, maxBigInt, minBigInt, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, rmDecimals, shuffle, withTimeout };
|
package/base.d.ts
CHANGED
|
@@ -43,6 +43,11 @@ declare const pageFromUri: (pathname: string, fallback: string) => string;
|
|
|
43
43
|
* @summary Removes the commas from a string.
|
|
44
44
|
*/
|
|
45
45
|
declare const rmCommas: (val: string) => string;
|
|
46
|
+
/**
|
|
47
|
+
* @name rmDecimals
|
|
48
|
+
* @summary Removes the decimal point and decimals from a string.
|
|
49
|
+
*/
|
|
50
|
+
declare const rmDecimals: (str: any) => any;
|
|
46
51
|
/**
|
|
47
52
|
* @name shuffle
|
|
48
53
|
* @summary Shuffle a set of objects.
|
|
@@ -101,4 +106,4 @@ declare const maxBigInt: (...values: bigint[]) => bigint;
|
|
|
101
106
|
*/
|
|
102
107
|
declare const minBigInt: (...values: bigint[]) => bigint;
|
|
103
108
|
|
|
104
|
-
export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, maxBigInt, minBigInt, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout };
|
|
109
|
+
export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, maxBigInt, minBigInt, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, rmDecimals, shuffle, withTimeout };
|
package/base.js
CHANGED
|
@@ -73,6 +73,7 @@ var pageFromUri = (pathname, fallback) => {
|
|
|
73
73
|
return page.trim();
|
|
74
74
|
};
|
|
75
75
|
var rmCommas = (val) => val.replace(/,/g, "");
|
|
76
|
+
var rmDecimals = (str) => str.split(".")[0];
|
|
76
77
|
var shuffle = (array) => {
|
|
77
78
|
let currentIndex = array.length;
|
|
78
79
|
let randomIndex;
|
|
@@ -133,6 +134,7 @@ export {
|
|
|
133
134
|
pageFromUri,
|
|
134
135
|
removeHexPrefix,
|
|
135
136
|
rmCommas,
|
|
137
|
+
rmDecimals,
|
|
136
138
|
shuffle,
|
|
137
139
|
withTimeout
|
|
138
140
|
};
|
package/index.cjs
CHANGED
|
@@ -25,7 +25,6 @@ __export(src_exports, {
|
|
|
25
25
|
applyWidthAsPadding: () => applyWidthAsPadding,
|
|
26
26
|
camelize: () => camelize,
|
|
27
27
|
capitalizeFirstLetter: () => capitalizeFirstLetter,
|
|
28
|
-
determinePoolDisplay: () => determinePoolDisplay,
|
|
29
28
|
ellipsisFn: () => ellipsisFn,
|
|
30
29
|
eqSet: () => eqSet,
|
|
31
30
|
extractUrlValue: () => extractUrlValue,
|
|
@@ -48,6 +47,7 @@ __export(src_exports, {
|
|
|
48
47
|
removeVarFromUrlHash: () => removeVarFromUrlHash,
|
|
49
48
|
removedFrom: () => removedFrom,
|
|
50
49
|
rmCommas: () => rmCommas,
|
|
50
|
+
rmDecimals: () => rmDecimals,
|
|
51
51
|
setStateWithRef: () => setStateWithRef,
|
|
52
52
|
shuffle: () => shuffle,
|
|
53
53
|
snakeToCamel: () => snakeToCamel,
|
|
@@ -136,6 +136,7 @@ var pageFromUri = (pathname, fallback) => {
|
|
|
136
136
|
return page.trim();
|
|
137
137
|
};
|
|
138
138
|
var rmCommas = (val) => val.replace(/,/g, "");
|
|
139
|
+
var rmDecimals = (str) => str.split(".")[0];
|
|
139
140
|
var shuffle = (array) => {
|
|
140
141
|
let currentIndex = array.length;
|
|
141
142
|
let randomIndex;
|
|
@@ -196,13 +197,12 @@ var u8aConcat = (...u8as) => {
|
|
|
196
197
|
};
|
|
197
198
|
|
|
198
199
|
// src/unit.ts
|
|
199
|
-
var import_util = require("@polkadot/util");
|
|
200
200
|
var import_substrate_bindings2 = require("@polkadot-api/substrate-bindings");
|
|
201
201
|
var planckToUnit = (val, units) => {
|
|
202
202
|
try {
|
|
203
203
|
units = Math.max(Math.round(units), 0);
|
|
204
204
|
const bigIntVal = typeof val === "bigint" ? val : BigInt(
|
|
205
|
-
typeof val === "number" ? Math.floor(val).toString() : rmCommas(val)
|
|
205
|
+
typeof val === "number" ? Math.floor(val).toString() : rmDecimals(rmCommas(val))
|
|
206
206
|
);
|
|
207
207
|
const divisor = units === 0 ? 1n : BigInt(10) ** BigInt(units);
|
|
208
208
|
const integerPart = bigIntVal / divisor;
|
|
@@ -262,18 +262,6 @@ var isValidAddress = (address) => {
|
|
|
262
262
|
return false;
|
|
263
263
|
}
|
|
264
264
|
};
|
|
265
|
-
var determinePoolDisplay = (address, batchItem) => {
|
|
266
|
-
const defaultDisplay = ellipsisFn(address, 6);
|
|
267
|
-
let display = batchItem ?? defaultDisplay;
|
|
268
|
-
const displayAsBytes = (0, import_util.u8aToString)((0, import_util.u8aUnwrapBytes)(display));
|
|
269
|
-
if (displayAsBytes !== "") {
|
|
270
|
-
display = displayAsBytes;
|
|
271
|
-
}
|
|
272
|
-
if (display === "") {
|
|
273
|
-
display = defaultDisplay;
|
|
274
|
-
}
|
|
275
|
-
return display;
|
|
276
|
-
};
|
|
277
265
|
var extractUrlValue = (key, url) => {
|
|
278
266
|
if (typeof url === "undefined") {
|
|
279
267
|
url = window.location.href;
|
|
@@ -414,7 +402,6 @@ var mergeDeep = (target, ...sources) => {
|
|
|
414
402
|
applyWidthAsPadding,
|
|
415
403
|
camelize,
|
|
416
404
|
capitalizeFirstLetter,
|
|
417
|
-
determinePoolDisplay,
|
|
418
405
|
ellipsisFn,
|
|
419
406
|
eqSet,
|
|
420
407
|
extractUrlValue,
|
|
@@ -437,6 +424,7 @@ var mergeDeep = (target, ...sources) => {
|
|
|
437
424
|
removeVarFromUrlHash,
|
|
438
425
|
removedFrom,
|
|
439
426
|
rmCommas,
|
|
427
|
+
rmDecimals,
|
|
440
428
|
setStateWithRef,
|
|
441
429
|
shuffle,
|
|
442
430
|
snakeToCamel,
|
package/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, maxBigInt, minBigInt, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout } from './base.cjs';
|
|
1
|
+
export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, maxBigInt, minBigInt, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, rmDecimals, shuffle, withTimeout } from './base.cjs';
|
|
2
2
|
export { u8aConcat } from './convert.cjs';
|
|
3
|
-
export { addedTo, applyWidthAsPadding, capitalizeFirstLetter,
|
|
3
|
+
export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, extractUrlValue, inChrome, isValidAddress, isValidHttpUrl, localStorageOrDefault, makeCancelable, matchedProperties, mergeDeep, planckToUnit, remToUnit, removeVarFromUrlHash, removedFrom, setStateWithRef, snakeToCamel, sortWithNull, unescape, unimplemented, unitToPlanck, varToUrlHash } from './unit.cjs';
|
|
4
4
|
import '@w3ux/types';
|
|
5
5
|
import 'react';
|
|
6
6
|
import './types.cjs';
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, maxBigInt, minBigInt, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout } from './base.js';
|
|
1
|
+
export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, maxBigInt, minBigInt, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, rmDecimals, shuffle, withTimeout } from './base.js';
|
|
2
2
|
export { u8aConcat } from './convert.js';
|
|
3
|
-
export { addedTo, applyWidthAsPadding, capitalizeFirstLetter,
|
|
3
|
+
export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, extractUrlValue, inChrome, isValidAddress, isValidHttpUrl, localStorageOrDefault, makeCancelable, matchedProperties, mergeDeep, planckToUnit, remToUnit, removeVarFromUrlHash, removedFrom, setStateWithRef, snakeToCamel, sortWithNull, unescape, unimplemented, unitToPlanck, varToUrlHash } from './unit.js';
|
|
4
4
|
import '@w3ux/types';
|
|
5
5
|
import 'react';
|
|
6
6
|
import './types.js';
|
package/index.js
CHANGED
|
@@ -73,6 +73,7 @@ var pageFromUri = (pathname, fallback) => {
|
|
|
73
73
|
return page.trim();
|
|
74
74
|
};
|
|
75
75
|
var rmCommas = (val) => val.replace(/,/g, "");
|
|
76
|
+
var rmDecimals = (str) => str.split(".")[0];
|
|
76
77
|
var shuffle = (array) => {
|
|
77
78
|
let currentIndex = array.length;
|
|
78
79
|
let randomIndex;
|
|
@@ -133,13 +134,12 @@ var u8aConcat = (...u8as) => {
|
|
|
133
134
|
};
|
|
134
135
|
|
|
135
136
|
// src/unit.ts
|
|
136
|
-
import { u8aToString, u8aUnwrapBytes } from "@polkadot/util";
|
|
137
137
|
import { AccountId as AccountId2 } from "@polkadot-api/substrate-bindings";
|
|
138
138
|
var planckToUnit = (val, units) => {
|
|
139
139
|
try {
|
|
140
140
|
units = Math.max(Math.round(units), 0);
|
|
141
141
|
const bigIntVal = typeof val === "bigint" ? val : BigInt(
|
|
142
|
-
typeof val === "number" ? Math.floor(val).toString() : rmCommas(val)
|
|
142
|
+
typeof val === "number" ? Math.floor(val).toString() : rmDecimals(rmCommas(val))
|
|
143
143
|
);
|
|
144
144
|
const divisor = units === 0 ? 1n : BigInt(10) ** BigInt(units);
|
|
145
145
|
const integerPart = bigIntVal / divisor;
|
|
@@ -199,18 +199,6 @@ var isValidAddress = (address) => {
|
|
|
199
199
|
return false;
|
|
200
200
|
}
|
|
201
201
|
};
|
|
202
|
-
var determinePoolDisplay = (address, batchItem) => {
|
|
203
|
-
const defaultDisplay = ellipsisFn(address, 6);
|
|
204
|
-
let display = batchItem ?? defaultDisplay;
|
|
205
|
-
const displayAsBytes = u8aToString(u8aUnwrapBytes(display));
|
|
206
|
-
if (displayAsBytes !== "") {
|
|
207
|
-
display = displayAsBytes;
|
|
208
|
-
}
|
|
209
|
-
if (display === "") {
|
|
210
|
-
display = defaultDisplay;
|
|
211
|
-
}
|
|
212
|
-
return display;
|
|
213
|
-
};
|
|
214
202
|
var extractUrlValue = (key, url) => {
|
|
215
203
|
if (typeof url === "undefined") {
|
|
216
204
|
url = window.location.href;
|
|
@@ -350,7 +338,6 @@ export {
|
|
|
350
338
|
applyWidthAsPadding,
|
|
351
339
|
camelize,
|
|
352
340
|
capitalizeFirstLetter,
|
|
353
|
-
determinePoolDisplay,
|
|
354
341
|
ellipsisFn,
|
|
355
342
|
eqSet,
|
|
356
343
|
extractUrlValue,
|
|
@@ -373,6 +360,7 @@ export {
|
|
|
373
360
|
removeVarFromUrlHash,
|
|
374
361
|
removedFrom,
|
|
375
362
|
rmCommas,
|
|
363
|
+
rmDecimals,
|
|
376
364
|
setStateWithRef,
|
|
377
365
|
shuffle,
|
|
378
366
|
snakeToCamel,
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@w3ux/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"license": "GPL-3.0-only",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@polkadot-api/substrate-bindings": "^0.9.3"
|
|
7
|
-
"@polkadot/util": "^13.2.2"
|
|
6
|
+
"@polkadot-api/substrate-bindings": "^0.9.3"
|
|
8
7
|
},
|
|
9
8
|
"main": "index.cjs",
|
|
10
9
|
"module": "index.js",
|
package/unit.cjs
CHANGED
|
@@ -22,7 +22,6 @@ __export(unit_exports, {
|
|
|
22
22
|
addedTo: () => addedTo,
|
|
23
23
|
applyWidthAsPadding: () => applyWidthAsPadding,
|
|
24
24
|
capitalizeFirstLetter: () => capitalizeFirstLetter,
|
|
25
|
-
determinePoolDisplay: () => determinePoolDisplay,
|
|
26
25
|
extractUrlValue: () => extractUrlValue,
|
|
27
26
|
inChrome: () => inChrome,
|
|
28
27
|
isValidAddress: () => isValidAddress,
|
|
@@ -44,37 +43,11 @@ __export(unit_exports, {
|
|
|
44
43
|
varToUrlHash: () => varToUrlHash
|
|
45
44
|
});
|
|
46
45
|
module.exports = __toCommonJS(unit_exports);
|
|
47
|
-
var import_util = require("@polkadot/util");
|
|
48
46
|
|
|
49
47
|
// src/base.ts
|
|
50
48
|
var import_substrate_bindings = require("@polkadot-api/substrate-bindings");
|
|
51
|
-
var ellipsisFn = (str, amount = 6, position = "center") => {
|
|
52
|
-
const half = str.length / 2;
|
|
53
|
-
if (amount <= 4) {
|
|
54
|
-
if (position === "center") {
|
|
55
|
-
return str.slice(0, 4) + "..." + str.slice(-4);
|
|
56
|
-
}
|
|
57
|
-
if (position === "end") {
|
|
58
|
-
return str.slice(0, 4) + "...";
|
|
59
|
-
}
|
|
60
|
-
return "..." + str.slice(-4);
|
|
61
|
-
}
|
|
62
|
-
if (position === "center") {
|
|
63
|
-
return amount >= (str.length - 2) / 2 ? str.slice(0, half - 3) + "..." + str.slice(-(half - 3)) : str.slice(0, amount) + "..." + str.slice(-amount);
|
|
64
|
-
}
|
|
65
|
-
if (amount >= str.length) {
|
|
66
|
-
if (position === "end") {
|
|
67
|
-
return str.slice(0, str.length - 3) + "...";
|
|
68
|
-
}
|
|
69
|
-
return "..." + str.slice(-(str.length - 3));
|
|
70
|
-
} else {
|
|
71
|
-
if (position === "end") {
|
|
72
|
-
return str.slice(0, amount) + "...";
|
|
73
|
-
}
|
|
74
|
-
return "..." + str.slice(amount);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
49
|
var rmCommas = (val) => val.replace(/,/g, "");
|
|
50
|
+
var rmDecimals = (str) => str.split(".")[0];
|
|
78
51
|
|
|
79
52
|
// src/unit.ts
|
|
80
53
|
var import_substrate_bindings2 = require("@polkadot-api/substrate-bindings");
|
|
@@ -82,7 +55,7 @@ var planckToUnit = (val, units) => {
|
|
|
82
55
|
try {
|
|
83
56
|
units = Math.max(Math.round(units), 0);
|
|
84
57
|
const bigIntVal = typeof val === "bigint" ? val : BigInt(
|
|
85
|
-
typeof val === "number" ? Math.floor(val).toString() : rmCommas(val)
|
|
58
|
+
typeof val === "number" ? Math.floor(val).toString() : rmDecimals(rmCommas(val))
|
|
86
59
|
);
|
|
87
60
|
const divisor = units === 0 ? 1n : BigInt(10) ** BigInt(units);
|
|
88
61
|
const integerPart = bigIntVal / divisor;
|
|
@@ -142,18 +115,6 @@ var isValidAddress = (address) => {
|
|
|
142
115
|
return false;
|
|
143
116
|
}
|
|
144
117
|
};
|
|
145
|
-
var determinePoolDisplay = (address, batchItem) => {
|
|
146
|
-
const defaultDisplay = ellipsisFn(address, 6);
|
|
147
|
-
let display = batchItem ?? defaultDisplay;
|
|
148
|
-
const displayAsBytes = (0, import_util.u8aToString)((0, import_util.u8aUnwrapBytes)(display));
|
|
149
|
-
if (displayAsBytes !== "") {
|
|
150
|
-
display = displayAsBytes;
|
|
151
|
-
}
|
|
152
|
-
if (display === "") {
|
|
153
|
-
display = defaultDisplay;
|
|
154
|
-
}
|
|
155
|
-
return display;
|
|
156
|
-
};
|
|
157
118
|
var extractUrlValue = (key, url) => {
|
|
158
119
|
if (typeof url === "undefined") {
|
|
159
120
|
url = window.location.href;
|
|
@@ -291,7 +252,6 @@ var mergeDeep = (target, ...sources) => {
|
|
|
291
252
|
addedTo,
|
|
292
253
|
applyWidthAsPadding,
|
|
293
254
|
capitalizeFirstLetter,
|
|
294
|
-
determinePoolDisplay,
|
|
295
255
|
extractUrlValue,
|
|
296
256
|
inChrome,
|
|
297
257
|
isValidAddress,
|
package/unit.d.cts
CHANGED
|
@@ -57,11 +57,6 @@ declare const localStorageOrDefault: <T>(key: string, _default: T, parse?: boole
|
|
|
57
57
|
* @summary Return whether an address is valid Substrate address.
|
|
58
58
|
*/
|
|
59
59
|
declare const isValidAddress: (address: string) => boolean;
|
|
60
|
-
/**
|
|
61
|
-
* @name determinePoolDisplay
|
|
62
|
-
* @summary A pool will be displayed with either its set metadata or its address.
|
|
63
|
-
*/
|
|
64
|
-
declare const determinePoolDisplay: (address: string, batchItem: AnyJson) => any;
|
|
65
60
|
/**
|
|
66
61
|
* @name extractUrlValue
|
|
67
62
|
* @summary Extracts a URL value from a URL string.
|
|
@@ -150,4 +145,4 @@ declare const unimplemented: ({ ...props }: {
|
|
|
150
145
|
*/
|
|
151
146
|
declare const mergeDeep: (target: AnyObject, ...sources: AnyObject[]) => AnyObject;
|
|
152
147
|
|
|
153
|
-
export { addedTo, applyWidthAsPadding, capitalizeFirstLetter,
|
|
148
|
+
export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, extractUrlValue, inChrome, isValidAddress, isValidHttpUrl, localStorageOrDefault, makeCancelable, matchedProperties, mergeDeep, planckToUnit, remToUnit, removeVarFromUrlHash, removedFrom, setStateWithRef, snakeToCamel, sortWithNull, unescape, unimplemented, unitToPlanck, varToUrlHash };
|
package/unit.d.ts
CHANGED
|
@@ -57,11 +57,6 @@ declare const localStorageOrDefault: <T>(key: string, _default: T, parse?: boole
|
|
|
57
57
|
* @summary Return whether an address is valid Substrate address.
|
|
58
58
|
*/
|
|
59
59
|
declare const isValidAddress: (address: string) => boolean;
|
|
60
|
-
/**
|
|
61
|
-
* @name determinePoolDisplay
|
|
62
|
-
* @summary A pool will be displayed with either its set metadata or its address.
|
|
63
|
-
*/
|
|
64
|
-
declare const determinePoolDisplay: (address: string, batchItem: AnyJson) => any;
|
|
65
60
|
/**
|
|
66
61
|
* @name extractUrlValue
|
|
67
62
|
* @summary Extracts a URL value from a URL string.
|
|
@@ -150,4 +145,4 @@ declare const unimplemented: ({ ...props }: {
|
|
|
150
145
|
*/
|
|
151
146
|
declare const mergeDeep: (target: AnyObject, ...sources: AnyObject[]) => AnyObject;
|
|
152
147
|
|
|
153
|
-
export { addedTo, applyWidthAsPadding, capitalizeFirstLetter,
|
|
148
|
+
export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, extractUrlValue, inChrome, isValidAddress, isValidHttpUrl, localStorageOrDefault, makeCancelable, matchedProperties, mergeDeep, planckToUnit, remToUnit, removeVarFromUrlHash, removedFrom, setStateWithRef, snakeToCamel, sortWithNull, unescape, unimplemented, unitToPlanck, varToUrlHash };
|
package/unit.js
CHANGED
|
@@ -1,35 +1,7 @@
|
|
|
1
|
-
// src/unit.ts
|
|
2
|
-
import { u8aToString, u8aUnwrapBytes } from "@polkadot/util";
|
|
3
|
-
|
|
4
1
|
// src/base.ts
|
|
5
2
|
import { AccountId } from "@polkadot-api/substrate-bindings";
|
|
6
|
-
var ellipsisFn = (str, amount = 6, position = "center") => {
|
|
7
|
-
const half = str.length / 2;
|
|
8
|
-
if (amount <= 4) {
|
|
9
|
-
if (position === "center") {
|
|
10
|
-
return str.slice(0, 4) + "..." + str.slice(-4);
|
|
11
|
-
}
|
|
12
|
-
if (position === "end") {
|
|
13
|
-
return str.slice(0, 4) + "...";
|
|
14
|
-
}
|
|
15
|
-
return "..." + str.slice(-4);
|
|
16
|
-
}
|
|
17
|
-
if (position === "center") {
|
|
18
|
-
return amount >= (str.length - 2) / 2 ? str.slice(0, half - 3) + "..." + str.slice(-(half - 3)) : str.slice(0, amount) + "..." + str.slice(-amount);
|
|
19
|
-
}
|
|
20
|
-
if (amount >= str.length) {
|
|
21
|
-
if (position === "end") {
|
|
22
|
-
return str.slice(0, str.length - 3) + "...";
|
|
23
|
-
}
|
|
24
|
-
return "..." + str.slice(-(str.length - 3));
|
|
25
|
-
} else {
|
|
26
|
-
if (position === "end") {
|
|
27
|
-
return str.slice(0, amount) + "...";
|
|
28
|
-
}
|
|
29
|
-
return "..." + str.slice(amount);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
3
|
var rmCommas = (val) => val.replace(/,/g, "");
|
|
4
|
+
var rmDecimals = (str) => str.split(".")[0];
|
|
33
5
|
|
|
34
6
|
// src/unit.ts
|
|
35
7
|
import { AccountId as AccountId2 } from "@polkadot-api/substrate-bindings";
|
|
@@ -37,7 +9,7 @@ var planckToUnit = (val, units) => {
|
|
|
37
9
|
try {
|
|
38
10
|
units = Math.max(Math.round(units), 0);
|
|
39
11
|
const bigIntVal = typeof val === "bigint" ? val : BigInt(
|
|
40
|
-
typeof val === "number" ? Math.floor(val).toString() : rmCommas(val)
|
|
12
|
+
typeof val === "number" ? Math.floor(val).toString() : rmDecimals(rmCommas(val))
|
|
41
13
|
);
|
|
42
14
|
const divisor = units === 0 ? 1n : BigInt(10) ** BigInt(units);
|
|
43
15
|
const integerPart = bigIntVal / divisor;
|
|
@@ -97,18 +69,6 @@ var isValidAddress = (address) => {
|
|
|
97
69
|
return false;
|
|
98
70
|
}
|
|
99
71
|
};
|
|
100
|
-
var determinePoolDisplay = (address, batchItem) => {
|
|
101
|
-
const defaultDisplay = ellipsisFn(address, 6);
|
|
102
|
-
let display = batchItem ?? defaultDisplay;
|
|
103
|
-
const displayAsBytes = u8aToString(u8aUnwrapBytes(display));
|
|
104
|
-
if (displayAsBytes !== "") {
|
|
105
|
-
display = displayAsBytes;
|
|
106
|
-
}
|
|
107
|
-
if (display === "") {
|
|
108
|
-
display = defaultDisplay;
|
|
109
|
-
}
|
|
110
|
-
return display;
|
|
111
|
-
};
|
|
112
72
|
var extractUrlValue = (key, url) => {
|
|
113
73
|
if (typeof url === "undefined") {
|
|
114
74
|
url = window.location.href;
|
|
@@ -245,7 +205,6 @@ export {
|
|
|
245
205
|
addedTo,
|
|
246
206
|
applyWidthAsPadding,
|
|
247
207
|
capitalizeFirstLetter,
|
|
248
|
-
determinePoolDisplay,
|
|
249
208
|
extractUrlValue,
|
|
250
209
|
inChrome,
|
|
251
210
|
isValidAddress,
|