From 417f2fa98cfd73c0b29cf90b850d23416b73bf8c Mon Sep 17 00:00:00 2001 From: chenshenhai Date: Wed, 28 Jul 2021 00:34:07 +0800 Subject: [PATCH] feat: update core.check.textDesc --- packages/core/__tests__/lib/core-check.test.ts | 2 ++ packages/core/__tests__/lib/core-is.test.ts | 6 ++++++ packages/core/src/lib/check.ts | 7 +++++++ packages/core/src/lib/is.ts | 7 ++++++- 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/core/__tests__/lib/core-check.test.ts b/packages/core/__tests__/lib/core-check.test.ts index 2b583bb..b70e3bf 100644 --- a/packages/core/__tests__/lib/core-check.test.ts +++ b/packages/core/__tests__/lib/core-check.test.ts @@ -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, diff --git a/packages/core/__tests__/lib/core-is.test.ts b/packages/core/__tests__/lib/core-is.test.ts index 5b2af96..df22c06 100644 --- a/packages/core/__tests__/lib/core-is.test.ts +++ b/packages/core/__tests__/lib/core-is.test.ts @@ -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); + }); + }) \ No newline at end of file diff --git a/packages/core/src/lib/check.ts b/packages/core/src/lib/check.ts index f424860..df4b328 100644 --- a/packages/core/src/lib/check.ts +++ b/packages/core/src/lib/check.ts @@ -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; } diff --git a/packages/core/src/lib/is.ts b/packages/core/src/lib/is.ts index e0c4027..1a07e5f 100644 --- a/packages/core/src/lib/is.ts +++ b/packages/core/src/lib/is.ts @@ -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,