Skip to content

Commit

Permalink
feat: implement integer validator
Browse files Browse the repository at this point in the history
  • Loading branch information
IamSebastianDev committed Dec 4, 2022
1 parent 2a7bff6 commit fe3bb3b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export {
RegExp,
Unsafe,
NotNull,
OfType,
IsArray,
IsType,
IsInt,
} from './lib';
export type { Collection, ObjectId, JSONDocument } from './lib';
export type {
Expand Down
11 changes: 11 additions & 0 deletions src/lib/Validators/IsInt.validator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/** @format */

import { FlotsamValidationError } from '../../utils';

export const IsInt = (value: unknown, propertyName: string) => {
if (!Number.isInteger(value)) {
throw new FlotsamValidationError(`Expected property '${propertyName}' to be an Integer.`);
}

return true;
};
4 changes: 3 additions & 1 deletion src/lib/Validators/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/** @format */

export { NotNull } from './NotNull.validator';
export { OfType } from './OfType.validator';
export { IsType } from './IsType.validator';
export { FlotsamValidationError, FlotsamOperationError } from '../../utils';
export { IsArray } from './IsArray.validator';
export { IsInt } from './IsInt.validator';
2 changes: 1 addition & 1 deletion src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ export {
RegExp,
Unsafe,
} from './Evaluators';
export { NotNull, OfType } from './Validators';
export { NotNull, IsType, IsArray, IsInt } from './Validators';

0 comments on commit fe3bb3b

Please sign in to comment.