@progress/kendo-charts 1.21.0 → 1.22.0-dev.202112221528

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,50 @@
1
+ import { Encodings } from './encodings/main';
2
+
3
+ var validate = function (encoding, size, prefix) { return function (value) {
4
+ try {
5
+ encoding.encode(
6
+ prefix + value,
7
+ size.width,
8
+ size.height
9
+ );
10
+ } catch (error) {
11
+ return {
12
+ valid: false,
13
+ error: error
14
+ };
15
+ }
16
+
17
+ return {
18
+ valid: true
19
+ };
20
+ }; };
21
+
22
+ // A default size for encodings, so the validator can check only the value if no size is provided.
23
+ var fallbackSize = { width: 500, height: 100 };
24
+
25
+ function barcodeValidator(type, size) {
26
+ if ( size === void 0 ) size = fallbackSize;
27
+
28
+ if (!type) {
29
+ throw new Error("Please specify barcode type to validate.");
30
+ }
31
+
32
+ var resolvedType = type.toLowerCase();
33
+ var prefix = '';
34
+ if (resolvedType === 'upca') {
35
+ resolvedType = 'ean13';
36
+ prefix = '0';
37
+ } else if (resolvedType === 'upce') {
38
+ resolvedType = 'ean8';
39
+ prefix = '0';
40
+ }
41
+
42
+ if (!Encodings[resolvedType]) {
43
+ throw new Error(("Encoding '" + type + "' is not supported."));
44
+ }
45
+
46
+ var encoding = new Encodings[resolvedType]();
47
+ return validate(encoding, size, prefix);
48
+ }
49
+
50
+ export default barcodeValidator;
@@ -1 +1,2 @@
1
1
  export { default as Barcode } from './barcode/barcode';
2
+ export { default as barcodeValidator } from './barcode/barcode-validator';
@@ -0,0 +1,24 @@
1
+ import { encodeData } from './encodings/encoding';
2
+
3
+ var ISO = 'ISO_8859_1';
4
+
5
+ function qrcodeValidator(encoding) {
6
+ if ( encoding === void 0 ) encoding = ISO;
7
+
8
+ return function(value) {
9
+ try {
10
+ encodeData(value, 'L', encoding);
11
+ } catch (error) {
12
+ return {
13
+ valid: false,
14
+ error: error
15
+ };
16
+ }
17
+
18
+ return {
19
+ valid: true
20
+ };
21
+ };
22
+ }
23
+
24
+ export default qrcodeValidator;
package/dist/es/qrcode.js CHANGED
@@ -1 +1,2 @@
1
1
  export { default as QRCode } from './qrcode/qrcode';
2
+ export { default as qrcodeValidator } from './qrcode/qrcode-validator';
@@ -0,0 +1,48 @@
1
+ import { Encodings } from './encodings/main';
2
+
3
+ const validate = (encoding, size, prefix) => (value) => {
4
+ try {
5
+ encoding.encode(
6
+ prefix + value,
7
+ size.width,
8
+ size.height
9
+ );
10
+ } catch (error) {
11
+ return {
12
+ valid: false,
13
+ error
14
+ };
15
+ }
16
+
17
+ return {
18
+ valid: true
19
+ };
20
+ };
21
+
22
+ // A default size for encodings, so the validator can check only the value if no size is provided.
23
+ const fallbackSize = { width: 500, height: 100 };
24
+
25
+ function barcodeValidator(type, size = fallbackSize) {
26
+ if (!type) {
27
+ throw new Error(`Please specify barcode type to validate.`);
28
+ }
29
+
30
+ let resolvedType = type.toLowerCase();
31
+ let prefix = '';
32
+ if (resolvedType === 'upca') {
33
+ resolvedType = 'ean13';
34
+ prefix = '0';
35
+ } else if (resolvedType === 'upce') {
36
+ resolvedType = 'ean8';
37
+ prefix = '0';
38
+ }
39
+
40
+ if (!Encodings[resolvedType]) {
41
+ throw new Error(`Encoding '${type}' is not supported.`);
42
+ }
43
+
44
+ const encoding = new Encodings[resolvedType]();
45
+ return validate(encoding, size, prefix);
46
+ }
47
+
48
+ export default barcodeValidator;
@@ -1 +1,2 @@
1
1
  export { default as Barcode } from './barcode/barcode';
2
+ export { default as barcodeValidator } from './barcode/barcode-validator';
@@ -0,0 +1,22 @@
1
+ import { encodeData } from './encodings/encoding';
2
+
3
+ const ISO = 'ISO_8859_1';
4
+
5
+ function qrcodeValidator(encoding = ISO) {
6
+ return function(value) {
7
+ try {
8
+ encodeData(value, 'L', encoding);
9
+ } catch (error) {
10
+ return {
11
+ valid: false,
12
+ error
13
+ };
14
+ }
15
+
16
+ return {
17
+ valid: true
18
+ };
19
+ };
20
+ }
21
+
22
+ export default qrcodeValidator;
@@ -1 +1,2 @@
1
1
  export { default as QRCode } from './qrcode/qrcode';
2
+ export { default as qrcodeValidator } from './qrcode/qrcode-validator';
@@ -1,5 +1,6 @@
1
- import { Group } from '@progress/kendo-drawing';
1
+ import { Group, geometry } from '@progress/kendo-drawing';
2
2
  import { Border, Margin, Padding, RenderMode } from './field-types';
3
+ import { ValidationResult } from './validation';
3
4
 
4
5
  /**
5
6
  * Supported symbologies (encodings) for the Barcode component.
@@ -130,3 +131,5 @@ export class Barcode {
130
131
  public setOptions(options: BarcodeOptions): void;
131
132
  public exportVisual(): Group;
132
133
  }
134
+
135
+ export function barcodeValidator(type: BarcodeType, size: geometry.Size): (value: number | string) => ValidationResult;
@@ -8,5 +8,6 @@ export * from './barcode';
8
8
  export * from './qrcode';
9
9
  export * from './common';
10
10
  export * from './field-types'
11
+ export * from './validation';
11
12
 
12
13
  export function chartBaseTheme(): any;