diff --git a/packages/core/__tests__/lib/core-is.test.ts b/packages/core/__tests__/lib/core-is.test.ts index b5c5fc0..5b2af96 100644 --- a/packages/core/__tests__/lib/core-is.test.ts +++ b/packages/core/__tests__/lib/core-is.test.ts @@ -106,6 +106,21 @@ describe("@idraw/core static is", () => { expect(Core.is.svg('dafafsfsaffafa')).toStrictEqual(false); }); + test('Core.is.html', () => { + expect(Core.is.html(` +
Hello World
+ `)).toStrictEqual(true); + expect(Core.is.html(` + +
Hello World
+ `)).toStrictEqual(true); + expect(Core.is.html('./xxxxx/xxx')).toStrictEqual(false); + expect(Core.is.html('/xxxxx/xxx')).toStrictEqual(false); + expect(Core.is.html('dafafsfsaffafa')).toStrictEqual(false); + }); + test('Core.is.text', () => { expect(Core.is.text('abcdefg123456')).toStrictEqual(true); expect(Core.is.text('')).toStrictEqual(true); diff --git a/packages/core/src/lib/is.ts b/packages/core/src/lib/is.ts index 46f3357..e0c4027 100644 --- a/packages/core/src/lib/is.ts +++ b/packages/core/src/lib/is.ts @@ -56,6 +56,19 @@ function svg(value: any) { return (typeof value === 'string' && /^()/i.test(`${value}`.trim()) && /<\/[\s]{0,}svg>$/i.test(`${value}`.trim())); } +function html(value: any) { + let result = false; + if (typeof value === 'string') { + let div: null | HTMLDivElement = document.createElement('div'); + div.innerHTML = value; + if (div.children.length > 0) { + result = true; + } + div = null; + } + return result; +} + function text(value: any) { return typeof value === 'string'; } @@ -79,7 +92,7 @@ function fontFamily(value: any) { const is: TypeIs = { x, y, w, h, angle, number, borderWidth, borderRadius, color, - imageSrc, imageURL, imageBase64, svg, + imageSrc, imageURL, imageBase64, svg, html, text, fontSize, lineHeight, textAlign, fontFamily, }; @@ -97,6 +110,7 @@ type TypeIs = { imageURL: (value: any) => boolean, imageBase64: (value: any) => boolean, svg: (value: any) => boolean, + html: (value: any) => boolean, text: (value: any) => boolean, fontSize: (value: any) => boolean, lineHeight: (value: any) => boolean,