Skip to content

Commit

Permalink
Added primitive type guards
Browse files Browse the repository at this point in the history
  • Loading branch information
alexiglesias93 committed Oct 26, 2022
1 parent da7fa9c commit 0024923
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/pretty-drinks-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@finsweet/ts-utils': minor
---

Added primitive type guards
1 change: 1 addition & 0 deletions src/type-guards/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { isFormField } from './isFormField';
export { isKeyOf } from './isKeyOf';
export { isNotEmpty } from './isNotEmpty';
export * from './primitives';
19 changes: 19 additions & 0 deletions src/type-guards/primitives.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/ban-types */
export const isString = (value: unknown): value is string => typeof value === 'string';

export const isNumber = (value: unknown): value is number => typeof value === 'number';

export const isBigint = (value: unknown): value is bigint => typeof value === 'bigint';

export const isBoolean = (value: unknown): value is boolean => typeof value === 'boolean';

export const isSymbol = (value: unknown): value is symbol => typeof value === 'symbol';

export const isUndefined = (value: unknown): value is undefined => value === undefined;

export const isNull = (value: unknown): value is null => value === null;

export const isFunction = (value: unknown): value is Function => typeof value === 'function';

export const isObject = (value: unknown): value is Record<any, any> => value !== null && typeof value === 'object';

0 comments on commit 0024923

Please sign in to comment.