number uint8 - nberlette/is GitHub Wiki
function isUint8<N = number>(it: N): it is Uint8<N>;
Checks if a given value is an unsigned 8-bit integer.
Name | Info |
---|---|
it |
The value to check. |
true
if it
is an unsigned 8-bit integer, false
otherwise.
Numbers
number
unsigned
integer
import { isUint8 } from "jsr:@nick/is/uint8";
isUint8(1); // true
isUint8(128); // true
isUint8(0xFF); // true
isUint8(-1); // false
isUint8(420); // false
function isUint8(it: unknown): it is Uint8<number>;
Checks if a given value is an unsigned 8-bit integer.
Name | Info |
---|---|
it |
The value to check. |
true
if it
is an unsigned 8-bit integer, false
otherwise.
Numbers
number
unsigned
integer
import { isUint8 } from "jsr:@nick/is/uint8";
isUint8(1); // true
isUint8(128); // true
isUint8(0xFF); // true
isUint8(-1); // false
isUint8(420); // false
export type MaybeUint8<N = number> = Cast<N, MAYBE_UINT8>;
Casts a value into a partial unsigned 8-bit integer type.
-
N
(default:number
)
Numbers
Types
maybe
unsigned
integer
import { isUint8, type MaybeUint8 } from "@nick/is/uint8";
let i = 1 as MaybeUint8, y = 0;
if (isUint8(i)) {
console.log(i);
} else {
console.log(y);
}
y = 1; // <- No error! (this is the main difference from `Uint8`)
export type Uint8<N = number> = Cast<N, UINT8>;
Casts a value into an unsigned 8-bit integer type.
-
N
(default:number
)
Numbers
Types
unsigned
integer
import { isUint8, type Uint8 } from "@nick/is/uint8";
let i = 1 as Uint8, y = 0;
if (isUint8(i)) {
console.log(i);
} else {
console.log(y);
}
// This will raise a TypeScript compiler error:
i = -1; // <- TS2322 Type '-1' is not assignable to type 'Uint8'.