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:
commit
d497bda676
1 changed files with 12 additions and 7 deletions
|
@ -128,16 +128,21 @@ export function substituteLoopStep(hbsString: string, substitute: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function stringSplit(value: string | string[]) {
|
export function stringSplit(value: string | string[]) {
|
||||||
if (value == null || Array.isArray(value)) {
|
if (value == null) {
|
||||||
return value || []
|
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) {
|
export function typecastForLooping(input: LoopInput) {
|
||||||
if (!input || !input.binding) {
|
if (!input || !input.binding) {
|
||||||
|
|
Loading…
Reference in a new issue