use undefined not null

This commit is contained in:
Jon Ruskin
2023-01-17 08:31:36 -07:00
parent b93ce24c3d
commit 9629c8d8d6
3 changed files with 9 additions and 5 deletions

View File

@@ -218,7 +218,11 @@ export const drawText = function (elem, textData) {
} }
} }
for (let [i, line] of lines.entries()) { for (let [i, line] of lines.entries()) {
if (textData.textMargin !== undefined && textData.textMargin === 0 && _textFontSize !== null) { if (
textData.textMargin !== undefined &&
textData.textMargin === 0 &&
_textFontSize !== undefined
) {
dy = i * _textFontSize; dy = i * _textFontSize;
} }
@@ -234,7 +238,7 @@ export const drawText = function (elem, textData) {
if (textData.fontFamily !== undefined) { if (textData.fontFamily !== undefined) {
textElem.style('font-family', textData.fontFamily); textElem.style('font-family', textData.fontFamily);
} }
if (_textFontSizePx !== null) { if (_textFontSizePx !== undefined) {
textElem.style('font-size', _textFontSizePx); textElem.style('font-size', _textFontSizePx);
} }
if (textData.fontWeight !== undefined) { if (textData.fontWeight !== undefined) {

View File

@@ -421,10 +421,10 @@ describe('when parsing font sizes', function () {
}); });
it('handles undefined input', function () { it('handles undefined input', function () {
expect(utils.parseFontSize(undefined)).toEqual([null, null]); expect(utils.parseFontSize(undefined)).toEqual([undefined, undefined]);
}); });
it('handles unparseable input', function () { it('handles unparseable input', function () {
expect(utils.parseFontSize({ fontSize: 14 })).toEqual([null, null]); expect(utils.parseFontSize({ fontSize: 14 })).toEqual([undefined, undefined]);
}); });
}); });

View File

@@ -962,7 +962,7 @@ export const parseFontSize = (fontSize: string | number | undefined): [number?,
const fontSizeNumber = parseInt(fontSize, 10); const fontSizeNumber = parseInt(fontSize, 10);
if (Number.isNaN(fontSizeNumber)) { if (Number.isNaN(fontSizeNumber)) {
// if a number value can't be parsed, return null for both values // if a number value can't be parsed, return null for both values
return [null, null]; return [undefined, undefined];
} else if (fontSize === String(fontSizeNumber)) { } else if (fontSize === String(fontSizeNumber)) {
// if a string input doesn't contain any units, assume px units // if a string input doesn't contain any units, assume px units
return [fontSizeNumber, fontSize + 'px']; return [fontSizeNumber, fontSize + 'px'];