@w3ux/utils 0.2.0 → 0.4.0-alpha.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/index.cjs ADDED
@@ -0,0 +1,493 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/index.ts
30
+ var src_exports = {};
31
+ __export(src_exports, {
32
+ addedTo: () => addedTo,
33
+ appendOr: () => appendOr,
34
+ appendOrEmpty: () => appendOrEmpty,
35
+ applyWidthAsPadding: () => applyWidthAsPadding,
36
+ camelize: () => camelize,
37
+ capitalizeFirstLetter: () => capitalizeFirstLetter,
38
+ determinePoolDisplay: () => determinePoolDisplay,
39
+ ellipsisFn: () => ellipsisFn,
40
+ evalUnits: () => evalUnits,
41
+ extractUrlValue: () => extractUrlValue,
42
+ formatAccountSs58: () => formatAccountSs58,
43
+ greaterThanZero: () => greaterThanZero,
44
+ inChrome: () => inChrome,
45
+ isNotZero: () => isNotZero,
46
+ isValidAddress: () => isValidAddress,
47
+ isValidHttpUrl: () => isValidHttpUrl,
48
+ localStorageOrDefault: () => localStorageOrDefault,
49
+ makeCancelable: () => makeCancelable,
50
+ matchedProperties: () => matchedProperties,
51
+ mergeDeep: () => mergeDeep,
52
+ minDecimalPlaces: () => minDecimalPlaces,
53
+ pageFromUri: () => pageFromUri,
54
+ planckToUnit: () => planckToUnit,
55
+ remToUnit: () => remToUnit,
56
+ removeHexPrefix: () => removeHexPrefix,
57
+ removeVarFromUrlHash: () => removeVarFromUrlHash,
58
+ removedFrom: () => removedFrom,
59
+ rmCommas: () => rmCommas,
60
+ setStateWithRef: () => setStateWithRef,
61
+ shuffle: () => shuffle,
62
+ snakeToCamel: () => snakeToCamel,
63
+ sortWithNull: () => sortWithNull,
64
+ stringToBigNumber: () => stringToBigNumber,
65
+ transformToBaseUnit: () => transformToBaseUnit,
66
+ unescape: () => unescape,
67
+ unimplemented: () => unimplemented,
68
+ unitToPlanck: () => unitToPlanck,
69
+ varToUrlHash: () => varToUrlHash,
70
+ withTimeout: () => withTimeout
71
+ });
72
+ module.exports = __toCommonJS(src_exports);
73
+
74
+ // src/base.ts
75
+ var import_bignumber = require("bignumber.js");
76
+ var import_keyring = __toESM(require("@polkadot/keyring"), 1);
77
+ var camelize = (str) => {
78
+ const convertToString = (string) => {
79
+ if (string) {
80
+ if (typeof string === "string") {
81
+ return string;
82
+ }
83
+ return String(string);
84
+ }
85
+ return "";
86
+ };
87
+ const toWords = (inp) => convertToString(inp).match(
88
+ /[A-Z\xC0-\xD6\xD8-\xDE]?[a-z\xDF-\xF6\xF8-\xFF]+|[A-Z\xC0-\xD6\xD8-\xDE]+(?![a-z\xDF-\xF6\xF8-\xFF])|\d+/g
89
+ );
90
+ const simpleCamelCase = (inp) => {
91
+ let result = "";
92
+ for (let i = 0; i < inp?.length; i++) {
93
+ const currString = inp[i];
94
+ let tmpStr = currString.toLowerCase();
95
+ if (i != 0) {
96
+ tmpStr = tmpStr.slice(0, 1).toUpperCase() + tmpStr.slice(1, tmpStr.length);
97
+ }
98
+ result += tmpStr;
99
+ }
100
+ return result;
101
+ };
102
+ const w = toWords(str)?.map((a) => a.toLowerCase());
103
+ return simpleCamelCase(w);
104
+ };
105
+ var ellipsisFn = (str, amount = 6, position = "center") => {
106
+ const half = str.length / 2;
107
+ if (amount <= 4) {
108
+ if (position === "center") {
109
+ return str.slice(0, 4) + "..." + str.slice(-4);
110
+ }
111
+ if (position === "end") {
112
+ return str.slice(0, 4) + "...";
113
+ }
114
+ return "..." + str.slice(-4);
115
+ }
116
+ if (position === "center") {
117
+ return amount >= (str.length - 2) / 2 ? str.slice(0, half - 3) + "..." + str.slice(-(half - 3)) : str.slice(0, amount) + "..." + str.slice(-amount);
118
+ }
119
+ if (amount >= str.length) {
120
+ if (position === "end") {
121
+ return str.slice(0, str.length - 3) + "...";
122
+ }
123
+ return "..." + str.slice(-(str.length - 3));
124
+ } else {
125
+ if (position === "end") {
126
+ return str.slice(0, amount) + "...";
127
+ }
128
+ return "..." + str.slice(amount);
129
+ }
130
+ };
131
+ var greaterThanZero = (val) => val.isGreaterThan(0);
132
+ var isNotZero = (val) => !val.isZero();
133
+ var minDecimalPlaces = (val, minDecimals) => {
134
+ const whole = new import_bignumber.BigNumber(rmCommas(val).split(".")[0] || 0);
135
+ const decimals = val.split(".")[1] || "";
136
+ const missingDecimals = new import_bignumber.BigNumber(minDecimals).minus(decimals.length);
137
+ return missingDecimals.isGreaterThan(0) ? `${whole.toFormat(0)}.${decimals.toString()}${"0".repeat(
138
+ missingDecimals.toNumber()
139
+ )}` : val;
140
+ };
141
+ var pageFromUri = (pathname, fallback) => {
142
+ const lastUriItem = pathname.substring(pathname.lastIndexOf("/") + 1);
143
+ const page = lastUriItem.trim() === "" ? fallback : lastUriItem;
144
+ return page.trim();
145
+ };
146
+ var rmCommas = (val) => val.replace(/,/g, "");
147
+ var shuffle = (array) => {
148
+ let currentIndex = array.length;
149
+ let randomIndex;
150
+ while (currentIndex !== 0) {
151
+ randomIndex = Math.floor(Math.random() * currentIndex);
152
+ currentIndex--;
153
+ [array[currentIndex], array[randomIndex]] = [
154
+ array[randomIndex],
155
+ array[currentIndex]
156
+ ];
157
+ }
158
+ return array;
159
+ };
160
+ var withTimeout = (ms, promise, options) => {
161
+ const timeout = new Promise(
162
+ (resolve) => setTimeout(async () => {
163
+ if (typeof options?.onTimeout === "function") {
164
+ options.onTimeout();
165
+ }
166
+ resolve(void 0);
167
+ }, ms)
168
+ );
169
+ return Promise.race([promise, timeout]);
170
+ };
171
+ var appendOrEmpty = (condition, value) => condition ? ` ${value}` : "";
172
+ var appendOr = (condition, value, fallback) => condition ? ` ${value}` : ` ${fallback}`;
173
+ var formatAccountSs58 = (address, ss58) => {
174
+ try {
175
+ const keyring = new import_keyring.default();
176
+ keyring.setSS58Format(ss58);
177
+ const formatted = keyring.addFromAddress(address).address;
178
+ if (formatted !== address) {
179
+ return formatted;
180
+ }
181
+ return null;
182
+ } catch (e) {
183
+ return null;
184
+ }
185
+ };
186
+ var removeHexPrefix = (str) => str.replace(/^0x/, "");
187
+
188
+ // src/unit.ts
189
+ var import_keyring2 = require("@polkadot/keyring");
190
+ var import_util = require("@polkadot/util");
191
+ var import_bignumber2 = require("bignumber.js");
192
+ var remToUnit = (rem) => Number(rem.slice(0, rem.length - 3)) * parseFloat(getComputedStyle(document.documentElement).fontSize);
193
+ var planckToUnit = (val, units) => new import_bignumber2.BigNumber(
194
+ val.dividedBy(new import_bignumber2.BigNumber(10).exponentiatedBy(units)).toFixed(units)
195
+ );
196
+ var unitToPlanck = (val, units) => {
197
+ const init = new import_bignumber2.BigNumber(!val.length || !val ? "0" : val);
198
+ return (!init.isNaN() ? init : new import_bignumber2.BigNumber(0)).multipliedBy(new import_bignumber2.BigNumber(10).exponentiatedBy(units)).integerValue();
199
+ };
200
+ var capitalizeFirstLetter = (string) => string.charAt(0).toUpperCase() + string.slice(1);
201
+ var snakeToCamel = (str) => str.toLowerCase().replace(
202
+ /([-_][a-z])/g,
203
+ (group) => group.toUpperCase().replace("-", "").replace("_", "")
204
+ );
205
+ var setStateWithRef = (value, setState, ref) => {
206
+ setState(value);
207
+ ref.current = value;
208
+ };
209
+ var localStorageOrDefault = (key, _default, parse = false) => {
210
+ const val = localStorage.getItem(key);
211
+ if (val === null) {
212
+ return _default;
213
+ }
214
+ if (parse) {
215
+ return JSON.parse(val);
216
+ }
217
+ return val;
218
+ };
219
+ var isValidAddress = (address) => {
220
+ try {
221
+ (0, import_keyring2.encodeAddress)((0, import_util.isHex)(address) ? (0, import_util.hexToU8a)(address) : (0, import_keyring2.decodeAddress)(address));
222
+ return true;
223
+ } catch (e) {
224
+ return false;
225
+ }
226
+ };
227
+ var determinePoolDisplay = (address, batchItem) => {
228
+ const defaultDisplay = ellipsisFn(address, 6);
229
+ let display = batchItem ?? defaultDisplay;
230
+ const displayAsBytes = (0, import_util.u8aToString)((0, import_util.u8aUnwrapBytes)(display));
231
+ if (displayAsBytes !== "") {
232
+ display = displayAsBytes;
233
+ }
234
+ if (display === "") {
235
+ display = defaultDisplay;
236
+ }
237
+ return display;
238
+ };
239
+ var extractUrlValue = (key, url) => {
240
+ if (typeof url === "undefined") {
241
+ url = window.location.href;
242
+ }
243
+ const match = url.match(`[?&]${key}=([^&]+)`);
244
+ return match ? match[1] : null;
245
+ };
246
+ var varToUrlHash = (key, val, addIfMissing) => {
247
+ const hash = window.location.hash;
248
+ const [page, params] = hash.split("?");
249
+ const searchParams = new URLSearchParams(params);
250
+ if (searchParams.get(key) === null && !addIfMissing) {
251
+ return;
252
+ }
253
+ searchParams.set(key, val);
254
+ window.location.hash = `${page}?${searchParams.toString()}`;
255
+ };
256
+ var removeVarFromUrlHash = (key) => {
257
+ const hash = window.location.hash;
258
+ const [page, params] = hash.split("?");
259
+ const searchParams = new URLSearchParams(params);
260
+ if (searchParams.get(key) === null) {
261
+ return;
262
+ }
263
+ searchParams.delete(key);
264
+ const paramsAsStr = searchParams.toString();
265
+ window.location.hash = `${page}${paramsAsStr ? `?${paramsAsStr}` : ``}`;
266
+ };
267
+ var sortWithNull = (ascending) => (a, b) => {
268
+ if (a === b) {
269
+ return 0;
270
+ }
271
+ if (a === null) {
272
+ return 1;
273
+ }
274
+ if (b === null) {
275
+ return -1;
276
+ }
277
+ if (ascending) {
278
+ return a < b ? -1 : 1;
279
+ }
280
+ return a < b ? 1 : -1;
281
+ };
282
+ var applyWidthAsPadding = (subjectRef, containerRef) => {
283
+ if (containerRef.current && subjectRef.current) {
284
+ containerRef.current.style.paddingRight = `${subjectRef.current.offsetWidth + remToUnit("1rem")}px`;
285
+ }
286
+ };
287
+ var unescape = (val) => val.replace(/\\"/g, '"');
288
+ var inChrome = () => {
289
+ const isChromium = window?.chrome || null;
290
+ const winNav = window?.navigator || null;
291
+ const isOpera = typeof window?.opr !== "undefined";
292
+ const isIEedge = winNav?.userAgent.indexOf("Edg") > -1 || false;
293
+ const isIOSChrome = winNav?.userAgent.match("CriOS") || false;
294
+ if (isIOSChrome) {
295
+ return true;
296
+ }
297
+ if (isChromium !== null && typeof isChromium !== "undefined" && isOpera === false && isIEedge === false) {
298
+ return true;
299
+ }
300
+ return false;
301
+ };
302
+ var addedTo = (fresh, stale, keys) => typeof fresh !== "object" || typeof stale !== "object" || !keys.length ? [] : fresh.filter(
303
+ (freshItem) => !stale.find(
304
+ (staleItem) => keys.every(
305
+ (key) => !(key in staleItem) || !(key in freshItem) ? false : staleItem[key] === freshItem[key]
306
+ )
307
+ )
308
+ );
309
+ var removedFrom = (fresh, stale, keys) => typeof fresh !== "object" || typeof stale !== "object" || !keys.length ? [] : stale.filter(
310
+ (staleItem) => !fresh.find(
311
+ (freshItem) => keys.every(
312
+ (key) => !(key in staleItem) || !(key in freshItem) ? false : freshItem[key] === staleItem[key]
313
+ )
314
+ )
315
+ );
316
+ var matchedProperties = (objX, objY, keys) => typeof objX !== "object" || typeof objY !== "object" || !keys.length ? [] : objY.filter(
317
+ (x) => objX.find(
318
+ (y) => keys.every(
319
+ (key) => !(key in x) || !(key in y) ? false : y[key] === x[key]
320
+ )
321
+ )
322
+ );
323
+ var isValidHttpUrl = (string) => {
324
+ let url;
325
+ try {
326
+ url = new URL(string);
327
+ } catch (_) {
328
+ return false;
329
+ }
330
+ return url.protocol === "http:" || url.protocol === "https:";
331
+ };
332
+ var makeCancelable = (promise) => {
333
+ let hasCanceled = false;
334
+ const wrappedPromise = new Promise((resolve, reject) => {
335
+ promise.then(
336
+ (val) => hasCanceled ? reject(Error("Cancelled")) : resolve(val)
337
+ );
338
+ promise.catch(
339
+ (error) => hasCanceled ? reject(Error("Cancelled")) : reject(error)
340
+ );
341
+ });
342
+ return {
343
+ promise: wrappedPromise,
344
+ cancel: () => {
345
+ hasCanceled = true;
346
+ }
347
+ };
348
+ };
349
+ var getSiValue = (si2) => new import_bignumber2.BigNumber(10).pow(new import_bignumber2.BigNumber(si2));
350
+ var si = [
351
+ { value: getSiValue(24), symbol: "y", isMil: true },
352
+ { value: getSiValue(21), symbol: "z", isMil: true },
353
+ { value: getSiValue(18), symbol: "a", isMil: true },
354
+ { value: getSiValue(15), symbol: "f", isMil: true },
355
+ { value: getSiValue(12), symbol: "p", isMil: true },
356
+ { value: getSiValue(9), symbol: "n", isMil: true },
357
+ { value: getSiValue(6), symbol: "\u03BC", isMil: true },
358
+ { value: getSiValue(3), symbol: "m", isMil: true },
359
+ { value: new import_bignumber2.BigNumber(1), symbol: "" },
360
+ { value: getSiValue(3), symbol: "k" },
361
+ { value: getSiValue(6), symbol: "M" },
362
+ { value: getSiValue(9), symbol: "G" },
363
+ { value: getSiValue(12), symbol: "T" },
364
+ { value: getSiValue(15), symbol: "P" },
365
+ { value: getSiValue(18), symbol: "E" },
366
+ { value: getSiValue(21), symbol: "Y" },
367
+ { value: getSiValue(24), symbol: "Z" }
368
+ ];
369
+ var allowedSymbols = si.map((s) => s.symbol).join(", ").replace(", ,", ",");
370
+ var floats = new RegExp("^[+]?[0-9]*[.,]{1}[0-9]*$");
371
+ var ints = new RegExp("^[+]?[0-9]+$");
372
+ var alphaFloats = new RegExp(
373
+ "^[+]?[0-9]*[.,]{1}[0-9]*[" + allowedSymbols + "]{1}$"
374
+ );
375
+ var alphaInts = new RegExp("^[+]?[0-9]*[" + allowedSymbols + "]{1}$");
376
+ var evalUnits = (input, chainDecimals) => {
377
+ input = input && input.replace("+", "");
378
+ if (!floats.test(input) && !ints.test(input) && !alphaInts.test(input) && !alphaFloats.test(input)) {
379
+ return [null, "Input is not correct. Use numbers, floats or expression (e.g. 1k, 1.3m)" /* GIBBERISH */];
380
+ }
381
+ const symbol = input.replace(/[0-9.,]/g, "");
382
+ const siVal = si.find((s) => s.symbol === symbol);
383
+ const numberStr = input.replace(symbol, "").replace(",", ".");
384
+ let numeric = new import_bignumber2.BigNumber(0);
385
+ if (!siVal) {
386
+ return [null, "Provided symbol is not correct" /* SYMBOL_ERROR */];
387
+ }
388
+ const decimalsBn = new import_bignumber2.BigNumber(10).pow(new import_bignumber2.BigNumber(chainDecimals));
389
+ const containDecimal = numberStr.includes(".");
390
+ const [decPart, fracPart] = numberStr.split(".");
391
+ const fracDecimals = fracPart?.length || 0;
392
+ const fracExp = new import_bignumber2.BigNumber(10).pow(new import_bignumber2.BigNumber(fracDecimals));
393
+ numeric = containDecimal ? new import_bignumber2.BigNumber(
394
+ new import_bignumber2.BigNumber(decPart).multipliedBy(fracExp).plus(new import_bignumber2.BigNumber(fracPart))
395
+ ) : new import_bignumber2.BigNumber(new import_bignumber2.BigNumber(numberStr));
396
+ numeric = numeric.multipliedBy(decimalsBn);
397
+ if (containDecimal) {
398
+ numeric = siVal.isMil ? numeric.dividedBy(siVal.value).dividedBy(fracExp) : numeric.multipliedBy(siVal.value).dividedBy(fracExp);
399
+ } else {
400
+ numeric = siVal.isMil ? numeric.dividedBy(siVal.value) : numeric.multipliedBy(siVal.value);
401
+ }
402
+ if (numeric.eq(new import_bignumber2.BigNumber(0))) {
403
+ return [null, "You cannot send 0 funds" /* ZERO */];
404
+ }
405
+ return [numeric, "" /* SUCCESS */];
406
+ };
407
+ var transformToBaseUnit = (estFee, chainDecimals) => {
408
+ const t = estFee.length - chainDecimals;
409
+ let s = "";
410
+ if (t < 0) {
411
+ for (let i = 0; i < Math.abs(t) - 1; i++) {
412
+ s += "0";
413
+ }
414
+ s = s + estFee;
415
+ for (let i = 0; i < s.length; i++) {
416
+ if (s.slice(s.length - 1) !== "0") {
417
+ break;
418
+ }
419
+ s = s.substring(0, s.length - 1);
420
+ }
421
+ s = "0." + s;
422
+ } else {
423
+ s = (parseInt(estFee) / 10 ** chainDecimals).toString();
424
+ }
425
+ return parseFloat(s) !== 0 ? s : "0";
426
+ };
427
+ var unimplemented = ({ ...props }) => {
428
+ };
429
+ var mergeDeep = (target, ...sources) => {
430
+ if (!sources.length) {
431
+ return target;
432
+ }
433
+ const isObject = (item) => item && typeof item === "object" && !Array.isArray(item);
434
+ const source = sources.shift();
435
+ if (isObject(target) && isObject(source)) {
436
+ for (const key in source) {
437
+ if (isObject(source[key])) {
438
+ if (!target[key]) {
439
+ Object.assign(target, { [key]: {} });
440
+ }
441
+ mergeDeep(target[key], source[key]);
442
+ } else {
443
+ Object.assign(target, { [key]: source[key] });
444
+ }
445
+ }
446
+ }
447
+ return mergeDeep(target, ...sources);
448
+ };
449
+ var stringToBigNumber = (value) => new import_bignumber2.BigNumber(rmCommas(value));
450
+ // Annotate the CommonJS export names for ESM import in node:
451
+ 0 && (module.exports = {
452
+ addedTo,
453
+ appendOr,
454
+ appendOrEmpty,
455
+ applyWidthAsPadding,
456
+ camelize,
457
+ capitalizeFirstLetter,
458
+ determinePoolDisplay,
459
+ ellipsisFn,
460
+ evalUnits,
461
+ extractUrlValue,
462
+ formatAccountSs58,
463
+ greaterThanZero,
464
+ inChrome,
465
+ isNotZero,
466
+ isValidAddress,
467
+ isValidHttpUrl,
468
+ localStorageOrDefault,
469
+ makeCancelable,
470
+ matchedProperties,
471
+ mergeDeep,
472
+ minDecimalPlaces,
473
+ pageFromUri,
474
+ planckToUnit,
475
+ remToUnit,
476
+ removeHexPrefix,
477
+ removeVarFromUrlHash,
478
+ removedFrom,
479
+ rmCommas,
480
+ setStateWithRef,
481
+ shuffle,
482
+ snakeToCamel,
483
+ sortWithNull,
484
+ stringToBigNumber,
485
+ transformToBaseUnit,
486
+ unescape,
487
+ unimplemented,
488
+ unitToPlanck,
489
+ varToUrlHash,
490
+ withTimeout
491
+ });
492
+ /* @license Copyright 2024 w3ux authors & contributors
493
+ SPDX-License-Identifier: GPL-3.0-only */
package/index.d.cts ADDED
@@ -0,0 +1,6 @@
1
+ export { appendOr, appendOrEmpty, camelize, ellipsisFn, formatAccountSs58, greaterThanZero, isNotZero, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout } from './base.cjs';
2
+ export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, determinePoolDisplay, evalUnits, extractUrlValue, inChrome, isValidAddress, isValidHttpUrl, localStorageOrDefault, makeCancelable, matchedProperties, mergeDeep, planckToUnit, remToUnit, removeVarFromUrlHash, removedFrom, setStateWithRef, snakeToCamel, sortWithNull, stringToBigNumber, transformToBaseUnit, unescape, unimplemented, unitToPlanck, varToUrlHash } from './unit.cjs';
3
+ import 'bignumber.js';
4
+ import '@w3ux/types';
5
+ import 'react';
6
+ import './types.cjs';
package/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { appendOr, appendOrEmpty, camelize, ellipsisFn, formatAccountSs58, greaterThanZero, isNotZero, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout } from './base.js';
2
2
  export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, determinePoolDisplay, evalUnits, extractUrlValue, inChrome, isValidAddress, isValidHttpUrl, localStorageOrDefault, makeCancelable, matchedProperties, mergeDeep, planckToUnit, remToUnit, removeVarFromUrlHash, removedFrom, setStateWithRef, snakeToCamel, sortWithNull, stringToBigNumber, transformToBaseUnit, unescape, unimplemented, unitToPlanck, varToUrlHash } from './unit.js';
3
3
  import 'bignumber.js';
4
- import './types.js';
4
+ import '@w3ux/types';
5
5
  import 'react';
6
+ import './types.js';
package/package.json CHANGED
@@ -1,11 +1,18 @@
1
1
  {
2
2
  "name": "@w3ux/utils",
3
- "version": "0.2.0",
3
+ "version": "0.4.0-alpha.0",
4
4
  "license": "GPL-3.0-only",
5
- "type": "module",
6
5
  "dependencies": {
7
6
  "@polkadot/keyring": "^12.6.2",
8
7
  "@polkadot/util": "^12.6.2",
9
8
  "bignumber.js": "^9.1.1"
9
+ },
10
+ "main": "index.cjs",
11
+ "module": "index.js",
12
+ "exports": {
13
+ ".": {
14
+ "import": "./index.js",
15
+ "require": "./index.cjs"
16
+ }
10
17
  }
11
18
  }
package/types.cjs ADDED
@@ -0,0 +1,38 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/types.ts
20
+ var types_exports = {};
21
+ __export(types_exports, {
22
+ EvalMessages: () => EvalMessages
23
+ });
24
+ module.exports = __toCommonJS(types_exports);
25
+ var EvalMessages = /* @__PURE__ */ ((EvalMessages2) => {
26
+ EvalMessages2["GIBBERISH"] = "Input is not correct. Use numbers, floats or expression (e.g. 1k, 1.3m)";
27
+ EvalMessages2["ZERO"] = "You cannot send 0 funds";
28
+ EvalMessages2["SUCCESS"] = "";
29
+ EvalMessages2["SYMBOL_ERROR"] = "Provided symbol is not correct";
30
+ EvalMessages2["GENERAL_ERROR"] = "Check your input. Something went wrong";
31
+ return EvalMessages2;
32
+ })(EvalMessages || {});
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ EvalMessages
36
+ });
37
+ /* @license Copyright 2024 w3ux authors & contributors
38
+ SPDX-License-Identifier: GPL-3.0-only */
package/types.d.cts ADDED
@@ -0,0 +1,10 @@
1
+ type AnyObject = any;
2
+ declare enum EvalMessages {
3
+ GIBBERISH = "Input is not correct. Use numbers, floats or expression (e.g. 1k, 1.3m)",
4
+ ZERO = "You cannot send 0 funds",
5
+ SUCCESS = "",
6
+ SYMBOL_ERROR = "Provided symbol is not correct",
7
+ GENERAL_ERROR = "Check your input. Something went wrong"
8
+ }
9
+
10
+ export { type AnyObject, EvalMessages };
package/types.d.ts CHANGED
@@ -1,6 +1,4 @@
1
- type AnyJson = any;
2
1
  type AnyObject = any;
3
- type AnyFunction = any;
4
2
  declare enum EvalMessages {
5
3
  GIBBERISH = "Input is not correct. Use numbers, floats or expression (e.g. 1k, 1.3m)",
6
4
  ZERO = "You cannot send 0 funds",
@@ -9,4 +7,4 @@ declare enum EvalMessages {
9
7
  GENERAL_ERROR = "Check your input. Something went wrong"
10
8
  }
11
9
 
12
- export { type AnyFunction, type AnyJson, type AnyObject, EvalMessages };
10
+ export { type AnyObject, EvalMessages };