Mild refactor of stringSplit to make it easier to understand.

This commit is contained in:
Sam Rose 2024-01-29 17:43:08 +00:00
parent b5672d676f
commit 2bfa4c6f91
No known key found for this signature in database
1 changed files with 9 additions and 7 deletions

View File

@ -128,18 +128,20 @@ export function substituteLoopStep(hbsString: string, substitute: string) {
}
export function stringSplit(value: string | string[]) {
if (value == null || Array.isArray(value)) {
return value || []
if (value == null) {
return []
}
if (Array.isArray(value)) {
return value
}
if (typeof value !== "string") {
throw new Error(`Unable to split value of type ${typeof value}: ${value}`)
}
if (value.split("\n").length > 1) {
value = value.split("\n")
} else {
value = value.split(",")
const splitOnNewLine = value.split("\n")
if (splitOnNewLine.length > 1) {
return splitOnNewLine
}
return value
return value.split(",")
}
export function typecastForLooping(loopStep: LoopStep, input: LoopInput) {