Add isBase64 string property
This PR adds isBase64 string property.
If we add this, do we need this for the other hash functions as well? Sha, md5 etc? 🤔
If we add this, do we need this for the other hash functions as well? Sha, md5 etc? 🤔
Maybe it makes sense only for base64 due to the base64Decoded string property. Another approach is to make base64Decoded detect if a string is a base64 through str?.base64Decoded.
What's the use-case for this? Is it for defining a constraint?
Today, you can do this in-language:
function isBase64(str: String) = str.match(Regex("[-A-Za-z0-9+/]*={0,3}"))
Or, a more precise version, and also a little bit more expensive:
import "pkl:test"
function isBase64(str: String) = test.catchOrNull(() -> str.base64Decoded) == null
We've rolled this into https://github.com/apple/pkl/pull/1019, and it will land in 0.29.
Thanks!