Is there a way to check a variable’s type in the f...
# prisma-whats-new
c
Is there a way to check a variable’s type in the frontend? I’m pulling a slug out of the url and I want to get a Type by either the
id: ID
field or by a custom
urlSlug: String
field. I don’t know if the slug is an ID or a String…
a
ID's have a fixed length and format, so you should be able to check that.
c
this seems like a finicky route…
a
Maybe I misunderstood your problem, but making a distinction between a well-defined ID format and a string seems pretty straightforward...
c
No, you didn’t… I’m just not great with regex 😬
a
c
Thank you!
😎 1
a
Spoiler alert though: the regex is-cuid is using seems to be not so good either...
c
blurg
a
try this:
^c\w{12}\d{4}\w{8}
Starts with c, 12 characters, 4 digits, 8 characters
Tested on every ID value I could find in my project 😄
c
oh wow
a
Beware though that Graphcool doesn't use the default cuid implementation (apparently), because that has the \w{12} and \w{8} the other way around...
But this one works for Graphcool ID's
c
thank you very much
😎 1