@layerzerolabs/typescript-utils 0.0.21 → 0.0.22

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@layerzerolabs/typescript-utils",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -16,8 +16,8 @@
16
16
  "devDependencies": {
17
17
  "tsup": "^8.4.0",
18
18
  "vitest": "^3.2.3",
19
- "@layerzerolabs/tsup-configuration": "0.0.21",
20
- "@layerzerolabs/typescript-configuration": "0.0.21"
19
+ "@layerzerolabs/tsup-configuration": "0.0.22",
20
+ "@layerzerolabs/typescript-configuration": "0.0.22"
21
21
  },
22
22
  "publishConfig": {
23
23
  "access": "restricted",
package/src/index.ts CHANGED
@@ -3,7 +3,6 @@ export * from './branded';
3
3
  export * from './constructor';
4
4
  export * from './deep';
5
5
  export * from './disallowedAny';
6
- export * from './hexString';
7
6
  export * from './lastOf';
8
7
  export * from './merge';
9
8
  export * from './methodOf';
@@ -1,6 +1,6 @@
1
1
  import { expectTypeOf, test } from 'vitest';
2
2
 
3
- import type { StringWithoutSuffix } from './strings';
3
+ import type { HexStringIsTrimmed, StringWithoutSuffix } from './strings';
4
4
 
5
5
  test('StringWithoutSuffix', () => {
6
6
  type A = StringWithoutSuffix<'hello', 'world'>;
@@ -19,3 +19,14 @@ test('StringWithoutSuffix', () => {
19
19
  type E = StringWithoutSuffix<'hello world!', 'lo' | 'world'>;
20
20
  expectTypeOf<E>().toBeString();
21
21
  });
22
+
23
+ test('HexStringIsTrimmed', () => {
24
+ type A = HexStringIsTrimmed<'0x0'>;
25
+ expectTypeOf<A>().toExtend<true>();
26
+
27
+ type B = HexStringIsTrimmed<'0x00'>;
28
+ expectTypeOf<B>().toExtend<false>();
29
+
30
+ type C = HexStringIsTrimmed<'0x'>;
31
+ expectTypeOf<C>().toExtend<false>();
32
+ });
package/src/strings.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import type { Branded } from './branded';
2
+
1
3
  /**
2
4
  * Guarantees that a string does not end with a suffix.
3
5
  * You can remove multiple suffixes by using a union.
@@ -11,3 +13,30 @@ export type StringWithoutSuffix<
11
13
  T extends string,
12
14
  Suffix extends string,
13
15
  > = T extends `${infer _}${Suffix}` ? never : T;
16
+
17
+ export type HexString = `0x${string}`;
18
+
19
+ export declare const _NormalizedHexString: unique symbol;
20
+
21
+ export type NormalizedHexString = Branded<typeof _NormalizedHexString, 'NormalizedHexString'>;
22
+
23
+ /**
24
+ * Guarantees that a hex string is trimmed.
25
+ *
26
+ * @example
27
+ * type A = HexStringIsTrimmed<'0x0'>; // true
28
+ * type B = HexStringIsTrimmed<'0x00'>; // false
29
+ * type C = HexStringIsTrimmed<'0x'>; // false
30
+ * type D = HexStringIsTrimmed<'0x100'>; // true
31
+ */
32
+ export type HexStringIsTrimmed<T extends HexString> = T extends '0x0'
33
+ ? true
34
+ : T extends '0x'
35
+ ? false
36
+ : T extends `0x0${string}`
37
+ ? false
38
+ : true;
39
+
40
+ export declare const _DecimalString: unique symbol;
41
+
42
+ export type DecimalString = Branded<typeof _DecimalString, 'DecimalString'>;
package/dist/5YKETKDX.js DELETED
@@ -1,6 +0,0 @@
1
- import { init_esm_shims } from './4RNWLMHM.js';
2
-
3
- // src/hexString.ts
4
- init_esm_shims();
5
- //# sourceMappingURL=5YKETKDX.js.map
6
- //# sourceMappingURL=5YKETKDX.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/hexString.ts"],"names":[],"mappings":";;;AAEA,cAAA,EAAA","file":"5YKETKDX.js","sourcesContent":["export type HexString = `0x${string}`;\nexport type NormalizedHexString = Symbol;\nexport type HexStringIsTrimmed<T extends HexString> = T extends '0x0'\n ? true\n : T extends `0x0${string}`\n ? false\n : true;\n"]}
package/dist/LRDSETNH.cjs DELETED
@@ -1,8 +0,0 @@
1
- 'use strict';
2
-
3
- var U7VZULNU_cjs = require('./U7VZULNU.cjs');
4
-
5
- // src/hexString.ts
6
- U7VZULNU_cjs.init_cjs_shims();
7
- //# sourceMappingURL=LRDSETNH.cjs.map
8
- //# sourceMappingURL=LRDSETNH.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/hexString.ts"],"names":["init_cjs_shims"],"mappings":";;;;;AAEAA,2BAAA,EAAA","file":"LRDSETNH.cjs","sourcesContent":["export type HexString = `0x${string}`;\nexport type NormalizedHexString = Symbol;\nexport type HexStringIsTrimmed<T extends HexString> = T extends '0x0'\n ? true\n : T extends `0x0${string}`\n ? false\n : true;\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/strings.ts"],"names":[],"mappings":";;;AAAA,cAAA,EAAA","file":"LXPGE3ZL.js","sourcesContent":["/**\n * Guarantees that a string does not end with a suffix.\n * You can remove multiple suffixes by using a union.\n *\n * @example\n * type A = StringWithoutSuffix<'hello', 'world'>; // 'hello'\n * type B = StringWithoutSuffix<'hello', 'lo'>; // never\n * type C = StringWithoutSuffix<'hello world', 'lo' | 'world'>; // never\n */\nexport type StringWithoutSuffix<\n T extends string,\n Suffix extends string,\n> = T extends `${infer _}${Suffix}` ? never : T;\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/strings.ts"],"names":["init_cjs_shims"],"mappings":";;;;;AAAAA,2BAAA,EAAA","file":"ODTE4REV.cjs","sourcesContent":["/**\n * Guarantees that a string does not end with a suffix.\n * You can remove multiple suffixes by using a union.\n *\n * @example\n * type A = StringWithoutSuffix<'hello', 'world'>; // 'hello'\n * type B = StringWithoutSuffix<'hello', 'lo'>; // never\n * type C = StringWithoutSuffix<'hello world', 'lo' | 'world'>; // never\n */\nexport type StringWithoutSuffix<\n T extends string,\n Suffix extends string,\n> = T extends `${infer _}${Suffix}` ? never : T;\n"]}
@@ -1,7 +0,0 @@
1
- 'use strict';
2
-
3
- require('./LRDSETNH.cjs');
4
- require('./U7VZULNU.cjs');
5
-
6
- //# sourceMappingURL=hexString.cjs.map
7
- //# sourceMappingURL=hexString.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"hexString.cjs"}
@@ -1,4 +0,0 @@
1
- export type HexString = `0x${string}`;
2
- export type NormalizedHexString = Symbol;
3
- export type HexStringIsTrimmed<T extends HexString> = T extends '0x0' ? true : T extends `0x0${string}` ? false : true;
4
- //# sourceMappingURL=hexString.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hexString.d.ts","sourceRoot":"","sources":["../src/hexString.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,KAAK,MAAM,EAAE,CAAC;AACtC,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC;AACzC,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,SAAS,IAAI,CAAC,SAAS,KAAK,GAC/D,IAAI,GACJ,CAAC,SAAS,MAAM,MAAM,EAAE,GACtB,KAAK,GACL,IAAI,CAAC"}
package/dist/hexString.js DELETED
@@ -1,4 +0,0 @@
1
- import './5YKETKDX.js';
2
- import './4RNWLMHM.js';
3
- //# sourceMappingURL=hexString.js.map
4
- //# sourceMappingURL=hexString.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"hexString.js"}
package/src/hexString.ts DELETED
@@ -1,7 +0,0 @@
1
- export type HexString = `0x${string}`;
2
- export type NormalizedHexString = Symbol;
3
- export type HexStringIsTrimmed<T extends HexString> = T extends '0x0'
4
- ? true
5
- : T extends `0x0${string}`
6
- ? false
7
- : true;