feat: add core.check.htmlDesc

This commit is contained in:
chenshenhai 2021-07-28 00:43:40 +08:00
parent f7953be78a
commit 042e34afca
2 changed files with 38 additions and 1 deletions

View file

@ -133,6 +133,31 @@ describe("@idraw/core static check", () => {
});
test('Core.check.htmlDesc', () => {
expect(Core.check.htmlDesc({
html: `
<style>
.box { display: block }
</style>
<div class="box">Hello World</div>
`,
})).toStrictEqual(true);
expect(Core.check.htmlDesc({
html: `
abcdefg
<div class="box">Hello World</div>
`,
})).toStrictEqual(true);
expect(Core.check.htmlDesc({
html: 'Hello World',
})).toStrictEqual(false);
expect(Core.check.htmlDesc({})).toStrictEqual(false);
});
test('Core.check.textDesc', () => {
expect(Core.check.textDesc({
text: 'abcdefg',

View file

@ -82,6 +82,16 @@ function svgDesc(
return true;
}
function htmlDesc(
desc: any
): boolean {
const { html } = desc;
if (!is.html(html)) {
return false;
}
return true;
}
function textDesc(
desc: any
): boolean {
@ -121,11 +131,12 @@ function textDesc(
const check = {
attrs,
textDesc,
rectDesc,
circleDesc,
imageDesc,
svgDesc,
textDesc,
htmlDesc,
};
type TypeCheck = {
@ -134,6 +145,7 @@ type TypeCheck = {
circleDesc: (value: any) => boolean,
imageDesc: (value: any) => boolean,
svgDesc: (value: any) => boolean,
htmlDesc: (value: any) => boolean,
textDesc: (value: any) => boolean,
}