Skip to content

Commit

Permalink
Add isFinite, isInteger, and isSafeInteger (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahsnider authored Dec 1, 2021
1 parent 743ef91 commit 369b89e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"helpers"
],
"dependencies": {
"type-fest": "^2.6.0"
"type-fest": "^2.7.0"
},
"devDependencies": {
"@sindresorhus/tsconfig": "^2.0.0",
Expand Down
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ import {isDefined} from 'ts-extras';
- [`arrayIncludes`](source/array-includes.ts) - An alternative to `Array#includes()` that properly acts as a type guard.
- [`objectKeys`](source/object-keys.ts) - A strongly-typed version of `Object.entries()`.
- [`objectEntries`](source/object-entries.ts) - A strongly-typed version of `Object.keys()`.
- [`isFinite`](source/is-finite.ts) - A strongly-typed version of `Number.isFinite()`.
- [`isInteger`](source/is-integer.ts) - A strongly-typed version of `Number.isInteger()`.
- [`isSafeInteger`](source/is-safe-integer.ts) - A strongly-typed version of `Number.isSafeInteger()`.

## FAQ

Expand Down
11 changes: 11 additions & 0 deletions source/is-finite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {Finite} from 'type-fest';

/**
An alternative to `Number.isFinite()` that properly acts as a type guard.
@category Improved builtin
@category Type guard
*/
export function isFinite<T extends number>(value: T): value is Finite<T> {
return Number.isFinite(value);
}
11 changes: 11 additions & 0 deletions source/is-integer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {Integer} from 'type-fest';

/**
An alternative to `Number.isInteger()` that properly acts as a type guard.
@category Improved builtin
@category Type guard
*/
export function isInteger<T extends number>(value: T): value is Integer<T> {
return Number.isInteger(value);
}
11 changes: 11 additions & 0 deletions source/is-safe-integer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {Integer} from 'type-fest';

/**
An alternative to `Number.isSafeInteger()` that properly acts as a type guard.
@category Improved builtin
@category Type guard
*/
export function isSafeInteger<T extends number>(value: T): value is Integer<T> {
return Number.isSafeInteger(value);
}

0 comments on commit 369b89e

Please sign in to comment.