Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/hex-prefixed.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* A string prefixed with "0x". This usually indicates that the string is a
* hexadecimal number.
*
* Note that this type doesn't ensure the string is a valid hexadecimal value.
* It only matches the "0x" prefix.
*/
export type HexPrefixed = `0x${string}`;
1 change: 1 addition & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './json';
export * from './hex-prefixed';
26 changes: 26 additions & 0 deletions test-d/hex-prefixed.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { expectAssignable, expectNotAssignable } from 'tsd';

import { HexPrefixed } from '../src/hex-prefixed';

// Valid hex-prefixed strings:

expectAssignable<HexPrefixed>('0x');

expectAssignable<HexPrefixed>('0x0');

expectAssignable<HexPrefixed>('0x😀');

const embeddedString = 'test';
expectAssignable<HexPrefixed>(`0x${embeddedString}`);

// Not valid hex-prefixed strings:

expectNotAssignable<HexPrefixed>(`0X${embeddedString}`);

expectNotAssignable<HexPrefixed>(`1x${embeddedString}`);

expectNotAssignable<HexPrefixed>(0);

expectNotAssignable<HexPrefixed>('0');

expectNotAssignable<HexPrefixed>('🙃');