@chainflip/utils 0.4.0 → 0.4.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.
@@ -0,0 +1,17 @@
1
+ import { UTCDate } from '@date-fns/utc';
2
+ import { Interval } from 'date-fns';
3
+
4
+ declare const toISODateString: (date: Date) => string;
5
+ declare const fromUnixTime: (time: string | number) => Date;
6
+ declare const formatTimestamp: (timestamp: string, locale?: string | undefined, timeZone?: undefined | "UTC") => string;
7
+ declare const formatTimestampShort: (timestamp: string, locale?: string | undefined, timeZone?: undefined | "UTC") => string;
8
+ declare const differenceInTimeAgo: (time: string, ago?: boolean, endTime?: string) => string;
9
+ declare const intervalToDurationWords: (interval: Interval) => string;
10
+ declare const toStartOfUtcDayString: (date: Date) => string;
11
+ declare const toEndOfUtcDayString: (date: Date) => string;
12
+ declare const eachUtcDayOfInterval: (interval: {
13
+ start: Date;
14
+ end: Date;
15
+ }) => UTCDate[];
16
+
17
+ export { differenceInTimeAgo, eachUtcDayOfInterval, formatTimestamp, formatTimestampShort, fromUnixTime, intervalToDurationWords, toEndOfUtcDayString, toISODateString, toStartOfUtcDayString };
package/dist/date.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { UTCDate } from '@date-fns/utc';
2
+ import { Interval } from 'date-fns';
3
+
4
+ declare const toISODateString: (date: Date) => string;
5
+ declare const fromUnixTime: (time: string | number) => Date;
6
+ declare const formatTimestamp: (timestamp: string, locale?: string | undefined, timeZone?: undefined | "UTC") => string;
7
+ declare const formatTimestampShort: (timestamp: string, locale?: string | undefined, timeZone?: undefined | "UTC") => string;
8
+ declare const differenceInTimeAgo: (time: string, ago?: boolean, endTime?: string) => string;
9
+ declare const intervalToDurationWords: (interval: Interval) => string;
10
+ declare const toStartOfUtcDayString: (date: Date) => string;
11
+ declare const toEndOfUtcDayString: (date: Date) => string;
12
+ declare const eachUtcDayOfInterval: (interval: {
13
+ start: Date;
14
+ end: Date;
15
+ }) => UTCDate[];
16
+
17
+ export { differenceInTimeAgo, eachUtcDayOfInterval, formatTimestamp, formatTimestampShort, fromUnixTime, intervalToDurationWords, toEndOfUtcDayString, toISODateString, toStartOfUtcDayString };
package/dist/date.js ADDED
@@ -0,0 +1,89 @@
1
+ import {
2
+ isNullish
3
+ } from "./chunk-HBIFE4XN.js";
4
+
5
+ // src/date.ts
6
+ import { utc } from "@date-fns/utc";
7
+ import {
8
+ differenceInDays,
9
+ differenceInHours,
10
+ differenceInMinutes,
11
+ differenceInSeconds,
12
+ intervalToDuration,
13
+ eachDayOfInterval,
14
+ endOfDay,
15
+ startOfDay
16
+ } from "date-fns";
17
+ var pluralize = (word, numb) => numb !== 1 ? `${word}s` : word;
18
+ var pad = (number) => String(number).padStart(2, "0");
19
+ var toISODateString = (date) => date.toISOString().slice(0, 10);
20
+ var fromUnixTime = (time) => {
21
+ const date = new Date(Number(time) * 1e3);
22
+ if (Number.isNaN(date.valueOf())) {
23
+ throw new Error("date is invalid");
24
+ }
25
+ return date;
26
+ };
27
+ var formatTimestamp = (timestamp, locale = void 0, timeZone = void 0) => new Date(timestamp).toLocaleString(locale, {
28
+ timeZone,
29
+ weekday: "short",
30
+ month: "short",
31
+ day: "numeric",
32
+ year: "numeric",
33
+ timeZoneName: "short",
34
+ hour: "numeric",
35
+ minute: "numeric",
36
+ second: "numeric"
37
+ });
38
+ var formatTimestampShort = (timestamp, locale = void 0, timeZone = void 0) => new Date(timestamp).toLocaleString(locale, {
39
+ timeZone,
40
+ month: "numeric",
41
+ day: "numeric",
42
+ year: "numeric",
43
+ hour: "numeric",
44
+ minute: "numeric",
45
+ second: "numeric"
46
+ });
47
+ var differenceInTimeAgo = (time, ago = true, endTime = (/* @__PURE__ */ new Date()).toISOString()) => {
48
+ const end = new Date(endTime);
49
+ const timeNumber = Date.parse(time);
50
+ const seconds = differenceInSeconds(end, timeNumber);
51
+ if (seconds < 60) return `${seconds} sec${ago ? " ago" : ""}`;
52
+ const minutes = differenceInMinutes(end, timeNumber);
53
+ if (minutes < 60) return `${minutes} min${ago ? " ago" : ""}`;
54
+ const hours = differenceInHours(end, timeNumber);
55
+ if (hours < 48) return `${hours} ${pluralize("hour", hours)}${ago ? " ago" : ""}`;
56
+ const days = differenceInDays(end, timeNumber);
57
+ return `${days} days${ago ? " ago" : ""}`;
58
+ };
59
+ var intervalToDurationWords = (interval) => {
60
+ if (isNullish(interval.start) || isNullish(interval.end)) return "??";
61
+ if (interval.end === 0) return "??";
62
+ const duration = intervalToDuration(interval);
63
+ if (duration.months) return ">1 month";
64
+ if (duration.days) {
65
+ return `${pad(duration.days)}${duration.days === 1 ? "day" : "days"} ${pad(
66
+ duration.hours ?? 0
67
+ )}h ${pad(duration.minutes ?? 0)}min ${pad(duration.seconds ?? 0)}s`;
68
+ }
69
+ if (duration.hours) {
70
+ return `${pad(duration.hours)}h ${pad(duration.minutes)}min ${pad(duration.seconds)}s`;
71
+ }
72
+ if (duration.minutes) return `${pad(duration.minutes)}min ${pad(duration.seconds)}s`;
73
+ if (duration.seconds) return `${pad(duration.seconds)}s`;
74
+ return "A few seconds";
75
+ };
76
+ var toStartOfUtcDayString = (date) => startOfDay(date, { in: utc }).toISOString();
77
+ var toEndOfUtcDayString = (date) => endOfDay(date, { in: utc }).toISOString();
78
+ var eachUtcDayOfInterval = (interval) => eachDayOfInterval(interval, { in: utc });
79
+ export {
80
+ differenceInTimeAgo,
81
+ eachUtcDayOfInterval,
82
+ formatTimestamp,
83
+ formatTimestampShort,
84
+ fromUnixTime,
85
+ intervalToDurationWords,
86
+ toEndOfUtcDayString,
87
+ toISODateString,
88
+ toStartOfUtcDayString
89
+ };
package/dist/guard.cjs CHANGED
@@ -22,12 +22,15 @@ var guard_exports = {};
22
22
  __export(guard_exports, {
23
23
  isBigInt: () => isBigInt,
24
24
  isBoolean: () => isBoolean,
25
+ isFullfilled: () => isFullfilled,
25
26
  isNotNullish: () => isNotNullish,
26
27
  isNullish: () => isNullish,
27
28
  isNumber: () => isNumber,
28
29
  isObject: () => isObject,
30
+ isRejected: () => isRejected,
29
31
  isString: () => isString,
30
32
  isSymbol: () => isSymbol,
33
+ isTruthy: () => isTruthy,
31
34
  isUndefined: () => isUndefined
32
35
  });
33
36
  module.exports = __toCommonJS(guard_exports);
@@ -41,15 +44,21 @@ var isObject = createIsGuard("object");
41
44
  var isUndefined = createIsGuard("undefined");
42
45
  var isNotNullish = (value) => value != null;
43
46
  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";
44
50
  // Annotate the CommonJS export names for ESM import in node:
45
51
  0 && (module.exports = {
46
52
  isBigInt,
47
53
  isBoolean,
54
+ isFullfilled,
48
55
  isNotNullish,
49
56
  isNullish,
50
57
  isNumber,
51
58
  isObject,
59
+ isRejected,
52
60
  isString,
53
61
  isSymbol,
62
+ isTruthy,
54
63
  isUndefined
55
64
  });
package/dist/guard.d.cts CHANGED
@@ -7,14 +7,17 @@ type TypeMap = {
7
7
  object: object;
8
8
  undefined: undefined;
9
9
  };
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;
10
+ declare const isString: (value: unknown) => value is TypeMap["string"];
11
+ declare const isNumber: (value: unknown) => value is TypeMap["number"];
12
+ declare const isBigInt: (value: unknown) => value is TypeMap["bigint"];
13
+ declare const isBoolean: (value: unknown) => value is TypeMap["boolean"];
14
+ declare const isSymbol: (value: unknown) => value is TypeMap["symbol"];
15
+ declare const isObject: (value: unknown) => value is TypeMap["object"];
16
+ declare const isUndefined: (value: unknown) => value is TypeMap["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;
19
22
 
20
- export { type TypeMap, isBigInt, isBoolean, isNotNullish, isNullish, isNumber, isObject, isString, isSymbol, isUndefined };
23
+ export { type TypeMap, isBigInt, isBoolean, isFullfilled, isNotNullish, isNullish, isNumber, isObject, isRejected, isString, isSymbol, isTruthy, isUndefined };
package/dist/guard.d.ts CHANGED
@@ -7,14 +7,17 @@ type TypeMap = {
7
7
  object: object;
8
8
  undefined: undefined;
9
9
  };
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;
10
+ declare const isString: (value: unknown) => value is TypeMap["string"];
11
+ declare const isNumber: (value: unknown) => value is TypeMap["number"];
12
+ declare const isBigInt: (value: unknown) => value is TypeMap["bigint"];
13
+ declare const isBoolean: (value: unknown) => value is TypeMap["boolean"];
14
+ declare const isSymbol: (value: unknown) => value is TypeMap["symbol"];
15
+ declare const isObject: (value: unknown) => value is TypeMap["object"];
16
+ declare const isUndefined: (value: unknown) => value is TypeMap["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;
19
22
 
20
- export { type TypeMap, isBigInt, isBoolean, isNotNullish, isNullish, isNumber, isObject, isString, isSymbol, isUndefined };
23
+ export { type TypeMap, isBigInt, isBoolean, isFullfilled, isNotNullish, isNullish, isNumber, isObject, isRejected, isString, isSymbol, isTruthy, isUndefined };
package/dist/guard.js CHANGED
@@ -1,22 +1,28 @@
1
1
  import {
2
2
  isBigInt,
3
3
  isBoolean,
4
+ isFullfilled,
4
5
  isNotNullish,
5
6
  isNullish,
6
7
  isNumber,
7
8
  isObject,
9
+ isRejected,
8
10
  isString,
9
11
  isSymbol,
12
+ isTruthy,
10
13
  isUndefined
11
- } from "./chunk-CZNX6EUV.js";
14
+ } from "./chunk-HBIFE4XN.js";
12
15
  export {
13
16
  isBigInt,
14
17
  isBoolean,
18
+ isFullfilled,
15
19
  isNotNullish,
16
20
  isNullish,
17
21
  isNumber,
18
22
  isObject,
23
+ isRejected,
19
24
  isString,
20
25
  isSymbol,
26
+ isTruthy,
21
27
  isUndefined
22
28
  };
package/dist/number.cjs CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,16 +17,55 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
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
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/number.ts
21
31
  var number_exports = {};
22
32
  __export(number_exports, {
33
+ formatUsdValue: () => formatUsdValue,
23
34
  hexEncodeNumber: () => hexEncodeNumber
24
35
  });
25
36
  module.exports = __toCommonJS(number_exports);
37
+ var import_assert = __toESM(require("assert"), 1);
38
+ var import_bignumber = __toESM(require("bignumber.js"), 1);
26
39
  var hexEncodeNumber = (num) => `0x${num.toString(16)}`;
40
+ function formatUsdValue(value, precise = true) {
41
+ if (value == null) return value;
42
+ let usdAmount = new import_bignumber.default(value);
43
+ (0, import_assert.default)(usdAmount.gte(0), "negative amounts not supported");
44
+ if (!usdAmount.eq(0) && usdAmount.lt(0.01)) return `<$0.01`;
45
+ let suffix = "";
46
+ let decimals = 2;
47
+ if (!precise) {
48
+ if (usdAmount.gte(1e12)) {
49
+ usdAmount = usdAmount.shiftedBy(-12);
50
+ suffix = "T";
51
+ } else if (usdAmount.gte(1e9)) {
52
+ usdAmount = usdAmount.shiftedBy(-9);
53
+ suffix = "B";
54
+ } else if (usdAmount.gte(1e6)) {
55
+ usdAmount = usdAmount.shiftedBy(-6);
56
+ suffix = "M";
57
+ }
58
+ if (suffix === "" && usdAmount.gte(1e4)) {
59
+ decimals = 0;
60
+ } else if (suffix !== "") {
61
+ decimals = void 0;
62
+ }
63
+ }
64
+ usdAmount = usdAmount.decimalPlaces(2);
65
+ return `$${usdAmount.toFormat(decimals)}${suffix}`;
66
+ }
27
67
  // Annotate the CommonJS export names for ESM import in node:
28
68
  0 && (module.exports = {
69
+ formatUsdValue,
29
70
  hexEncodeNumber
30
71
  });
package/dist/number.d.cts CHANGED
@@ -1,5 +1,10 @@
1
+ import BigNumber from 'bignumber.js';
1
2
  import { HexString } from './types.cjs';
2
3
 
3
4
  declare const hexEncodeNumber: (num: number | bigint) => HexString;
5
+ declare function formatUsdValue(value: BigNumber.Value, precise?: boolean): string;
6
+ declare function formatUsdValue(value: null, precise?: boolean): null;
7
+ declare function formatUsdValue(value: undefined, precise?: boolean): undefined;
8
+ declare function formatUsdValue(value: BigNumber.Value | null | undefined, precise?: boolean): string | null | undefined;
4
9
 
5
- export { hexEncodeNumber };
10
+ export { formatUsdValue, hexEncodeNumber };
package/dist/number.d.ts CHANGED
@@ -1,5 +1,10 @@
1
+ import BigNumber from 'bignumber.js';
1
2
  import { HexString } from './types.js';
2
3
 
3
4
  declare const hexEncodeNumber: (num: number | bigint) => HexString;
5
+ declare function formatUsdValue(value: BigNumber.Value, precise?: boolean): string;
6
+ declare function formatUsdValue(value: null, precise?: boolean): null;
7
+ declare function formatUsdValue(value: undefined, precise?: boolean): undefined;
8
+ declare function formatUsdValue(value: BigNumber.Value | null | undefined, precise?: boolean): string | null | undefined;
4
9
 
5
- export { hexEncodeNumber };
10
+ export { formatUsdValue, hexEncodeNumber };
package/dist/number.js CHANGED
@@ -1,5 +1,35 @@
1
1
  // src/number.ts
2
+ import assert from "assert";
3
+ import BigNumber from "bignumber.js";
2
4
  var hexEncodeNumber = (num) => `0x${num.toString(16)}`;
5
+ function formatUsdValue(value, precise = true) {
6
+ if (value == null) return value;
7
+ let usdAmount = new BigNumber(value);
8
+ assert(usdAmount.gte(0), "negative amounts not supported");
9
+ if (!usdAmount.eq(0) && usdAmount.lt(0.01)) return `<$0.01`;
10
+ let suffix = "";
11
+ let decimals = 2;
12
+ if (!precise) {
13
+ if (usdAmount.gte(1e12)) {
14
+ usdAmount = usdAmount.shiftedBy(-12);
15
+ suffix = "T";
16
+ } else if (usdAmount.gte(1e9)) {
17
+ usdAmount = usdAmount.shiftedBy(-9);
18
+ suffix = "B";
19
+ } else if (usdAmount.gte(1e6)) {
20
+ usdAmount = usdAmount.shiftedBy(-6);
21
+ suffix = "M";
22
+ }
23
+ if (suffix === "" && usdAmount.gte(1e4)) {
24
+ decimals = 0;
25
+ } else if (suffix !== "") {
26
+ decimals = void 0;
27
+ }
28
+ }
29
+ usdAmount = usdAmount.decimalPlaces(2);
30
+ return `$${usdAmount.toFormat(decimals)}${suffix}`;
31
+ }
3
32
  export {
33
+ formatUsdValue,
4
34
  hexEncodeNumber
5
35
  };
package/dist/ss58.cjs CHANGED
@@ -26,24 +26,7 @@ __export(ss58_exports, {
26
26
  });
27
27
  module.exports = __toCommonJS(ss58_exports);
28
28
 
29
- // src/guard.ts
30
- var createIsGuard = (type) => (value) => typeof value === type;
31
- var isString = createIsGuard("string");
32
- var isNumber = createIsGuard("number");
33
- var isBigInt = createIsGuard("bigint");
34
- var isBoolean = createIsGuard("boolean");
35
- var isSymbol = createIsGuard("symbol");
36
- var isObject = createIsGuard("object");
37
- var isUndefined = createIsGuard("undefined");
38
-
39
- // src/assertion.ts
40
- function assert(condition, message = "assertion failed", Constructor = Error) {
41
- if (!condition) {
42
- throw new Constructor(message);
43
- }
44
- }
45
-
46
- // ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/_assert.js
29
+ // ../../node_modules/.pnpm/@noble+hashes@1.5.0/node_modules/@noble/hashes/esm/_assert.js
47
30
  function number(n) {
48
31
  if (!Number.isSafeInteger(n) || n < 0)
49
32
  throw new Error(`positive integer expected, not ${n}`);
@@ -71,7 +54,7 @@ function output(out, instance) {
71
54
  }
72
55
  }
73
56
 
74
- // ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/utils.js
57
+ // ../../node_modules/.pnpm/@noble+hashes@1.5.0/node_modules/@noble/hashes/esm/utils.js
75
58
  var u32 = (arr) => new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
76
59
  var isLE = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
77
60
  var byteSwap = (word) => word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
@@ -108,7 +91,7 @@ function wrapConstructorWithOpts(hashCons) {
108
91
  return hashC;
109
92
  }
110
93
 
111
- // ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/_blake.js
94
+ // ../../node_modules/.pnpm/@noble+hashes@1.5.0/node_modules/@noble/hashes/esm/_blake.js
112
95
  var SIGMA = /* @__PURE__ */ new Uint8Array([
113
96
  0,
114
97
  1,
@@ -397,7 +380,7 @@ var BLAKE = class extends Hash {
397
380
  }
398
381
  };
399
382
 
400
- // ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/_u64.js
383
+ // ../../node_modules/.pnpm/@noble+hashes@1.5.0/node_modules/@noble/hashes/esm/_u64.js
401
384
  var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
402
385
  var _32n = /* @__PURE__ */ BigInt(32);
403
386
  function fromBig(n, le = false) {
@@ -463,7 +446,7 @@ var u64 = {
463
446
  };
464
447
  var u64_default = u64;
465
448
 
466
- // ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/blake2b.js
449
+ // ../../node_modules/.pnpm/@noble+hashes@1.5.0/node_modules/@noble/hashes/esm/blake2b.js
467
450
  var B2B_IV = /* @__PURE__ */ new Uint32Array([
468
451
  4089235720,
469
452
  1779033703,
@@ -642,6 +625,23 @@ var BLAKE2b = class extends BLAKE {
642
625
  };
643
626
  var blake2b = /* @__PURE__ */ wrapConstructorWithOpts((opts) => new BLAKE2b(opts));
644
627
 
628
+ // src/guard.ts
629
+ var createIsGuard = (type) => (value) => typeof value === type;
630
+ var isString = createIsGuard("string");
631
+ var isNumber = createIsGuard("number");
632
+ var isBigInt = createIsGuard("bigint");
633
+ var isBoolean = createIsGuard("boolean");
634
+ var isSymbol = createIsGuard("symbol");
635
+ var isObject = createIsGuard("object");
636
+ var isUndefined = createIsGuard("undefined");
637
+
638
+ // src/assertion.ts
639
+ function assert(condition, message = "assertion failed", Constructor = Error) {
640
+ if (!condition) {
641
+ throw new Constructor(message);
642
+ }
643
+ }
644
+
645
645
  // src/bytes.ts
646
646
  var bytesToHex = (input) => {
647
647
  const bytes2 = new Uint8Array(input);
@@ -710,7 +710,7 @@ var decode2 = (input) => {
710
710
  ss58Format = (decodedBytes[0] & 63) << 2 | decodedBytes[1] >> 6 | (decodedBytes[1] & 63) << 8;
711
711
  } else {
712
712
  ss58FormatLen = 1;
713
- ss58Format = decodedBytes[0];
713
+ [ss58Format] = decodedBytes;
714
714
  }
715
715
  assert(!RESERVED_PREFIXES.includes(ss58Format), `Reserved prefix: ${ss58Format}`);
716
716
  const checksumBytes = decodedBytes.slice(-CHECKSUM_BYTE_LENGTH);
package/dist/ss58.js CHANGED
@@ -1,17 +1,17 @@
1
1
  import {
2
2
  decode,
3
3
  encode
4
- } from "./chunk-UPA7KLTI.js";
4
+ } from "./chunk-CGMSQQDO.js";
5
5
  import {
6
6
  bytesToHex,
7
7
  hexToBytes
8
- } from "./chunk-D7RIA7SA.js";
8
+ } from "./chunk-2KA626OL.js";
9
9
  import {
10
10
  assert
11
- } from "./chunk-MYP3UYWE.js";
12
- import "./chunk-CZNX6EUV.js";
11
+ } from "./chunk-ZHIKNZLU.js";
12
+ import "./chunk-HBIFE4XN.js";
13
13
 
14
- // ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/_assert.js
14
+ // ../../node_modules/.pnpm/@noble+hashes@1.5.0/node_modules/@noble/hashes/esm/_assert.js
15
15
  function number(n) {
16
16
  if (!Number.isSafeInteger(n) || n < 0)
17
17
  throw new Error(`positive integer expected, not ${n}`);
@@ -39,7 +39,7 @@ function output(out, instance) {
39
39
  }
40
40
  }
41
41
 
42
- // ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/utils.js
42
+ // ../../node_modules/.pnpm/@noble+hashes@1.5.0/node_modules/@noble/hashes/esm/utils.js
43
43
  var u32 = (arr) => new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
44
44
  var isLE = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
45
45
  var byteSwap = (word) => word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
@@ -76,7 +76,7 @@ function wrapConstructorWithOpts(hashCons) {
76
76
  return hashC;
77
77
  }
78
78
 
79
- // ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/_blake.js
79
+ // ../../node_modules/.pnpm/@noble+hashes@1.5.0/node_modules/@noble/hashes/esm/_blake.js
80
80
  var SIGMA = /* @__PURE__ */ new Uint8Array([
81
81
  0,
82
82
  1,
@@ -365,7 +365,7 @@ var BLAKE = class extends Hash {
365
365
  }
366
366
  };
367
367
 
368
- // ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/_u64.js
368
+ // ../../node_modules/.pnpm/@noble+hashes@1.5.0/node_modules/@noble/hashes/esm/_u64.js
369
369
  var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
370
370
  var _32n = /* @__PURE__ */ BigInt(32);
371
371
  function fromBig(n, le = false) {
@@ -431,7 +431,7 @@ var u64 = {
431
431
  };
432
432
  var u64_default = u64;
433
433
 
434
- // ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/blake2b.js
434
+ // ../../node_modules/.pnpm/@noble+hashes@1.5.0/node_modules/@noble/hashes/esm/blake2b.js
435
435
  var B2B_IV = /* @__PURE__ */ new Uint32Array([
436
436
  4089235720,
437
437
  1779033703,
@@ -630,7 +630,7 @@ var decode2 = (input) => {
630
630
  ss58Format = (decodedBytes[0] & 63) << 2 | decodedBytes[1] >> 6 | (decodedBytes[1] & 63) << 8;
631
631
  } else {
632
632
  ss58FormatLen = 1;
633
- ss58Format = decodedBytes[0];
633
+ [ss58Format] = decodedBytes;
634
634
  }
635
635
  assert(!RESERVED_PREFIXES.includes(ss58Format), `Reserved prefix: ${ss58Format}`);
636
636
  const checksumBytes = decodedBytes.slice(-CHECKSUM_BYTE_LENGTH);
package/dist/string.cjs CHANGED
@@ -20,26 +20,47 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/string.ts
21
21
  var string_exports = {};
22
22
  __export(string_exports, {
23
+ abbreviate: () => abbreviate,
23
24
  capitalize: () => capitalize,
24
25
  isHex: () => isHex,
26
+ isInteger: () => isInteger,
25
27
  split: () => split,
26
28
  toLowerCase: () => toLowerCase,
27
29
  toUpperCase: () => toUpperCase,
30
+ truncateString: () => truncateString,
28
31
  uncapitalize: () => uncapitalize
29
32
  });
30
33
  module.exports = __toCommonJS(string_exports);
31
34
  var toUpperCase = (str) => str.toUpperCase();
32
35
  var toLowerCase = (str) => str.toLowerCase();
36
+ var isInteger = (string) => /^\d+$/.test(string);
33
37
  var split = (str, delimiter) => str.split(delimiter);
34
38
  var capitalize = (str) => `${str.charAt(0).toUpperCase()}${str.slice(1)}`;
35
39
  var uncapitalize = (str) => `${str.charAt(0).toLowerCase()}${str.slice(1)}`;
36
40
  var isHex = (str) => /^0x[\da-f]+$/i.test(str);
41
+ var abbreviate = (text, showLength = 4, space = false) => {
42
+ if (typeof text !== "string") return "";
43
+ const leftPart = text.slice(0, showLength);
44
+ const rightPart = text.slice(text.length - showLength);
45
+ return [leftPart, rightPart].join(space ? ". . ." : "\u2026");
46
+ };
47
+ var truncateString = (string, numCharacters = 20, ellipsis = true) => {
48
+ if (string.length < numCharacters) return string;
49
+ let slicedString = string.slice(0, numCharacters);
50
+ if (ellipsis) {
51
+ slicedString += "...";
52
+ }
53
+ return slicedString;
54
+ };
37
55
  // Annotate the CommonJS export names for ESM import in node:
38
56
  0 && (module.exports = {
57
+ abbreviate,
39
58
  capitalize,
40
59
  isHex,
60
+ isInteger,
41
61
  split,
42
62
  toLowerCase,
43
63
  toUpperCase,
64
+ truncateString,
44
65
  uncapitalize
45
66
  });
package/dist/string.d.cts CHANGED
@@ -1,9 +1,14 @@
1
+ import { HexString } from './types.cjs';
2
+
1
3
  declare const toUpperCase: <const T extends string>(str: T) => Uppercase<T>;
2
4
  declare const toLowerCase: <const T extends string>(str: T) => Lowercase<T>;
5
+ declare const isInteger: (string: string) => boolean;
3
6
  type Split<T extends string, D extends string> = T extends `${infer L}${D}${infer R}` ? [L, ...Split<R, D>] : [T];
4
7
  declare const split: <const T extends string, D extends string>(str: T, delimiter: D) => Split<T, D>;
5
8
  declare const capitalize: <const T extends string>(str: T) => Capitalize<T>;
6
9
  declare const uncapitalize: <const T extends string>(str: T) => Uncapitalize<T>;
7
- declare const isHex: (str: string) => str is `0x${string}`;
10
+ declare const isHex: (str: string) => str is HexString;
11
+ declare const abbreviate: (text: string | undefined | null, showLength?: number, space?: boolean) => string;
12
+ declare const truncateString: (string: string, numCharacters?: number, ellipsis?: boolean) => string;
8
13
 
9
- export { capitalize, isHex, split, toLowerCase, toUpperCase, uncapitalize };
14
+ export { abbreviate, capitalize, isHex, isInteger, split, toLowerCase, toUpperCase, truncateString, uncapitalize };
package/dist/string.d.ts CHANGED
@@ -1,9 +1,14 @@
1
+ import { HexString } from './types.js';
2
+
1
3
  declare const toUpperCase: <const T extends string>(str: T) => Uppercase<T>;
2
4
  declare const toLowerCase: <const T extends string>(str: T) => Lowercase<T>;
5
+ declare const isInteger: (string: string) => boolean;
3
6
  type Split<T extends string, D extends string> = T extends `${infer L}${D}${infer R}` ? [L, ...Split<R, D>] : [T];
4
7
  declare const split: <const T extends string, D extends string>(str: T, delimiter: D) => Split<T, D>;
5
8
  declare const capitalize: <const T extends string>(str: T) => Capitalize<T>;
6
9
  declare const uncapitalize: <const T extends string>(str: T) => Uncapitalize<T>;
7
- declare const isHex: (str: string) => str is `0x${string}`;
10
+ declare const isHex: (str: string) => str is HexString;
11
+ declare const abbreviate: (text: string | undefined | null, showLength?: number, space?: boolean) => string;
12
+ declare const truncateString: (string: string, numCharacters?: number, ellipsis?: boolean) => string;
8
13
 
9
- export { capitalize, isHex, split, toLowerCase, toUpperCase, uncapitalize };
14
+ export { abbreviate, capitalize, isHex, isInteger, split, toLowerCase, toUpperCase, truncateString, uncapitalize };
package/dist/string.js CHANGED
@@ -1,15 +1,33 @@
1
1
  // src/string.ts
2
2
  var toUpperCase = (str) => str.toUpperCase();
3
3
  var toLowerCase = (str) => str.toLowerCase();
4
+ var isInteger = (string) => /^\d+$/.test(string);
4
5
  var split = (str, delimiter) => str.split(delimiter);
5
6
  var capitalize = (str) => `${str.charAt(0).toUpperCase()}${str.slice(1)}`;
6
7
  var uncapitalize = (str) => `${str.charAt(0).toLowerCase()}${str.slice(1)}`;
7
8
  var isHex = (str) => /^0x[\da-f]+$/i.test(str);
9
+ var abbreviate = (text, showLength = 4, space = false) => {
10
+ if (typeof text !== "string") return "";
11
+ const leftPart = text.slice(0, showLength);
12
+ const rightPart = text.slice(text.length - showLength);
13
+ return [leftPart, rightPart].join(space ? ". . ." : "\u2026");
14
+ };
15
+ var truncateString = (string, numCharacters = 20, ellipsis = true) => {
16
+ if (string.length < numCharacters) return string;
17
+ let slicedString = string.slice(0, numCharacters);
18
+ if (ellipsis) {
19
+ slicedString += "...";
20
+ }
21
+ return slicedString;
22
+ };
8
23
  export {
24
+ abbreviate,
9
25
  capitalize,
10
26
  isHex,
27
+ isInteger,
11
28
  split,
12
29
  toLowerCase,
13
30
  toUpperCase,
31
+ truncateString,
14
32
  uncapitalize
15
33
  };