Skip to content

Commit

Permalink
Handle value not an object in isTextStyleObject
Browse files Browse the repository at this point in the history
  • Loading branch information
YoussefHenna committed Nov 20, 2024
1 parent da5288f commit dcdc06e
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions packages/theme/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@ import { isObject } from "lodash";
import type { ThemeValues } from "./types";

export function isTextStyleObject(value: any): boolean {
return Object.keys(value).some((key) =>
[
"fontFamily",
"fontWeight",
"fontSize",
"fontStyle",
"lineHeight",
"letterSpacing",
].includes(key)
);
try {
return Object.keys(value).some((key) =>
[
"fontFamily",
"fontWeight",
"fontSize",
"fontStyle",
"lineHeight",
"letterSpacing",
].includes(key)
);
} catch (e) {
// If `value` is not an object, the above code will throw an error
// Catch error and return false is more efficient than a call to `isObject`
return false;
}
}

export function asThemeValuesObject(value: any): ThemeValues | null {
Expand Down

0 comments on commit dcdc06e

Please sign in to comment.