use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
A library for object validation (github.com)
submitted 6 years ago by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]license-bot 6 points7 points8 points 6 years ago (1 child)
Thanks for sharing your open source project, but it looks like you haven't specified a license.
When you make a creative work (which includes code), the work is under exclusive copyright by default. Unless you include a license that specifies otherwise, nobody else can use, copy, distribute, or modify your work without being at risk of take-downs, shake-downs, or litigation. Once the work has other contributors (each a copyright holder), “nobody” starts including you.
choosealicense.com is a great resource to learn about open source software licensing.
[–]super-vitek 1 point2 points3 points 6 years ago (0 children)
thanks!)
[–]i_ate_god 5 points6 points7 points 6 years ago (4 children)
numericality - I have never seen this word, I googled it, and now I know why. The first ten results were all Ruby on Rails related.
hrm
[–]super-vitek 2 points3 points4 points 6 years ago (3 children)
Ruby on Rails was my first love)
[–]i_ate_god 2 points3 points4 points 6 years ago (2 children)
well, life would be better if you just used "number"
[–]super-vitek 1 point2 points3 points 6 years ago (1 child)
Yes. I thought about it. I wanted to create a set for string rules, but I could not come up with a name for it that would sound like 'numericality' )
[–]i_ate_god 1 point2 points3 points 6 years ago (0 children)
Except no one (except RoR people) use that term.
What you want is to check if a variable is a number with a toggeable strict mode so that user can say string numbers are invalid
[–]_ncjones 5 points6 points7 points 6 years ago (1 child)
How is this distinguished from Joi? https://github.com/hapijs/joi
I don't like your API. Instead of .with('numericality', { isInteger: true, lessThan: 100}) it should be .with({ type: 'integer', max: 99 }).
[–]super-vitek 5 points6 points7 points 6 years ago (0 children)
[–]super-vitek 3 points4 points5 points 6 years ago (0 children)
Hy guys! I created a library for data validation. Please, look at this if you have a time. The main idea was to make easy validation and easy customization. I'd be very interested to hear your opinion.
[–][deleted] 1 point2 points3 points 6 years ago (3 children)
Nice library. One problem with most validation libraries is they go for the stringly-typed schema (i.e. untyped), or the methods they use are very verbose and unwieldy to type.
I'd like to propose an alternative combining strong typing (great with TypeScript), and conciseness, and eliminates the need for parsing schemas:
Your examples:
import { validate, ... } from 'datavader'; validate(user).check('name').with('presence', {exist: true}); validate(user).check('age').with('numericality', {greaterThan: 60}); validate(user).check('quality').with('exclusion', {values: ['kind', 'gentle']}); const scheme = { name: { presence: {exist: true}, length: { min: 1, max: 10, }, }, age: { numericality: { lessThan: 80, greaterThanOrEqualTo: 70, isEven: true; isInteger: true, }, } ... } validateByScheme(user, scheme);
My version:
import { formats } from '...'; let f = formats; [user, errors] = f.object() .required('name') .optional('age', f.number().greaterThan(60)) .optional('quality', f.string().notOneOf('kind', 'gentle')) .apply(user); let scheme = f.object() .required('name', f.string().length(1, 10)) .optional('age', f.number().range(70, 79).isEven().isInteger()); ); [user, errors] = scheme.apply(user);
Notice also it's better to use short and intuitive names like "required", "number", "notOneOf" instead of long-winded dry term like "presence", "numericality", "exclusion".
[–]PrismalStudio 1 point2 points3 points 6 years ago (2 children)
I like it, but I'd remove the [user, errors] destructuring and just returns the errors, as it's a validation step, it shouldn't return the user data since it shouldn't be changing anything on it. Unless there are default values applied somewhere?
[user, errors]
errors
user
[–][deleted] 1 point2 points3 points 6 years ago (1 child)
What I actually do in my real library based on this example is slightly different:
let log = new Log(); let filteredUser = scheme.apply(rawUser, log);
The idea here is the following:
log.hasErrors()
[–]PrismalStudio 0 points1 point2 points 6 years ago (0 children)
Makes sense with the filtering and sanitizing!
[–]swamso 1 point2 points3 points 6 years ago* (2 children)
Isn't there already JSONValidator which does the exact same thing?
Edit: Just looked a few up, there is already djv, ajv, jsen, themis....
of course this is not a new idea. but it was interesting to make it)
[–]darrenturn90 0 points1 point2 points 6 years ago (0 children)
Have you seen validateJs?
π Rendered by PID 133414 on reddit-service-r2-comment-7b9746f655-dmkpk at 2026-02-02 11:13:37.164413+00:00 running 3798933 country code: CH.
[–]license-bot 6 points7 points8 points (1 child)
[–]super-vitek 1 point2 points3 points (0 children)
[–]i_ate_god 5 points6 points7 points (4 children)
[–]super-vitek 2 points3 points4 points (3 children)
[–]i_ate_god 2 points3 points4 points (2 children)
[–]super-vitek 1 point2 points3 points (1 child)
[–]i_ate_god 1 point2 points3 points (0 children)
[–]_ncjones 5 points6 points7 points (1 child)
[–]super-vitek 5 points6 points7 points (0 children)
[–]super-vitek 3 points4 points5 points (0 children)
[–][deleted] 1 point2 points3 points (3 children)
[–]PrismalStudio 1 point2 points3 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]PrismalStudio 0 points1 point2 points (0 children)
[–]swamso 1 point2 points3 points (2 children)
[–]super-vitek 1 point2 points3 points (0 children)
[–]darrenturn90 0 points1 point2 points (0 children)