feat: update core.check.circleDesc

This commit is contained in:
chenshenhai 2021-07-28 00:40:33 +08:00
parent 417f2fa98c
commit f7953be78a
2 changed files with 42 additions and 0 deletions

View file

@ -55,6 +55,30 @@ describe("@idraw/core static check", () => {
});
test('Core.check.circleDesc', () => {
expect(Core.check.circleDesc({
color: '#ffffff',
})).toStrictEqual(true);
expect(Core.check.circleDesc({
color: 123,
})).toStrictEqual(false);
expect(Core.check.circleDesc({
borderWidth: 10,
borderColor: '#123abf',
color: '#ffffff',
})).toStrictEqual(true);
expect(Core.check.circleDesc({
borderWidth: 10,
borderColor: '#123af',
})).toStrictEqual(false);
});
test('Core.check.imageDesc', () => {
expect(Core.check.imageDesc({

View file

@ -45,6 +45,22 @@ function rectDesc(
return true;
}
function circleDesc(
desc: any
): boolean {
const { color, borderColor, borderWidth } = desc;
if (desc.hasOwnProperty('color') && !is.color(color)) {
return false;
}
if (desc.hasOwnProperty('borderColor') && !is.color(borderColor)) {
return false;
}
if (desc.hasOwnProperty('borderWidth') && !is.number(borderWidth)) {
return false;
}
return true;
}
function imageDesc(
desc: any
@ -106,6 +122,7 @@ function textDesc(
const check = {
attrs,
rectDesc,
circleDesc,
imageDesc,
svgDesc,
textDesc,
@ -114,6 +131,7 @@ const check = {
type TypeCheck = {
attrs: (value: any) => boolean,
rectDesc: (value: any) => boolean,
circleDesc: (value: any) => boolean,
imageDesc: (value: any) => boolean,
svgDesc: (value: any) => boolean,
textDesc: (value: any) => boolean,