Toolbox-XToolbox-X
GuardsPrimitive Type Guards

Numeric Type Guards

Runtime type guards to validate numeric values.

Runtime type guards to validate numeric values.

Imports

import { isInteger, isPositiveInteger, isNumericString } from 'toolbox-x/guards';

isInteger

Validates if a value is an integer.

Signature

isInteger(value: unknown): value is number

Examples

playground.ts

isPositiveInteger

Validates if a value is a positive integer.

Signature

isPositiveInteger(value: unknown): value is number

Examples

playground.ts

isNumericString

Validates whether a value is a string that fully represents a finite number.

Signature

isNumericString(value: unknown): value is `${number}`

Description

This function checks:

  • ✅ Integers: '42', '-15'
  • ✅ Decimals: '3.14', '0.5', '-.99'
  • ✅ Scientific notation: '1e5', '-2.5e-3'
  • ✅ Strings with leading/trailing whitespace (they are trimmed)

It excludes any string that would result in:

  • NaN (e.g. 'abc', '', '42px')
  • Infinity, -Infinity
  • ❌ Hexadecimal numbers (e.g. '0xFF')
  • ❌ Strings that only partially parse into a number

Info

Internally uses Number.isFinite(Number(value)) for validation.

Examples

playground.ts

Note

Please, refer to number guard: isNumber for strict number type checking.

Last updated: Sat, Jun 06, 2026 09:29:26AM (UTC)

On this page