-
-
Notifications
You must be signed in to change notification settings - Fork 256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: 自定义验证schema.string是否符合条件。 #1104
Labels
feature
新特性
Comments
我也觉得是个好主意,但是在后端定义的函数并不好传到前端。所以我目前比较倾向于只提供一些可序列化的检验能力,例如正则表达式之类? |
可行,但是既然正则可以作为字符串传递,函数也是不是不可以。 如果使用正则的话,我不是很清楚一个问题: const str0 = `beee
teeested str
eee`
const str1 = `eee`
//我想要匹配三个连续的字符且仅能是三个连续的字符。例如上面两个变量,能被匹配的只有str1。这个能实现吗,原谅我正则水平不足
//关于函数转为字符串
const a = function(){console.log(123)}
or
const a = () => {console.log(123)}
a.toString();
// ^ "function(){console.log(123)}"
//关于字符串转为函数
Function(srting) or eval(string) |
你这种方案是不行的,函数里只要有闭包变量就无法 eval。 |
是我考虑不周, 那么就使用正则表达式吧。我刚才的问题好像可以通过正则表达式的正|反向预查来解决(不细说了)。 |
正则表达式已经支持了。 其实后端早就支持了,最新的更新 shigma/schemastery@01bee32 支持了正则表达式的前端错误提示。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the problem related to the feature request
很显然,string是很通用的一个类型,也经常使用
在我开发的插件的用户群体里接到的问题反馈,很大一部分都是由于字符串的格式错误造成的问题。
我希望可以使用一个回调函数来验证字符串格式是否正确,来提高用户体验和string的通用性。
Describe the solution you'd like
如上伪代码,check或许还需要防抖,
检查在前端或后端实现都是可以的,但是在前端实现可以带来更好的用户体验。
当回调函数返回true时,值符合条件。返回false时,值不符合条件,此时项目标红禁止插件启动。
Describe alternatives you've considered
我尝试过通过启动插件时检查值是否符合规定,如不符合则throw error来阻止用户启动插件。
但是,这样无法直观的表达是那一个值出现的问题,我尝试通过error来告知用户,
但是总是有人不看log,直接放弃使用或询问。
Additional context
schema非常好,甚至我都想拿来用在自己写的玩具上了。
The text was updated successfully, but these errors were encountered: