UNPKG

@progress/kendo-angular-barcodes

Version:
45 lines (44 loc) 1.57 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { qrcodeValidator } from '@progress/kendo-charts'; /** * Creates a value validator for a specific QR Code encoding. * * @param {QRCodeEncoding} encoding Sets the QR Code encoding. Defaults to `ISO_8859_1`. * @returns {ValidatorFn} Returns a validator function. The function returns an error map with the `qrcode` property if the value is invalid. Otherwise, it returns `null`. * * @example * ```ts-no-run * const control = new FormControl('Фоо', createQRCodeValidator()); * console.log(control.errors); * * // { * // qrcode: { * // message: 'Unsupported character in QR Code: "Ф".', * // value: '1234', * // type: 'EAN13' * // } * // } * ``` */ export const createQRCodeValidator = (encoding = 'ISO_8859_1') => { const validator = qrcodeValidator(encoding); return (control) => { if (!control.value) { return null; } const result = validator(control.value); if (result.valid === true) { return null; } return { qrcode: { message: result.error.message, value: control.value, encoding: encoding } }; }; };