Skip to content

Commit

Permalink
Fix side normalize when non-object (#1585)
Browse files Browse the repository at this point in the history
  • Loading branch information
hollandjake authored Jan 13, 2025
1 parent 36549b3 commit 73d86db
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function PDFNumber(n) {
* - Or `{top: SideValue, right: SideValue, bottom: SideValue, left: SideValue}`
*
* @template T
* @typedef {T | [T, T] | [T, T, T, T] | { vertical: T; horizontal: T } | { top: T; right: T; bottom: T; left: T }} SideDefinition<T>
* @typedef {T | [T, T] | [T, T, T, T] | { vertical: T; horizontal: T } | ExpandedSideDefinition<T>} SideDefinition<T>
**/

/**
Expand All @@ -52,12 +52,13 @@ export function normalizeSides(
transformer = (v) => v,
) {
if (
sides === undefined || sides === null ||
sides === undefined ||
sides === null ||
(typeof sides === "object" && Object.keys(sides).length === 0)
) {
sides = defaultDefinition;
}
if (typeof sides === "string" || typeof sides === "number" || !sides) {
if (typeof sides !== "object" || sides === null) {
sides = [sides, sides, sides, sides];
}
if (Array.isArray(sides)) {
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ describe("normalizeSides", () => {
undefined,
{ top: undefined, right: undefined, bottom: undefined, left: undefined },
],
[
true,
{ top: true, right: true, bottom: true, left: true },
],
[
false,
{ top: false, right: false, bottom: false, left: false },
],
])("%s -> %s", (size, expected) => {
expect(normalizeSides(size)).toEqual(expected);
});
Expand Down

0 comments on commit 73d86db

Please sign in to comment.