UNPKG

820 BJavaScriptView Raw
1import { buildMessage, ValidateBy } from '../common/ValidateBy';
2import isJwtValidator from 'validator/lib/isJWT';
3export const IS_JWT = 'isJwt';
4/**
5 * Checks if the string is valid JWT token.
6 * If given value is not a string, then it returns false.
7 */
8export function isJWT(value) {
9 return typeof value === 'string' && isJwtValidator(value);
10}
11/**
12 * Checks if the string is valid JWT token.
13 * If given value is not a string, then it returns false.
14 */
15export function IsJWT(validationOptions) {
16 return ValidateBy({
17 name: IS_JWT,
18 validator: {
19 validate: (value, args) => isJWT(value),
20 defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be a jwt string', validationOptions),
21 },
22 }, validationOptions);
23}
24//# sourceMappingURL=IsJWT.js.map
\No newline at end of file