UNPKG

1.22 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.IsBase64 = exports.isBase64 = exports.IS_BASE64 = void 0;
7const ValidateBy_1 = require("../common/ValidateBy");
8const isBase64_1 = __importDefault(require("validator/lib/isBase64"));
9exports.IS_BASE64 = 'isBase64';
10/**
11 * Checks if a string is base64 encoded.
12 * If given value is not a string, then it returns false.
13 */
14function isBase64(value) {
15 return typeof value === 'string' && (0, isBase64_1.default)(value);
16}
17exports.isBase64 = isBase64;
18/**
19 * Checks if a string is base64 encoded.
20 * If given value is not a string, then it returns false.
21 */
22function IsBase64(validationOptions) {
23 return (0, ValidateBy_1.ValidateBy)({
24 name: exports.IS_BASE64,
25 validator: {
26 validate: (value, args) => isBase64(value),
27 defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must be base64 encoded', validationOptions),
28 },
29 }, validationOptions);
30}
31exports.IsBase64 = IsBase64;
32//# sourceMappingURL=IsBase64.js.map
\No newline at end of file