1
0
Fork 0
mirror of synced 2024-07-11 01:06:04 +12:00

Merge pull request #12900 from Budibase/string-split-check

Add a check to stringSplit that gives a nicer error message if a non-string is passed.
This commit is contained in:
Michael Drury 2024-01-30 11:43:56 +00:00 committed by GitHub
commit d497bda676
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -128,15 +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 (value.split("\n").length > 1) {
value = value.split("\n")
} else {
value = value.split(",")
if (Array.isArray(value)) {
return value
}
return value
if (typeof value !== "string") {
throw new Error(`Unable to split value of type ${typeof value}: ${value}`)
}
const splitOnNewLine = value.split("\n")
if (splitOnNewLine.length > 1) {
return splitOnNewLine
}
return value.split(",")
}
export function typecastForLooping(input: LoopInput) {