padding.ts

 1type PaddingOptions = {
 2    all?: number
 3    left?: number
 4    right?: number
 5    top?: number
 6    bottom?: number
 7}
 8
 9export type PaddingStyle = {
10    top: number
11    bottom: number
12    left: number
13    right: number
14}
15
16export const padding_style = (options: PaddingOptions): PaddingStyle => {
17    const { all, top, bottom, left, right } = options
18
19    if (all !== undefined) return {
20        top: all,
21        bottom: all,
22        left: all,
23        right: all
24    }
25
26    if (top === undefined && bottom === undefined && left === undefined && right === undefined) throw new Error("Padding must have at least one value")
27
28    return {
29        top: top || 0,
30        bottom: bottom || 0,
31        left: left || 0,
32        right: right || 0
33    }
34}