4 ms·
ForgJs – A lightweight object validator
- coding123 8y agoVery nice API. I do have a question, and not to be dismissive, but is there a strong reason to use Forg over Validatejs. The APIs are pretty similar so I don't know what I would choose Forg over ValidateJS. Some things to address: * Typescript definitions * ES/6 import documentation * There are a lot of tiny typos in the readme, it would make sense to spell check that. Thanks for the contribution.
- forg_js 8y agoThank you, i tried to fix typos but im sure some are left. I dont think that there is a strong reason, I just wanted a modern lightweight validation library where rules are easy to write and closer to buisness rules
- deleted 8y ago[deleted]
- LiterallyDoge 8y agoVery cool idea. Something I would enjoy using is a shorthand syntax for validation rule object declarations eg: new Validator = ({ age: 'int 22-48' }); If memory serves you can parse that type of string in the Validator constructor and insert the Rule structures you already have in place of it.
- forg_js 8y agoI can't make this possible becacuse if there are nested objects forgjs cant make the diference between a rule and a value
- Siilwyn 8y agoWith two mature packages doing the same: Joi & ajv. What made you write this? https://www.npmjs.com/package/joi https://www.npmjs.com/package/joi https://www.npmjs.com/package/ajv https://www.npmjs.com/package/ajv
- chickenfries 8y agoJoi is much larger. https://bundlephobia.com/result?p=joi@14.3.0 https://bundlephobia.com/result?p=joi@14.3.0
- andyfleming 8y agoOnce forg has more features, won't it be bigger as well?
- chickenfries 8y agoNot if their goal is to be “lightweight” like they say it is.
- gyoubu 8y agoCame here looking to find / provide this comment.
- jaklfdjkasf 8y agoThis is very cool, but I highly recommend using a standard like JSON schema instead. It will make your life easier long term. The initial hurdle of learning may be harder, but lots of libraries/languages support JSON schema. If you are using typescript, I highly recommend using a generator to create JSON schema definitions. This one has worked really well recently https://github.com/YousefED/typescript-json-schema https://github.com/YousefED/typescript-json-schema
- pagnol 8y agoBeen using runtypes and it works well enough, but now I'm wondering if this may be a smarter option.
- mtrpcic 8y agoOut of curiosity, why have a singular Rule class that has a type (with internal branching logic based on that field), rather than separate Rule classes for each type of Rule, with Rule being a base class that users can extend to define their own rules?
- nnq 8y agoanything like this for Python?
- lfx 8y agoI have seen used this quite a bit https://github.com/Julian/jsonschema https://github.com/Julian/jsonschema Here is some sample https://gist.github.com/nmarley/afe61a36f71ed1e4a9728c0f5f6f7f6f https://gist.github.com/nmarley/afe61a36f71ed1e4a9728c0f5f6f...
- dstjean 8y agoAny attributes for required/optional fields?
- forg_js 8y agoby default every value is required, until optional is set to true
- zhs 8y agoI've found https://github.com/ianstormtaylor/superstruct https://github.com/ianstormtaylor/superstruct to be really flexible/powerful.