Repository: NativeScript/NativeScript
File: packages/core/ui/styling/font-common.ts (TypeScript)

Code before:
import { Font as FontDefinition } from './font';
import { ParsedFont } from './font-interfaces';
import { makeValidator, makeParser } from '../core/properties';

export * from './font-interfaces';

export abstract class Font implements FontDefinition {
	public static default = undefined;
	public readonly fontStyle: FontStyleType;
	public readonly fontWeight: FontWeightType;
	public readonly fontScale: number;

	get isItalic(): boolean {
		return this.fontStyle === FontStyle.ITALIC;
	}

	get isBold(): boolean {
		return this.fontWeight === FontWeight.SEMI_BOLD || this.fontWeight === FontWeight.BOLD || this.fontWeight === '700' || this.fontWeight === FontWeight.EXTRA_BOLD || this.fontWeight === FontWeight.BLACK;
	}

	protected constructor(public readonly fontFamily: string, public readonly fontSize: number, fontStyle?: FontStyleType, fontWeight?: FontWeightType, fontScale?: number) {
		this.fontStyle = fontStyle || FontStyle.NORMAL;
		this.fontWeight = fontWeight || FontWeight.NORMAL;
		this.fontScale = fontScale || 1;
	}

	public abstract getAndroidTypeface(): any; /* android.graphics.Typeface */
	public abstract getUIFont(defaultFont: any /* UIFont */): any; /* UIFont */
	public abstract withFontFamily(family: string): Font;
	public abstract withFontStyle(style: string): Font;
	public abstract withFontWeight(weight: string): Font;
	public abstract withFontSize(size: number): Font;
	public abstract withFontScale(scale: number): Font;

	public static equals(value1: Font, value2: Font): boolean {
		// both values are falsy
		if (!value1 && !value2) {
			return true;
		}

		// only one is falsy
		if (!value1 || !value2) {
			return false;
		}

		return value1.fontFamily === value2.fontFamily && value1.fontSize === value2.fontSize && value1.fontStyle === value2.fontStyle && value1.fontWeight === value2.fontWeight;
	}
}


Review comment (suggestion):
```suggestion
		this.fontStyle = fontStyle ?? FontStyle.NORMAL;
		this.fontWeight = fontWeight ?? FontWeight.NORMAL;
		this.fontScale = fontScale ?? 1;
```

Code after:
import { Font as FontDefinition } from './font';
import { ParsedFont } from './font-interfaces';
import { makeValidator, makeParser } from '../core/properties';

export * from './font-interfaces';

export abstract class Font implements FontDefinition {
	public static default = undefined;
	public readonly fontStyle: FontStyleType;
	public readonly fontWeight: FontWeightType;
	public readonly fontScale: number;

	get isItalic(): boolean {
		return this.fontStyle === FontStyle.ITALIC;
	}

	get isBold(): boolean {
		return this.fontWeight === FontWeight.SEMI_BOLD || this.fontWeight === FontWeight.BOLD || this.fontWeight === '700' || this.fontWeight === FontWeight.EXTRA_BOLD || this.fontWeight === FontWeight.BLACK;
	}

	protected constructor(public readonly fontFamily: string, public readonly fontSize: number, fontStyle?: FontStyleType, fontWeight?: FontWeightType, fontScale?: number) {
		this.fontStyle = fontStyle ?? FontStyle.NORMAL;
		this.fontWeight = fontWeight ?? FontWeight.NORMAL;
		this.fontScale = fontScale ?? 1;
	}

	public abstract getAndroidTypeface(): any; /* android.graphics.Typeface */
	public abstract getUIFont(defaultFont: any /* UIFont */): any; /* UIFont */
	public abstract withFontFamily(family: string): Font;
	public abstract withFontStyle(style: string): Font;
	public abstract withFontWeight(weight: string): Font;
	public abstract withFontSize(size: number): Font;
	public abstract withFontScale(scale: number): Font;

	public static equals(value1: Font, value2: Font): boolean {
		// both values are falsy
		if (!value1 && !value2) {
			return true;
		}

		// only one is falsy
		if (!value1 || !value2) {
			return false;
		}

		return value1.fontFamily === value2.fontFamily && value1.fontSize === value2.fontSize && value1.fontStyle === value2.fontStyle && value1.fontWeight === value2.fontWeight;
	}
}