@6river/reason-guard
Advanced tools
Comparing version 3.6.0 to 3.7.0
import { ReasonGuard } from './ReasonGuard'; | ||
export declare const isDateOrDateString: import("./NegatableGuard").NegatableGuard<unknown, string | Date, unknown>; | ||
export declare const isUUIDString: import("./NegatableGuard").NegatableGuard<string, string, string>; | ||
export declare const isUUID: import("./NegatableGuard").NegatableGuard<unknown, string, unknown>; | ||
export declare const numberIsInteger: import("./NegatableGuard").NegatableGuard<number, number, number>; | ||
@@ -4,0 +6,0 @@ export declare const numberIsFinite: import("./NegatableGuard").NegatableGuard<number, number, number>; |
@@ -9,2 +9,13 @@ "use strict"; | ||
exports.isDateOrDateString = Combinators_1.orGuard(Combinators_1.thenGuard(primitiveGuards_1.isString, parseGuards_1.isDateString), instanceGuards_1.isDate); | ||
// TODO investigate non-regex pattern checks | ||
const UUIDRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/; | ||
exports.isUUIDString = Checker_1.checkerToGuard((input) => { | ||
if (UUIDRegex.test(input)) { | ||
return 'Valid UUID'; | ||
} | ||
else { | ||
throw new Error('Not a valid UUID'); | ||
} | ||
}); | ||
exports.isUUID = Combinators_1.thenGuard(primitiveGuards_1.isString, exports.isUUIDString); | ||
exports.numberIsInteger = Checker_1.checkerToGuard((input) => { | ||
@@ -11,0 +22,0 @@ if (!Number.isInteger(input)) { |
@@ -18,2 +18,15 @@ "use strict"; | ||
}); | ||
context('isUUID', function () { | ||
it('should guard for a valid UUID', function () { | ||
assertGuards_1.assertGuards(true)(restricting.isUUID, '0ca8f69c-1d07-4404-9b82-d1d0eb492313'); | ||
}); | ||
it('should guard against a invalid UUID', function () { | ||
assertGuards_1.assertGuards(false)(restricting.isUUID, ''); | ||
assertGuards_1.assertGuards(false)(restricting.isUUID, '123'); | ||
assertGuards_1.assertGuards(false)(restricting.isUUID, 'ABC0ca8f69c-1d07-4404-9b82-d1d0eb492313'); | ||
assertGuards_1.assertGuards(false)(restricting.isUUID, '0ca8f69c-1d07-4404-9b82-d1d0eb492313ABC'); | ||
assertGuards_1.assertGuards(false)(restricting.isUUID, ' 0ca8f69c-1d07-4404-9b82-d1d0eb492313ABC'); | ||
assertGuards_1.assertGuards(false)(restricting.isUUID, 123); | ||
}); | ||
}); | ||
context('isLiteral', function () { | ||
@@ -20,0 +33,0 @@ const testSymbol = Symbol('test'); |
@@ -55,3 +55,3 @@ { | ||
}, | ||
"version": "3.6.0" | ||
"version": "3.7.0" | ||
} |
@@ -16,2 +16,15 @@ import {checkerToGuard} from './Checker'; | ||
// TODO investigate non-regex pattern checks | ||
const UUIDRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/; | ||
export const isUUIDString = checkerToGuard<string, string>((input) => { | ||
if (UUIDRegex.test(input)) { | ||
return 'Valid UUID'; | ||
} else { | ||
throw new Error('Not a valid UUID'); | ||
} | ||
}); | ||
export const isUUID = thenGuard(isString, isUUIDString); | ||
export const numberIsInteger = checkerToGuard<number, number>((input: number) => { | ||
@@ -18,0 +31,0 @@ if (!Number.isInteger(input)) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
311140
2752