Validating that a string isn't empty after trimming

Title says it all really. I want to have ArkType trim a string and then check its length, but type("string.trim > 0") doesn't work as the left side is a morph.
2 Replies
ssalbdivad
ssalbdivad5w ago
Yeah there's a few options for this, basically you just have to ensure the length constraint applies after the pipe:
const A = type("string.trim |> string > 0")
const B = type("string.trim").to("string > 0")
const A = type("string.trim |> string > 0")
const B = type("string.trim").to("string > 0")
You can also try something like this if you want a reusable generic to create strings like this: https://discord.com/channels/957797212103016458/1345272840538292307/1345491516549758986 But probably overkill for most scenarios
!skyfall
!skyfallOP5w ago
Ended up going with B and it worked, thanks a ton!

Did you find this page helpful?