UNPKG

872 BJavaScriptView Raw
1import { buildMessage, ValidateBy } from '../common/ValidateBy';
2import isEANValidator from 'validator/lib/isEAN';
3export const IS_EAN = 'isEAN';
4/**
5 * Check if the string is an EAN (European Article Number).
6 * If given value is not a string, then it returns false.
7 */
8export function isEAN(value) {
9 return typeof value === 'string' && isEANValidator(value);
10}
11/**
12 * Check if the string is an EAN (European Article Number).
13 * If given value is not a string, then it returns false.
14 */
15export function IsEAN(validationOptions) {
16 return ValidateBy({
17 name: IS_EAN,
18 validator: {
19 validate: (value, args) => isEAN(value),
20 defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be an EAN (European Article Number)', validationOptions),
21 },
22 }, validationOptions);
23}
24//# sourceMappingURL=IsEAN.js.map
\No newline at end of file