feat: update core.check.textDesc

This commit is contained in:
chenshenhai 2021-07-28 00:34:07 +08:00
parent bdf39807b0
commit 417f2fa98c
4 changed files with 21 additions and 1 deletions

View file

@ -113,8 +113,10 @@ describe("@idraw/core static check", () => {
expect(Core.check.textDesc({
text: 'abcdefg',
color: '#af1234',
bgColor: '#f0f0f0',
fontSize: 12,
lineHeight: 12,
fontWeight: 'bold',
fontFamily: 'abc',
textAlign: 'center',
borderRadius: 12,

View file

@ -153,4 +153,10 @@ describe("@idraw/core static is", () => {
expect(Core.is.fontFamily('')).toStrictEqual(false);
});
test('Core.is.fontWeight', () => {
expect(Core.is.fontWeight('bold')).toStrictEqual(true);
expect(Core.is.fontWeight('xxxxxxx')).toStrictEqual(false);
expect(Core.is.fontWeight('')).toStrictEqual(false);
});
})

View file

@ -71,6 +71,7 @@ function textDesc(
): boolean {
const {
text, color, fontSize, lineHeight, fontFamily, textAlign,
fontWeight, bgColor,
} = desc;
if (!is.text(text)){
return false;
@ -81,6 +82,12 @@ function textDesc(
if (!is.fontSize(fontSize)){
return false;
}
if (desc.hasOwnProperty('bgColor') && !is.color(bgColor)){
return false;
}
if (desc.hasOwnProperty('fontWeight') && !is.fontWeight(fontWeight)){
return false;
}
if (desc.hasOwnProperty('lineHeight') && !is.lineHeight(lineHeight)){
return false;
}

View file

@ -89,11 +89,15 @@ function fontFamily(value: any) {
return typeof value === 'string' && value.length > 0;
}
function fontWeight(value: any) {
return ['bold'].includes(value);
}
const is: TypeIs = {
x, y, w, h, angle, number,
borderWidth, borderRadius, color,
imageSrc, imageURL, imageBase64, svg, html,
text, fontSize, lineHeight, textAlign, fontFamily,
text, fontSize, lineHeight, textAlign, fontFamily, fontWeight,
};
type TypeIs = {
@ -113,6 +117,7 @@ type TypeIs = {
html: (value: any) => boolean,
text: (value: any) => boolean,
fontSize: (value: any) => boolean,
fontWeight: (value: any) => boolean,
lineHeight: (value: any) => boolean,
textAlign: (value: any) => boolean,
fontFamily: (value: any) => boolean,