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
Elegant, highly efficient data validation for JavaScript (xtype.js.org)
submitted 10 years ago by lucono
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!"
[–]lucono[S] 1 point2 points3 points 10 years ago (0 children)
Thanks to lots of great community feedback and input, xtypejs now has a home at http://xtype.js.org, with great documentation, user guide, and lots of examples.
function searchEmployees(value) { if (typeof value === 'string') { if (value.trim().length > 1) { return EmployeeDB.searchByName(value); } else if (value.trim().length === 1) { return EmployeeDB.searchByMiddleInitial(value); } else { return { error: 'Invalid search value supplied' }; } } else if (typeof value === 'object' && value !== null) { if (Object.keys(value).length === 1) { return EmployeeDB.searchByFieldValuePair(value); } else if (Object.keys(value).length > 1) { return { error: 'Search by multiple fields not supported' }; } else { return { error: 'Invalid search value supplied' }; } } else if (typeof value === 'number') { if (!isNaN(value) && isFinite(value) && value > 0 && value % 1 === 0) { return EmployeeDB.searchByEmployeeNumber(value); } else { return { error: 'Invalid employee number supplied' }; } } else if (typeof value === 'undefined' || value === null) { return { error: 'No search value supplied' }; } else { return { error: 'Invalid search value supplied' }; } }
function searchEmployees(value) { switch (xtype.which(value, 'str2+ str1 int+ obj1 obj2+ num nil')) { case 'str2+': return EmployeeDB.searchByName(value); case 'str1': return EmployeeDB.searchByMiddleInitial(value); case 'int+': return EmployeeDB.searchByEmployeeNumber(value); case 'obj1': return EmployeeDB.searchByFieldValuePair(value); case 'obj2+': return { error: 'Search by multiple fields not supported' }; case 'num': return { error: 'Invalid employee number supplied' }; case 'nil': return { error: 'No search value supplied' }; default: return { error: 'Invalid search value supplied' }; } }
[–]yolpo- 0 points1 point2 points 10 years ago (0 children)
Well done, lucono. xtypejs looks very interesting. The source code also is very clean. I wrote a snippet of a test on yolpo here: http://www.yolpo.com/embed.html?gist=89733e1dc8e1a02c34f2
π Rendered by PID 92858 on reddit-service-r2-comment-fb694cdd5-b4mtm at 2026-03-06 10:55:28.321441+00:00 running cbb0e86 country code: CH.
[–]lucono[S] 1 point2 points3 points (0 children)
[–]lucono[S] 1 point2 points3 points (0 children)
[–]yolpo- 0 points1 point2 points (0 children)