UNPKG

940 BJavaScriptView Raw
1import { buildMessage, ValidateBy } from '../common/ValidateBy';
2export const IS_FIREBASE_PUSH_ID = 'IsFirebasePushId';
3/**
4 * Checks if the string is a Firebase Push Id
5 * If given value is not a Firebase Push Id, it returns false
6 */
7export function isFirebasePushId(value) {
8 const webSafeRegex = /^[a-zA-Z0-9_-]*$/;
9 return typeof value === 'string' && value.length === 20 && webSafeRegex.test(value);
10}
11/**
12 * Checks if the string is a Firebase Push Id
13 * If given value is not a Firebase Push Id, it returns false
14 */
15export function IsFirebasePushId(validationOptions) {
16 return ValidateBy({
17 name: IS_FIREBASE_PUSH_ID,
18 validator: {
19 validate: (value, args) => isFirebasePushId(value),
20 defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be a Firebase Push Id', validationOptions),
21 },
22 }, validationOptions);
23}
24//# sourceMappingURL=IsFirebasePushId.js.map
\No newline at end of file