number uint32 - nberlette/is GitHub Wiki
function isUint32<N = number>(it: N): it is Uint32<N>;
Checks if a given value is an unsigned 32-bit integer.
Name | Info |
---|---|
it |
The value to check. |
true
if it
is an unsigned 32-bit integer, false
otherwise.
Numbers
number
unsigned
integer
import { isUint32, type MaybeUint32, type Uint32 } from "@nick/is/number";
let value = 1 as Uint32;
const setValue = (newValue: MaybeUint32) => {
if (isUint32(newValue)) value = newValue;
};
setValue(0xFFFF); // <- No error!
// This will raise a TypeScript compiler error:
value = -1; // <- TS2322 Type '-1' is not assignable to type 'Uint32'.
function isUint32(it: unknown): it is Uint32<number>;
Checks if a given value is an unsigned 32-bit integer.
Name | Info |
---|---|
it |
The value to check. |
true
if it
is an unsigned 32-bit integer, false
otherwise.
Numbers
number
unsigned
integer
import { isUint32, type MaybeUint32, type Uint32 } from "@nick/is/number";
let value = 1 as Uint32;
const setValue = (newValue: MaybeUint32) => {
if (isUint32(newValue)) value = newValue;
};
setValue(0xFFFF); // <- No error!
// This will raise a TypeScript compiler error:
value = -1; // <- TS2322 Type '-1' is not assignable to type 'Uint32'.
export type MaybeUint32<N = number> = Cast<N, MAYBE_UINT32>;
Casts a value into a partial unsigned 32-bit integer type.
-
N
(default:number
)
Numbers
Types
maybe
unsigned
integer
import { isUint32, type MaybeUint32, type Uint32 } from "@nick/is/number";
let value = 1 as Uint32;
const setValue = (newValue: MaybeUint32) => {
if (isUint32(newValue)) value = newValue;
};
setValue(0xFFFF); // <- No error!
// This will raise a TypeScript compiler error:
value = -1; // <- TS2322 Type '-1' is not assignable to type 'Uint32'.
export type Uint32<N = number> = Cast<N, UINT32>;
Casts a value into an unsigned 32-bit integer type.
-
N
(default:number
)
Numbers
Types
unsigned
integer
import { isUint32, type MaybeUint32, type Uint32 } from "@nick/is/number";
let value = 1 as Uint32;
const setValue = (newValue: MaybeUint32) => {
if (isUint32(newValue)) value = newValue;
};
setValue(0xFFFF); // <- No error!
// This will raise a TypeScript compiler error:
value = -1; // <- TS2322 Type '-1' is not assignable to type 'Uint32'.