Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
demand
Advanced tools
Readme
Form error handling for dietjs
request.body[..]
values to match criterias like existence, length etc..POST
requestrequest.demand
functionrequest.body
request.passed
is true than the form request has passedrequest.passed
is false then request.errors
contains the errors in JSONrequest.passed
with response.success(data)
response.error(data)
When a POST
request comes in (from a form or ajax request) with these parameters:
{
'account':{
username:'adam',
password:'123456',
},
'remain_logged_in': true
}
You can check if everything is ok with the submitted data with request.check
:
var app = new Application(options);
app.get('/login', function(request, response, mysql){
// DEMAND values to be specific
request.demand('username').length(0,40);
request.demand('email').length(0,40).isEmail();
request.demand('password').length(0,40).equals(request.body.password_again);
request.demand('options', 'remain_logged_in').isBoolean().length(0,1);
// IF request has passed
if(request.passed){
response.success(); // { passed: true, errors: false}
mysql.end();
} else {
response.error(); // { passed: true, errors: [{..},{..}]}
mysql.end();
}
});
Function | Condition | Example | Use Case |
---|---|---|---|
is | regex | /([0-9]+)/i | request.demand('id').is(/([0-9]+)/i) |
isset | defined | undefined vs hell world | request.demand('message').isset() |
isArray | array | [1,3,5,7] | request.demand('users').isArray() |
isNumber | integer | 8080 | request.demand('birth_day').isNumber() |
isBoolean | boolean | true or false | request.demand('agree').isBoolean() |
isText | alpha | A simple text | request.demand('username').isText() |
isString | string | 52 people likes you today! | request.demand('message').isString() |
isSlug | slug | seomthing_like_this_842 | request.demand('username').isSlug() |
isEmail | me@email.com | request.demand('email').isEmail() | |
isURL | url | http://example.com/?p=10 | request.demand('personal_blog').isUrl() |
length | range | hello is 4 | request.demand('tweet').length(0, 140) |
equals | comparison | comparing value a with b | request.demand('agree').equals('true') |
request.error(field, message)
- both attributes are required
response.success(data)
{ passed: true, errors: false}
data
is appended to the default json response but it's optional
response.error(data)
{ passed: false, errors: [...]}
data
is appended to the default json response but it's optional
errors
contain a list of erros withadded
: request.error(field, message)added
: response.success(data)added
: response.error(data)added
Echo to arguments for multi language isset demading
FAQs
Form error handling for dietjs
The npm package demand receives a total of 15 weekly downloads. As such, demand popularity was classified as not popular.
We found that demand demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.