Skip to content

Commit 5df12f0

Browse files
committed
clean up assertions [skip publish]
1 parent 269dc6f commit 5df12f0

1 file changed

Lines changed: 37 additions & 37 deletions

File tree

src/assertions.ts

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,75 +7,75 @@ export function assert(condition: any, message?: string): void {
77
}
88
}
99

10+
function nullOr(condition: any, condition2: any): boolean {
11+
return [null, undefined].includes(condition) || condition2
12+
}
13+
1014
export function assertHelp(help: HelpDef) {
15+
assert(nullOr(help.binName, typeof help.binName === "string"), "Binary Name must be string")
1116
assert(
12-
[null, undefined].includes(help.binName as any) || typeof help.binName === "string",
13-
"Binary Name must be string"
14-
)
15-
assert(
16-
[null, undefined].includes(help.normalColors as any) ||
17-
asArray(help.normalColors).every((c) => typeof c === "string"),
17+
nullOr(
18+
help.normalColors,
19+
asArray(help.normalColors).every((c) => typeof c === "string")
20+
),
1821
"Normal colors must be string or list of strings"
1922
)
2023
assert(
21-
[null, undefined].includes(help.bodyColors as any) || asArray(help.bodyColors).every((c) => typeof c === "string"),
24+
nullOr(
25+
help.bodyColors,
26+
asArray(help.bodyColors).every((c) => typeof c === "string")
27+
),
2228
"Body colors must be string or list of strings"
2329
)
2430
assert(
25-
[null, undefined].includes(help.titleColors as any) ||
26-
asArray(help.titleColors).every((c) => typeof c === "string"),
31+
nullOr(
32+
help.titleColors,
33+
asArray(help.titleColors).every((c) => typeof c === "string")
34+
),
2735
"Title colors must be string or list of strings"
2836
)
2937
assert(
30-
[null, undefined].includes(help.subtitleColors as any) ||
31-
asArray(help.subtitleColors).every((c) => typeof c === "string"),
38+
nullOr(
39+
help.subtitleColors,
40+
asArray(help.subtitleColors).every((c) => typeof c === "string")
41+
),
3242
"Subtitle colors must be string or list of strings"
3343
)
3444
assert(
35-
[null, undefined].includes(help.highlightColors as any) ||
36-
asArray(help.highlightColors).every((c) => typeof c === "string"),
45+
nullOr(
46+
help.highlightColors,
47+
asArray(help.highlightColors).every((c) => typeof c === "string")
48+
),
3749
"Highlight colors must be string or list of strings"
3850
)
39-
assert([null, undefined].includes(help.footer as any) || typeof help.footer === "string", "Footer must be string")
40-
assert([null, undefined].includes(help.header as any) || typeof help.header === "string", "Header must be string")
51+
assert(nullOr(help.footer, typeof help.footer === "string"), "Footer must be string")
52+
assert(nullOr(help.header, typeof help.header === "string"), "Header must be string")
4153
assert(
42-
[null, undefined].includes(help.optionNameSeparator as any) || typeof help.optionNameSeparator === "string",
54+
nullOr(help.optionNameSeparator, typeof help.optionNameSeparator === "string"),
4355
"Option Name Separator must be string"
4456
)
4557
assert(
46-
[null, undefined].includes(help.commandNameSeparator as any) || typeof help.commandNameSeparator === "string",
58+
nullOr(help.commandNameSeparator, typeof help.commandNameSeparator === "string"),
4759
"Command Name Separator must be string"
4860
)
4961
assert(
50-
[null, undefined].includes(help.printWidth as any) || (typeof help.printWidth === "number" && help.printWidth >= 0),
62+
nullOr(help.printWidth, typeof help.printWidth === "number" && help.printWidth >= 0),
5163
"Print Width must be a number ≥ 0"
5264
)
5365
assert(
54-
[null, undefined].includes(help.exampleInputPrefix as any) || typeof help.exampleInputPrefix === "string",
66+
nullOr(help.exampleInputPrefix, typeof help.exampleInputPrefix === "string"),
5567
"Example Input Prefix must be string"
5668
)
5769
assert(
58-
[null, undefined].includes(help.exampleOutputPrefix as any) || typeof help.exampleOutputPrefix === "string",
70+
nullOr(help.exampleOutputPrefix, typeof help.exampleOutputPrefix === "string"),
5971
"Example Output Prefix must be string"
6072
)
73+
assert(nullOr(help.usageExample, typeof help.usageExample === "string"), "Usage Example must be string")
74+
assert(nullOr(help.useGlobalColumns, typeof help.useGlobalColumns === "boolean"), "Usage Example must be boolean")
75+
assert(nullOr(help.includeDefaults, typeof help.includeDefaults === "boolean"), "Include Defaults must be boolean")
76+
assert(nullOr(help.useColors, typeof help.useColors === "boolean"), "Use Colors must be boolean")
6177
assert(
62-
[null, undefined].includes(help.usageExample as any) || typeof help.usageExample === "string",
63-
"Usage Example must be string"
64-
)
65-
assert(
66-
[null, undefined].includes(help.useGlobalColumns as any) || typeof help.useGlobalColumns === "boolean",
67-
"Usage Example must be boolean"
68-
)
69-
assert(
70-
[null, undefined].includes(help.includeDefaults as any) || typeof help.includeDefaults === "boolean",
71-
"Include Defaults must be boolean"
72-
)
73-
assert(
74-
[null, undefined].includes(help.useColors as any) || typeof help.useColors === "boolean",
75-
"Use Colors must be boolean"
76-
)
77-
assert(
78-
[null, undefined].includes(help.useGlobalColumns as any) || typeof help.useGlobalColumns === "boolean",
78+
nullOr(help.useGlobalColumns, typeof help.useGlobalColumns === "boolean"),
7979
"Use Global Columns must be boolean"
8080
)
8181
}

0 commit comments

Comments
 (0)