@pdfme/common 1.0.0-beta.9 → 1.0.2
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.
- package/dist/index.js +1 -1
- package/dist/index.js.LICENSE.txt +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types/helper.d.ts +2 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/schema.d.ts +1 -0
- package/package.json +1 -1
- package/src/helper.ts +31 -5
- package/src/index.ts +4 -0
- package/src/schema.ts +1 -1
package/dist/types/helper.d.ts
CHANGED
@@ -7,6 +7,8 @@ export declare const checkFont: (arg: {
|
|
7
7
|
font: Font;
|
8
8
|
template: Template;
|
9
9
|
}) => void;
|
10
|
+
export declare const checkInputs: (data: unknown) => void;
|
11
|
+
export declare const checkUIOptions: (data: unknown) => void;
|
10
12
|
export declare const checkTemplate: (data: unknown) => void;
|
11
13
|
export declare const checkUIProps: (data: unknown) => void;
|
12
14
|
export declare const checkPreviewProps: (data: unknown) => void;
|
package/dist/types/index.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { DEFAULT_FONT_SIZE, DEFAULT_ALIGNMENT, DEFAULT_LINE_HEIGHT, DEFAULT_CHARACTER_SPACING, DEFAULT_FONT_COLOR, BLANK_PDF } from './constants';
|
2
2
|
import { schemaTypes, isImageSchema, isBarcodeSchema, isTextSchema } from './type';
|
3
3
|
import type { Lang, Size, Alignment, SchemaType, BarCodeType, TextSchema, ImageSchema, BarcodeSchema, Schema, SchemaForUI, Font, BasePdf, Template, CommonProps, GeneratorOptions, GenerateProps, UIOptions, UIProps, PreviewProps, PreviewReactProps, DesignerProps, DesignerReactProps } from './type';
|
4
|
-
import { getB64BasePdf, b64toUint8Array, getFallbackFontName, getDefaultFont, checkFont, checkTemplate, checkUIProps, checkPreviewProps, checkDesignerProps, checkGenerateProps, validateBarcodeInput } from './helper';
|
5
|
-
export { DEFAULT_FONT_SIZE, DEFAULT_ALIGNMENT, DEFAULT_LINE_HEIGHT, DEFAULT_CHARACTER_SPACING, DEFAULT_FONT_COLOR, BLANK_PDF, schemaTypes, isTextSchema, isImageSchema, isBarcodeSchema, getB64BasePdf, b64toUint8Array, getFallbackFontName, getDefaultFont, checkFont, checkTemplate, checkUIProps, checkPreviewProps, checkDesignerProps, checkGenerateProps, validateBarcodeInput, };
|
4
|
+
import { getB64BasePdf, b64toUint8Array, getFallbackFontName, getDefaultFont, checkFont, checkInputs, checkUIOptions, checkTemplate, checkUIProps, checkPreviewProps, checkDesignerProps, checkGenerateProps, validateBarcodeInput } from './helper';
|
5
|
+
export { DEFAULT_FONT_SIZE, DEFAULT_ALIGNMENT, DEFAULT_LINE_HEIGHT, DEFAULT_CHARACTER_SPACING, DEFAULT_FONT_COLOR, BLANK_PDF, schemaTypes, isTextSchema, isImageSchema, isBarcodeSchema, getB64BasePdf, b64toUint8Array, getFallbackFontName, getDefaultFont, checkFont, checkInputs, checkUIOptions, checkTemplate, checkUIProps, checkPreviewProps, checkDesignerProps, checkGenerateProps, validateBarcodeInput, };
|
6
6
|
export type { Lang, Size, Alignment, SchemaType, BarCodeType, TextSchema, ImageSchema, BarcodeSchema, Schema, SchemaForUI, Font, BasePdf, Template, CommonProps, GeneratorOptions, GenerateProps, UIOptions, UIProps, PreviewProps, PreviewReactProps, DesignerProps, DesignerReactProps, };
|
package/dist/types/schema.d.ts
CHANGED
@@ -686,6 +686,7 @@ export declare const Template: z.ZodObject<{
|
|
686
686
|
}>[];
|
687
687
|
basePdf: string | ArrayBuffer | Uint8Array;
|
688
688
|
}>;
|
689
|
+
export declare const Inputs: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodString>, "many">;
|
689
690
|
export declare const CommonProps: z.ZodObject<{
|
690
691
|
template: z.ZodObject<{
|
691
692
|
schemas: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<z.extendShape<{
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@pdfme/common",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.2",
|
4
4
|
"author": "hand-dot",
|
5
5
|
"license": "MIT",
|
6
6
|
"description": "TypeScript base PDF generator and React base UI. Open source, developed by the community, and completely free to use under the MIT license!",
|
package/src/helper.ts
CHANGED
@@ -2,6 +2,8 @@ import { z } from 'zod';
|
|
2
2
|
import Helvetica from './assets/Helvetica.ttf';
|
3
3
|
import { Template, Schema, BasePdf, Font, CommonProps, isTextSchema, BarCodeType } from './type';
|
4
4
|
import {
|
5
|
+
Inputs as InputsSchema,
|
6
|
+
UIOptions as UIOptionsSchema,
|
5
7
|
Template as TemplateSchema,
|
6
8
|
PreviewProps as PreviewPropsSchema,
|
7
9
|
DesignerProps as DesignerPropsSchema,
|
@@ -140,12 +142,36 @@ ${message}`);
|
|
140
142
|
}
|
141
143
|
};
|
142
144
|
|
145
|
+
export const checkInputs = (data: unknown) => checkProps(data, InputsSchema);
|
146
|
+
export const checkUIOptions = (data: unknown) => checkProps(data, UIOptionsSchema);
|
143
147
|
export const checkTemplate = (data: unknown) => checkProps(data, TemplateSchema);
|
144
148
|
export const checkUIProps = (data: unknown) => checkProps(data, UIPropsSchema);
|
145
149
|
export const checkPreviewProps = (data: unknown) => checkProps(data, PreviewPropsSchema);
|
146
150
|
export const checkDesignerProps = (data: unknown) => checkProps(data, DesignerPropsSchema);
|
147
151
|
export const checkGenerateProps = (data: unknown) => checkProps(data, GeneratePropsSchema);
|
148
152
|
|
153
|
+
// GTIN-13, GTIN-8, GTIN-12, GTIN-14
|
154
|
+
const validateCheckDigit = (input: string, checkDigitPos: number) => {
|
155
|
+
let passCheckDigit = true;
|
156
|
+
|
157
|
+
if (input.length === checkDigitPos) {
|
158
|
+
const ds = input.slice(0, -1).replace(/[^0-9]/g, '');
|
159
|
+
let sum = 0;
|
160
|
+
let odd = 1;
|
161
|
+
for (let i = ds.length - 1; i > -1; i -= 1) {
|
162
|
+
sum += Number(ds[i]) * (odd ? 3 : 1);
|
163
|
+
odd ^= 1;
|
164
|
+
if (sum > 0xffffffffffff) {
|
165
|
+
// ~2^48 at max
|
166
|
+
sum %= 10;
|
167
|
+
}
|
168
|
+
}
|
169
|
+
passCheckDigit = String(10 - (sum % 10)).slice(-1) === input.slice(-1);
|
170
|
+
}
|
171
|
+
|
172
|
+
return passCheckDigit;
|
173
|
+
};
|
174
|
+
|
149
175
|
export const validateBarcodeInput = (type: BarCodeType, input: string) => {
|
150
176
|
if (!input) return false;
|
151
177
|
if (type === 'qrcode') {
|
@@ -162,13 +188,13 @@ export const validateBarcodeInput = (type: BarCodeType, input: string) => {
|
|
162
188
|
// 有効文字は数値(0-9)のみ。チェックデジットを含まない12桁orチェックデジットを含む13桁。
|
163
189
|
const regexp = /^\d{12}$|^\d{13}$/;
|
164
190
|
|
165
|
-
return regexp.test(input);
|
191
|
+
return regexp.test(input) && validateCheckDigit(input, 13);
|
166
192
|
}
|
167
193
|
if (type === 'ean8') {
|
168
194
|
// 有効文字は数値(0-9)のみ。チェックデジットを含まない7桁orチェックデジットを含む8桁。
|
169
195
|
const regexp = /^\d{7}$|^\d{8}$/;
|
170
196
|
|
171
|
-
return regexp.test(input);
|
197
|
+
return regexp.test(input) && validateCheckDigit(input, 8);
|
172
198
|
}
|
173
199
|
if (type === 'code39') {
|
174
200
|
// 有効文字は数字(0-9)。アルファベット大文字(A-Z)、記号(-.$/+%)、半角スペース。
|
@@ -194,20 +220,20 @@ export const validateBarcodeInput = (type: BarCodeType, input: string) => {
|
|
194
220
|
// 有効文字は数値(0-9)のみ。 チェックデジットを含まない13桁orチェックデジットを含む14桁。
|
195
221
|
const regexp = /^\d{13}$|^\d{14}$/;
|
196
222
|
|
197
|
-
return regexp.test(input);
|
223
|
+
return regexp.test(input) && validateCheckDigit(input, 14);
|
198
224
|
}
|
199
225
|
if (type === 'upca') {
|
200
226
|
// 有効文字は数値(0-9)のみ。 チェックデジットを含まない11桁orチェックデジットを含む12桁。
|
201
227
|
const regexp = /^\d{11}$|^\d{12}$/;
|
202
228
|
|
203
|
-
return regexp.test(input);
|
229
|
+
return regexp.test(input) && validateCheckDigit(input, 12);
|
204
230
|
}
|
205
231
|
if (type === 'upce') {
|
206
232
|
// 有効文字は数値(0-9)のみ。 1桁目に指定できる数字(ナンバーシステムキャラクタ)は0のみ。
|
207
233
|
// チェックデジットを含まない7桁orチェックデジットを含む8桁。
|
208
234
|
const regexp = /^0(\d{6}$|\d{7}$)/;
|
209
235
|
|
210
|
-
return regexp.test(input);
|
236
|
+
return regexp.test(input) && validateCheckDigit(input, 8);
|
211
237
|
}
|
212
238
|
|
213
239
|
return false;
|
package/src/index.ts
CHANGED
@@ -37,6 +37,8 @@ import {
|
|
37
37
|
getFallbackFontName,
|
38
38
|
getDefaultFont,
|
39
39
|
checkFont,
|
40
|
+
checkInputs,
|
41
|
+
checkUIOptions,
|
40
42
|
checkTemplate,
|
41
43
|
checkUIProps,
|
42
44
|
checkPreviewProps,
|
@@ -61,6 +63,8 @@ export {
|
|
61
63
|
getFallbackFontName,
|
62
64
|
getDefaultFont,
|
63
65
|
checkFont,
|
66
|
+
checkInputs,
|
67
|
+
checkUIOptions,
|
64
68
|
checkTemplate,
|
65
69
|
checkUIProps,
|
66
70
|
checkPreviewProps,
|
package/src/schema.ts
CHANGED
@@ -66,7 +66,7 @@ export const Template = z.object({
|
|
66
66
|
columns: z.array(z.string()).optional(),
|
67
67
|
});
|
68
68
|
|
69
|
-
const Inputs = z.array(z.record(z.string())).min(1);
|
69
|
+
export const Inputs = z.array(z.record(z.string())).min(1);
|
70
70
|
|
71
71
|
const CommonOptions = z.object({ font: Font.optional() });
|
72
72
|
|