@w3ux/utils 2.0.7-alpha.1 → 2.0.8
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 +2 -3
- package/base.js +2 -3
- package/index.cjs +4 -6
- package/index.d.cts +1 -0
- package/index.d.ts +1 -0
- package/index.js +4 -6
- package/package.json +2 -2
- package/unit.cjs +3 -4
- package/unit.d.cts +8 -7
- package/unit.d.ts +8 -7
- package/unit.js +3 -4
package/base.cjs
CHANGED
|
@@ -37,7 +37,7 @@ __export(base_exports, {
|
|
|
37
37
|
withTimeout: () => withTimeout
|
|
38
38
|
});
|
|
39
39
|
module.exports = __toCommonJS(base_exports);
|
|
40
|
-
var
|
|
40
|
+
var import_utils = require("dedot/utils");
|
|
41
41
|
var minDecimalPlaces = (val, minDecimals) => {
|
|
42
42
|
try {
|
|
43
43
|
const retainCommas = typeof val === "string" && val.includes(",");
|
|
@@ -140,8 +140,7 @@ var appendOrEmpty = (condition, value) => condition ? ` ${value}` : "";
|
|
|
140
140
|
var appendOr = (condition, value, fallback) => condition ? ` ${value}` : ` ${fallback}`;
|
|
141
141
|
var formatAccountSs58 = (address, ss58Prefix) => {
|
|
142
142
|
try {
|
|
143
|
-
|
|
144
|
-
return codec.dec(codec.enc(address));
|
|
143
|
+
return (0, import_utils.encodeAddress)(address, ss58Prefix);
|
|
145
144
|
} catch (e) {
|
|
146
145
|
return null;
|
|
147
146
|
}
|
package/base.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/base.ts
|
|
2
|
-
import {
|
|
2
|
+
import { encodeAddress } from "dedot/utils";
|
|
3
3
|
var minDecimalPlaces = (val, minDecimals) => {
|
|
4
4
|
try {
|
|
5
5
|
const retainCommas = typeof val === "string" && val.includes(",");
|
|
@@ -102,8 +102,7 @@ var appendOrEmpty = (condition, value) => condition ? ` ${value}` : "";
|
|
|
102
102
|
var appendOr = (condition, value, fallback) => condition ? ` ${value}` : ` ${fallback}`;
|
|
103
103
|
var formatAccountSs58 = (address, ss58Prefix) => {
|
|
104
104
|
try {
|
|
105
|
-
|
|
106
|
-
return codec.dec(codec.enc(address));
|
|
105
|
+
return encodeAddress(address, ss58Prefix);
|
|
107
106
|
} catch (e) {
|
|
108
107
|
return null;
|
|
109
108
|
}
|
package/index.cjs
CHANGED
|
@@ -62,7 +62,7 @@ __export(index_exports, {
|
|
|
62
62
|
module.exports = __toCommonJS(index_exports);
|
|
63
63
|
|
|
64
64
|
// src/base.ts
|
|
65
|
-
var
|
|
65
|
+
var import_utils = require("dedot/utils");
|
|
66
66
|
var minDecimalPlaces = (val, minDecimals) => {
|
|
67
67
|
try {
|
|
68
68
|
const retainCommas = typeof val === "string" && val.includes(",");
|
|
@@ -165,8 +165,7 @@ var appendOrEmpty = (condition, value) => condition ? ` ${value}` : "";
|
|
|
165
165
|
var appendOr = (condition, value, fallback) => condition ? ` ${value}` : ` ${fallback}`;
|
|
166
166
|
var formatAccountSs58 = (address, ss58Prefix) => {
|
|
167
167
|
try {
|
|
168
|
-
|
|
169
|
-
return codec.dec(codec.enc(address));
|
|
168
|
+
return (0, import_utils.encodeAddress)(address, ss58Prefix);
|
|
170
169
|
} catch (e) {
|
|
171
170
|
return null;
|
|
172
171
|
}
|
|
@@ -197,7 +196,7 @@ var u8aConcat = (...u8as) => {
|
|
|
197
196
|
};
|
|
198
197
|
|
|
199
198
|
// src/unit.ts
|
|
200
|
-
var
|
|
199
|
+
var import_utils2 = require("dedot/utils");
|
|
201
200
|
var planckToUnit = (val, units) => {
|
|
202
201
|
try {
|
|
203
202
|
units = Math.max(Math.round(units), 0);
|
|
@@ -255,8 +254,7 @@ var localStorageOrDefault = (key, _default, parse = false) => {
|
|
|
255
254
|
};
|
|
256
255
|
var isValidAddress = (address) => {
|
|
257
256
|
try {
|
|
258
|
-
|
|
259
|
-
codec.dec(codec.enc(address));
|
|
257
|
+
(0, import_utils2.decodeAddress)(address);
|
|
260
258
|
return true;
|
|
261
259
|
} catch (e) {
|
|
262
260
|
return false;
|
package/index.d.cts
CHANGED
|
@@ -2,3 +2,4 @@ export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58
|
|
|
2
2
|
export { u8aConcat } from './convert.cjs';
|
|
3
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 'react';
|
|
5
|
+
import './types.cjs';
|
package/index.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58
|
|
|
2
2
|
export { u8aConcat } from './convert.js';
|
|
3
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 'react';
|
|
5
|
+
import './types.js';
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/base.ts
|
|
2
|
-
import {
|
|
2
|
+
import { encodeAddress } from "dedot/utils";
|
|
3
3
|
var minDecimalPlaces = (val, minDecimals) => {
|
|
4
4
|
try {
|
|
5
5
|
const retainCommas = typeof val === "string" && val.includes(",");
|
|
@@ -102,8 +102,7 @@ var appendOrEmpty = (condition, value) => condition ? ` ${value}` : "";
|
|
|
102
102
|
var appendOr = (condition, value, fallback) => condition ? ` ${value}` : ` ${fallback}`;
|
|
103
103
|
var formatAccountSs58 = (address, ss58Prefix) => {
|
|
104
104
|
try {
|
|
105
|
-
|
|
106
|
-
return codec.dec(codec.enc(address));
|
|
105
|
+
return encodeAddress(address, ss58Prefix);
|
|
107
106
|
} catch (e) {
|
|
108
107
|
return null;
|
|
109
108
|
}
|
|
@@ -134,7 +133,7 @@ var u8aConcat = (...u8as) => {
|
|
|
134
133
|
};
|
|
135
134
|
|
|
136
135
|
// src/unit.ts
|
|
137
|
-
import {
|
|
136
|
+
import { decodeAddress } from "dedot/utils";
|
|
138
137
|
var planckToUnit = (val, units) => {
|
|
139
138
|
try {
|
|
140
139
|
units = Math.max(Math.round(units), 0);
|
|
@@ -192,8 +191,7 @@ var localStorageOrDefault = (key, _default, parse = false) => {
|
|
|
192
191
|
};
|
|
193
192
|
var isValidAddress = (address) => {
|
|
194
193
|
try {
|
|
195
|
-
|
|
196
|
-
codec.dec(codec.enc(address));
|
|
194
|
+
decodeAddress(address);
|
|
197
195
|
return true;
|
|
198
196
|
} catch (e) {
|
|
199
197
|
return false;
|
package/package.json
CHANGED
package/unit.cjs
CHANGED
|
@@ -43,10 +43,10 @@ __export(unit_exports, {
|
|
|
43
43
|
varToUrlHash: () => varToUrlHash
|
|
44
44
|
});
|
|
45
45
|
module.exports = __toCommonJS(unit_exports);
|
|
46
|
-
var
|
|
46
|
+
var import_utils2 = require("dedot/utils");
|
|
47
47
|
|
|
48
48
|
// src/base.ts
|
|
49
|
-
var
|
|
49
|
+
var import_utils = require("dedot/utils");
|
|
50
50
|
var rmCommas = (val) => val.replace(/,/g, "");
|
|
51
51
|
var rmDecimals = (str) => str.split(".")[0];
|
|
52
52
|
|
|
@@ -108,8 +108,7 @@ var localStorageOrDefault = (key, _default, parse = false) => {
|
|
|
108
108
|
};
|
|
109
109
|
var isValidAddress = (address) => {
|
|
110
110
|
try {
|
|
111
|
-
|
|
112
|
-
codec.dec(codec.enc(address));
|
|
111
|
+
(0, import_utils2.decodeAddress)(address);
|
|
113
112
|
return true;
|
|
114
113
|
} catch (e) {
|
|
115
114
|
return false;
|
package/unit.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { RefObject } from 'react';
|
|
1
|
+
import { MutableRefObject, RefObject } from 'react';
|
|
2
|
+
import { AnyObject } from './types.cjs';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Converts an on-chain balance value from planck to a decimal value in token units.
|
|
@@ -43,7 +44,7 @@ declare const snakeToCamel: (str: string) => string;
|
|
|
43
44
|
* @name setStateWithRef
|
|
44
45
|
* @summary Synchronize React state and its reference with the provided value.
|
|
45
46
|
*/
|
|
46
|
-
declare const setStateWithRef: <T>(value: T, setState: (_state: T) => void, ref:
|
|
47
|
+
declare const setStateWithRef: <T>(value: T, setState: (_state: T) => void, ref: MutableRefObject<T>) => void;
|
|
47
48
|
/**
|
|
48
49
|
* @name localStorageOrDefault
|
|
49
50
|
* @summary Retrieve the local stroage value with the key, return defult value if it is not
|
|
@@ -100,19 +101,19 @@ declare const inChrome: () => boolean;
|
|
|
100
101
|
* @summary Given 2 objects and some keys, return items in the fresh object that do not exist in the
|
|
101
102
|
* stale object by matching the given common key values of both objects.
|
|
102
103
|
*/
|
|
103
|
-
declare const addedTo: (fresh:
|
|
104
|
+
declare const addedTo: (fresh: AnyObject[], stale: AnyObject[], keys: string[]) => AnyObject[];
|
|
104
105
|
/**
|
|
105
106
|
* @name removedFrom
|
|
106
107
|
* @summary Given 2 objects and some keys, return items in the stale object that do not exist in the
|
|
107
108
|
* fresh object by matching the given common key values of both objects.
|
|
108
109
|
*/
|
|
109
|
-
declare const removedFrom: (fresh:
|
|
110
|
+
declare const removedFrom: (fresh: AnyObject[], stale: AnyObject[], keys: string[]) => AnyObject[];
|
|
110
111
|
/**
|
|
111
112
|
* @name matchedProperties
|
|
112
113
|
* @summary Given 2 objects and some keys, return items in object 1 that also exist in object 2 by
|
|
113
114
|
* matching the given common key values of both objects.
|
|
114
115
|
*/
|
|
115
|
-
declare const matchedProperties: (objX:
|
|
116
|
+
declare const matchedProperties: (objX: AnyObject[], objY: AnyObject[], keys: string[]) => AnyObject[];
|
|
116
117
|
/**
|
|
117
118
|
* @name isValidHttpUrl
|
|
118
119
|
* @summary Give a string, return whether it is a valid http URL.
|
|
@@ -124,7 +125,7 @@ declare const isValidHttpUrl: (string: string) => boolean;
|
|
|
124
125
|
* @summary Makes a promise cancellable.
|
|
125
126
|
* @param promise - The promise to make cancellable.
|
|
126
127
|
*/
|
|
127
|
-
declare const makeCancelable:
|
|
128
|
+
declare const makeCancelable: (promise: Promise<AnyObject>) => {
|
|
128
129
|
promise: Promise<unknown>;
|
|
129
130
|
cancel: () => void;
|
|
130
131
|
};
|
|
@@ -141,6 +142,6 @@ declare const unimplemented: ({ ...props }: {
|
|
|
141
142
|
* @param target
|
|
142
143
|
* @param ...sources
|
|
143
144
|
*/
|
|
144
|
-
declare const mergeDeep: (target:
|
|
145
|
+
declare const mergeDeep: (target: AnyObject, ...sources: AnyObject[]) => AnyObject;
|
|
145
146
|
|
|
146
147
|
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
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { RefObject } from 'react';
|
|
1
|
+
import { MutableRefObject, RefObject } from 'react';
|
|
2
|
+
import { AnyObject } from './types.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Converts an on-chain balance value from planck to a decimal value in token units.
|
|
@@ -43,7 +44,7 @@ declare const snakeToCamel: (str: string) => string;
|
|
|
43
44
|
* @name setStateWithRef
|
|
44
45
|
* @summary Synchronize React state and its reference with the provided value.
|
|
45
46
|
*/
|
|
46
|
-
declare const setStateWithRef: <T>(value: T, setState: (_state: T) => void, ref:
|
|
47
|
+
declare const setStateWithRef: <T>(value: T, setState: (_state: T) => void, ref: MutableRefObject<T>) => void;
|
|
47
48
|
/**
|
|
48
49
|
* @name localStorageOrDefault
|
|
49
50
|
* @summary Retrieve the local stroage value with the key, return defult value if it is not
|
|
@@ -100,19 +101,19 @@ declare const inChrome: () => boolean;
|
|
|
100
101
|
* @summary Given 2 objects and some keys, return items in the fresh object that do not exist in the
|
|
101
102
|
* stale object by matching the given common key values of both objects.
|
|
102
103
|
*/
|
|
103
|
-
declare const addedTo: (fresh:
|
|
104
|
+
declare const addedTo: (fresh: AnyObject[], stale: AnyObject[], keys: string[]) => AnyObject[];
|
|
104
105
|
/**
|
|
105
106
|
* @name removedFrom
|
|
106
107
|
* @summary Given 2 objects and some keys, return items in the stale object that do not exist in the
|
|
107
108
|
* fresh object by matching the given common key values of both objects.
|
|
108
109
|
*/
|
|
109
|
-
declare const removedFrom: (fresh:
|
|
110
|
+
declare const removedFrom: (fresh: AnyObject[], stale: AnyObject[], keys: string[]) => AnyObject[];
|
|
110
111
|
/**
|
|
111
112
|
* @name matchedProperties
|
|
112
113
|
* @summary Given 2 objects and some keys, return items in object 1 that also exist in object 2 by
|
|
113
114
|
* matching the given common key values of both objects.
|
|
114
115
|
*/
|
|
115
|
-
declare const matchedProperties: (objX:
|
|
116
|
+
declare const matchedProperties: (objX: AnyObject[], objY: AnyObject[], keys: string[]) => AnyObject[];
|
|
116
117
|
/**
|
|
117
118
|
* @name isValidHttpUrl
|
|
118
119
|
* @summary Give a string, return whether it is a valid http URL.
|
|
@@ -124,7 +125,7 @@ declare const isValidHttpUrl: (string: string) => boolean;
|
|
|
124
125
|
* @summary Makes a promise cancellable.
|
|
125
126
|
* @param promise - The promise to make cancellable.
|
|
126
127
|
*/
|
|
127
|
-
declare const makeCancelable:
|
|
128
|
+
declare const makeCancelable: (promise: Promise<AnyObject>) => {
|
|
128
129
|
promise: Promise<unknown>;
|
|
129
130
|
cancel: () => void;
|
|
130
131
|
};
|
|
@@ -141,6 +142,6 @@ declare const unimplemented: ({ ...props }: {
|
|
|
141
142
|
* @param target
|
|
142
143
|
* @param ...sources
|
|
143
144
|
*/
|
|
144
|
-
declare const mergeDeep: (target:
|
|
145
|
+
declare const mergeDeep: (target: AnyObject, ...sources: AnyObject[]) => AnyObject;
|
|
145
146
|
|
|
146
147
|
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,8 +1,8 @@
|
|
|
1
1
|
// src/unit.ts
|
|
2
|
-
import {
|
|
2
|
+
import { decodeAddress } from "dedot/utils";
|
|
3
3
|
|
|
4
4
|
// src/base.ts
|
|
5
|
-
import {
|
|
5
|
+
import { encodeAddress } from "dedot/utils";
|
|
6
6
|
var rmCommas = (val) => val.replace(/,/g, "");
|
|
7
7
|
var rmDecimals = (str) => str.split(".")[0];
|
|
8
8
|
|
|
@@ -64,8 +64,7 @@ var localStorageOrDefault = (key, _default, parse = false) => {
|
|
|
64
64
|
};
|
|
65
65
|
var isValidAddress = (address) => {
|
|
66
66
|
try {
|
|
67
|
-
|
|
68
|
-
codec.dec(codec.enc(address));
|
|
67
|
+
decodeAddress(address);
|
|
69
68
|
return true;
|
|
70
69
|
} catch (e) {
|
|
71
70
|
return false;
|